Skip to content

Commit

Permalink
chore(shm) rename ngx_wasm_shm to ngx_wa_shm
Browse files Browse the repository at this point in the history
  • Loading branch information
casimiro committed Aug 9, 2024
1 parent 239bc8c commit 1d9b3f0
Show file tree
Hide file tree
Showing 22 changed files with 249 additions and 250 deletions.
12 changes: 6 additions & 6 deletions config
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ NGX_WASMX_DEPS="\
$ngx_addon_dir/src/common/proxy_wasm/ngx_proxy_wasm.h \
$ngx_addon_dir/src/common/proxy_wasm/ngx_proxy_wasm_maps.h \
$ngx_addon_dir/src/common/proxy_wasm/ngx_proxy_wasm_properties.h \
$ngx_addon_dir/src/common/shm/ngx_wasm_shm.h \
$ngx_addon_dir/src/common/shm/ngx_wasm_shm_kv.h \
$ngx_addon_dir/src/common/shm/ngx_wasm_shm_queue.h \
$ngx_addon_dir/src/common/shm/ngx_wa_shm.h \
$ngx_addon_dir/src/common/shm/ngx_wa_shm_kv.h \
$ngx_addon_dir/src/common/shm/ngx_wa_shm_queue.h \
$ngx_addon_dir/src/common/metrics/ngx_wa_metrics.h"

NGX_WASMX_SRCS="\
Expand All @@ -155,9 +155,9 @@ NGX_WASMX_SRCS="\
$ngx_addon_dir/src/common/proxy_wasm/ngx_proxy_wasm_maps.c \
$ngx_addon_dir/src/common/proxy_wasm/ngx_proxy_wasm_properties.c \
$ngx_addon_dir/src/common/proxy_wasm/ngx_proxy_wasm_util.c \
$ngx_addon_dir/src/common/shm/ngx_wasm_shm.c \
$ngx_addon_dir/src/common/shm/ngx_wasm_shm_kv.c \
$ngx_addon_dir/src/common/shm/ngx_wasm_shm_queue.c \
$ngx_addon_dir/src/common/shm/ngx_wa_shm.c \
$ngx_addon_dir/src/common/shm/ngx_wa_shm_kv.c \
$ngx_addon_dir/src/common/shm/ngx_wa_shm_queue.c \
$ngx_addon_dir/src/common/metrics/ngx_wa_metrics.c \
$ngx_addon_dir/src/common/metrics/ngx_wa_histogram.c"

Expand Down
16 changes: 8 additions & 8 deletions lib/resty/wasmx/shm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ ffi.cdef [[
NGX_WASM_SHM_TYPE_KV,
NGX_WASM_SHM_TYPE_QUEUE,
NGX_WASM_SHM_TYPE_METRICS,
} ngx_wasm_shm_type_e;
} ngx_wa_shm_type_e;

typedef enum {
NGX_WASM_SHM_EVICTION_LRU,
NGX_WASM_SHM_EVICTION_SLRU,
NGX_WASM_SHM_EVICTION_NONE,
} ngx_wasm_shm_eviction_e;
} ngx_wa_shm_eviction_e;

typedef struct {
ngx_wasm_shm_type_e type;
ngx_wasm_shm_eviction_e eviction;
ngx_wa_shm_type_e type;
ngx_wa_shm_eviction_e eviction;
ngx_str_t name;
ngx_log_t *log;
ngx_slab_pool_t *shpool;
void *data;
} ngx_wasm_shm_t;
} ngx_wa_shm_t;

typedef enum {
NGX_WA_METRIC_COUNTER,
Expand Down Expand Up @@ -98,14 +98,14 @@ ffi.cdef [[
} ngx_wa_metric_t;


typedef void (*ngx_wa_ffi_shm_get_zones_handler_pt)(ngx_wasm_shm_t *shm);
typedef void (*ngx_wa_ffi_shm_get_zones_handler_pt)(ngx_wa_shm_t *shm);


int ngx_wa_ffi_shm_get_zones(ngx_wa_ffi_shm_get_zones_handler_pt handler);
int ngx_wa_ffi_shm_get_keys(ngx_wasm_shm_t *shm,
int ngx_wa_ffi_shm_get_keys(ngx_wa_shm_t *shm,
ngx_uint_t n,
ngx_str_t **keys);
int ngx_wa_ffi_shm_get_kv_value(ngx_wasm_shm_t *shm,
int ngx_wa_ffi_shm_get_kv_value(ngx_wa_shm_t *shm,
ngx_str_t *k,
ngx_str_t **v,
uint32_t *cas);
Expand Down
24 changes: 12 additions & 12 deletions src/common/lua/ngx_wasm_lua_ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "ddebug.h"

#include <ngx_wasm_lua_ffi.h>
#include <ngx_wasm_shm_kv.h>
#include <ngx_wa_shm_kv.h>
#include <ngx_http_lua_common.h>


Expand Down Expand Up @@ -262,11 +262,11 @@ ngx_http_wasm_ffi_set_host_properties_handlers(ngx_http_request_t *r,
ngx_int_t
ngx_wa_ffi_shm_get_zones(ngx_wa_ffi_shm_get_zones_handler_pt handler)
{
ngx_uint_t i;
ngx_cycle_t *cycle = (ngx_cycle_t *) ngx_cycle;
ngx_array_t *shms = ngx_wasmx_shms(cycle);
ngx_wasm_shm_mapping_t *mappings;
ngx_wasm_shm_t *shm;
ngx_uint_t i;
ngx_cycle_t *cycle = (ngx_cycle_t *) ngx_cycle;
ngx_array_t *shms = ngx_wasmx_shms(cycle);
ngx_wa_shm_t *shm;
ngx_wa_shm_mapping_t *mappings;

if (!handler) {
return NGX_ERROR;
Expand All @@ -291,7 +291,7 @@ static void
shm_kv_retrieve_keys(ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel,
ngx_int_t *total, ngx_int_t limit, ngx_str_t **keys)
{
ngx_wasm_shm_kv_node_t *n = (ngx_wasm_shm_kv_node_t *) node;
ngx_wa_shm_kv_node_t *n = (ngx_wa_shm_kv_node_t *) node;

if (!node || node == sentinel || (limit > 0 && *total == limit)) {
return;
Expand All @@ -309,10 +309,10 @@ shm_kv_retrieve_keys(ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel,


ngx_int_t
ngx_wa_ffi_shm_get_keys(ngx_wasm_shm_t *shm, ngx_uint_t n, ngx_str_t **keys)
ngx_wa_ffi_shm_get_keys(ngx_wa_shm_t *shm, ngx_uint_t n, ngx_str_t **keys)
{
ngx_int_t total = 0;
ngx_wasm_shm_kv_t *kv;
ngx_int_t total = 0;
ngx_wa_shm_kv_t *kv;

if (!shm || shm->type == NGX_WASM_SHM_TYPE_QUEUE) {
return NGX_ERROR;
Expand All @@ -331,14 +331,14 @@ ngx_wa_ffi_shm_get_keys(ngx_wasm_shm_t *shm, ngx_uint_t n, ngx_str_t **keys)


ngx_int_t
ngx_wa_ffi_shm_get_kv_value(ngx_wasm_shm_t *shm, ngx_str_t *k, ngx_str_t **v,
ngx_wa_ffi_shm_get_kv_value(ngx_wa_shm_t *shm, ngx_str_t *k, ngx_str_t **v,
uint32_t *cas)
{
if (!shm || !k || !v || !cas) {
return NGX_ERROR;
}

return ngx_wasm_shm_kv_get_locked(shm, k, NULL, v, cas);
return ngx_wa_shm_kv_get_locked(shm, k, NULL, v, cas);
}


Expand Down
6 changes: 3 additions & 3 deletions src/common/lua/ngx_wasm_lua_ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ typedef struct {
} ngx_wasm_ffi_filter_t;


typedef void (*ngx_wa_ffi_shm_get_zones_handler_pt)(ngx_wasm_shm_t *shm);
typedef void (*ngx_wa_ffi_shm_get_zones_handler_pt)(ngx_wa_shm_t *shm);


ngx_int_t ngx_http_wasm_ffi_plan_new(ngx_wavm_t *vm,
Expand All @@ -47,9 +47,9 @@ ngx_int_t ngx_http_wasm_ffi_set_host_properties_handlers(ngx_http_request_t *r,


ngx_int_t ngx_wa_ffi_shm_get_zones(ngx_wa_ffi_shm_get_zones_handler_pt handler);
ngx_int_t ngx_wa_ffi_shm_get_keys(ngx_wasm_shm_t *shm, ngx_uint_t n,
ngx_int_t ngx_wa_ffi_shm_get_keys(ngx_wa_shm_t *shm, ngx_uint_t n,
ngx_str_t **keys);
ngx_int_t ngx_wa_ffi_shm_get_kv_value(ngx_wasm_shm_t *shm, ngx_str_t *k,
ngx_int_t ngx_wa_ffi_shm_get_kv_value(ngx_wa_shm_t *shm, ngx_str_t *k,
ngx_str_t **v, uint32_t *cas);
ngx_int_t ngx_wa_ffi_shm_get_metric(ngx_str_t *k, u_char *m_buf, size_t mbs,
u_char *h_buf, size_t hbs);
Expand Down
4 changes: 2 additions & 2 deletions src/common/metrics/ngx_wa_histogram.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ histogram_grow(ngx_wa_metrics_t *metrics, ngx_wa_metrics_histogram_t *h,
size = old_size + sizeof(ngx_wa_metrics_bin_t) * n;

if (metrics->shm->eviction == NGX_WASM_SHM_EVICTION_NONE) {
ngx_wasm_shm_lock(metrics->shm);
ngx_wa_shm_lock(metrics->shm);
}

new_h = ngx_slab_calloc_locked(metrics->shm->shpool, size);
Expand All @@ -69,7 +69,7 @@ histogram_grow(ngx_wa_metrics_t *metrics, ngx_wa_metrics_histogram_t *h,
error:

if (metrics->shm->eviction == NGX_WASM_SHM_EVICTION_NONE) {
ngx_wasm_shm_unlock(metrics->shm);
ngx_wa_shm_unlock(metrics->shm);
}

return rc;
Expand Down
48 changes: 24 additions & 24 deletions src/common/metrics/ngx_wa_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ realloc_histogram(ngx_wa_metrics_t *metrics, ngx_wa_metric_t *old_m,
ngx_str_t *val;
ngx_wa_metric_t *m;

rc = ngx_wasm_shm_kv_get_locked(metrics->shm, NULL, &mid, &val, &cas);
rc = ngx_wa_shm_kv_get_locked(metrics->shm, NULL, &mid, &val, &cas);
if (rc != NGX_OK) {
return rc;
}
Expand All @@ -90,11 +90,11 @@ static ngx_int_t
realloc_metrics(ngx_wa_metrics_t *metrics, ngx_rbtree_node_t *node,
ngx_rbtree_node_t *sentinel)
{
uint32_t mid;
ngx_int_t rc;
ngx_uint_t val;
ngx_wasm_shm_kv_node_t *n = (ngx_wasm_shm_kv_node_t *) node;
ngx_wa_metric_t *m = (ngx_wa_metric_t *) n->value.data;
uint32_t mid;
ngx_int_t rc;
ngx_uint_t val;
ngx_wa_shm_kv_node_t *n = (ngx_wa_shm_kv_node_t *) node;
ngx_wa_metric_t *m = (ngx_wa_metric_t *) n->value.data;

if (node == sentinel) {
return NGX_OK;
Expand Down Expand Up @@ -167,7 +167,7 @@ ngx_wa_metrics_alloc(ngx_cycle_t *cycle)
metrics->config.slab_size = NGX_CONF_UNSET_SIZE;
metrics->config.max_metric_name_length = NGX_CONF_UNSET_SIZE;

metrics->shm = ngx_pcalloc(cycle->pool, sizeof(ngx_wasm_shm_t));
metrics->shm = ngx_pcalloc(cycle->pool, sizeof(ngx_wa_shm_t));
if (metrics->shm == NULL) {
ngx_pfree(cycle->pool, metrics);
return NULL;
Expand Down Expand Up @@ -217,7 +217,7 @@ ngx_wa_metrics_init_conf(ngx_wa_metrics_t *metrics, ngx_conf_t *cf)
return NGX_CONF_ERROR;
}

metrics->mapping->zone->init = ngx_wasm_shm_init_zone;
metrics->mapping->zone->init = ngx_wa_shm_init_zone;
metrics->mapping->zone->data = metrics->shm;
metrics->mapping->zone->noreuse = 0;

Expand All @@ -235,17 +235,17 @@ ngx_wa_metrics_init_conf(ngx_wa_metrics_t *metrics, ngx_conf_t *cf)
ngx_int_t
ngx_wa_metrics_init(ngx_cycle_t *cycle)
{
ngx_int_t rc;
ngx_wasm_shm_kv_t *old_shm_kv;
ngx_wa_metrics_t *metrics = ngx_wasmx_metrics(cycle);
ngx_int_t rc;
ngx_wa_shm_kv_t *old_shm_kv;
ngx_wa_metrics_t *metrics = ngx_wasmx_metrics(cycle);

if (metrics->old_metrics && !metrics->mapping->zone->noreuse) {
/* reuse old kv store */
metrics->shm->data = metrics->old_metrics->shm->data;
return NGX_OK;
}

rc = ngx_wasm_shm_kv_init(metrics->shm);
rc = ngx_wa_shm_kv_init(metrics->shm);
if (rc != NGX_OK) {
return rc;
}
Expand All @@ -256,7 +256,7 @@ ngx_wa_metrics_init(ngx_cycle_t *cycle)
metrics->mapping->zone->noreuse = 0;

/* realloc old kv store */
old_shm_kv = ngx_wasm_shm_get_kv(metrics->old_metrics->shm);
old_shm_kv = ngx_wa_shm_get_kv(metrics->old_metrics->shm);

return realloc_metrics(metrics, old_shm_kv->rbtree.root,
old_shm_kv->rbtree.sentinel);
Expand Down Expand Up @@ -296,9 +296,9 @@ ngx_wa_metrics_define(ngx_wa_metrics_t *metrics, ngx_str_t *name,

mid = ngx_crc32_long(name->data, name->len);

ngx_wasm_shm_lock(metrics->shm);
ngx_wa_shm_lock(metrics->shm);

rc = ngx_wasm_shm_kv_get_locked(metrics->shm, NULL, &mid, &p, &cas);
rc = ngx_wa_shm_kv_get_locked(metrics->shm, NULL, &mid, &p, &cas);
if (rc == NGX_OK) {
ngx_log_debug1(NGX_LOG_DEBUG_WASM, metrics->shm->log, 0,
"wasm returning existing metric id \"%uD\"", mid);
Expand All @@ -321,7 +321,7 @@ ngx_wa_metrics_define(ngx_wa_metrics_t *metrics, ngx_str_t *name,
val.len = size;
val.data = buf;

rc = ngx_wasm_shm_kv_set_locked(metrics->shm, name, &val, 0, &written);
rc = ngx_wa_shm_kv_set_locked(metrics->shm, name, &val, 0, &written);
if (rc != NGX_OK) {
goto error;
}
Expand All @@ -332,7 +332,7 @@ ngx_wa_metrics_define(ngx_wa_metrics_t *metrics, ngx_str_t *name,

error:

ngx_wasm_shm_unlock(metrics->shm);
ngx_wa_shm_unlock(metrics->shm);

if (rc == NGX_OK) {
ngx_wasm_log_error(NGX_LOG_INFO, metrics->shm->log, 0,
Expand Down Expand Up @@ -365,11 +365,11 @@ ngx_wa_metrics_increment(ngx_wa_metrics_t *metrics, uint32_t mid, ngx_int_t n)
#if 0
if (metrics->shm->eviction != NGX_WASM_EVICTION_NONE) {
slot = 0;
ngx_wasm_shm_lock(metrics->shm);
ngx_wa_shm_lock(metrics->shm);
}
#endif

rc = ngx_wasm_shm_kv_get_locked(metrics->shm, NULL, &mid, &val, &cas);
rc = ngx_wa_shm_kv_get_locked(metrics->shm, NULL, &mid, &val, &cas);
if (rc != NGX_OK) {
goto error;
}
Expand All @@ -394,7 +394,7 @@ ngx_wa_metrics_increment(ngx_wa_metrics_t *metrics, uint32_t mid, ngx_int_t n)

#if 0
if (metrics->shm->eviction != NGX_WASM_EVICTION_NONE) {
ngx_wasm_shm_unlock(metrics->shm);
ngx_wa_shm_unlock(metrics->shm);
}
#endif

Expand Down Expand Up @@ -425,11 +425,11 @@ ngx_wa_metrics_record(ngx_wa_metrics_t *metrics, uint32_t mid, ngx_int_t n)
#if 0
if (metrics->shm->eviction != NGX_WASM_EVICTION_NONE) {
slot = 0;
ngx_wasm_shm_lock(metrics->shm);
ngx_wa_shm_lock(metrics->shm);
}
#endif

rc = ngx_wasm_shm_kv_get_locked(metrics->shm, NULL, &mid, &val, &cas);
rc = ngx_wa_shm_kv_get_locked(metrics->shm, NULL, &mid, &val, &cas);
if (rc != NGX_OK) {
goto error;
}
Expand Down Expand Up @@ -458,7 +458,7 @@ ngx_wa_metrics_record(ngx_wa_metrics_t *metrics, uint32_t mid, ngx_int_t n)

#if 0
if (metrics->shm->eviction != NGX_WASM_EVICTION_NONE) {
ngx_wasm_shm_unlock(metrics->shm);
ngx_wa_shm_unlock(metrics->shm);
}
#endif

Expand All @@ -482,7 +482,7 @@ ngx_wa_metrics_get(ngx_wa_metrics_t *metrics, uint32_t mid, ngx_wa_metric_t *o)
ngx_str_t *n;
ngx_wa_metric_t *m;

rc = ngx_wasm_shm_kv_get_locked(metrics->shm, NULL, &mid, &n, &cas);
rc = ngx_wa_shm_kv_get_locked(metrics->shm, NULL, &mid, &n, &cas);
if (rc != NGX_OK) {
goto done;
}
Expand Down
6 changes: 3 additions & 3 deletions src/common/metrics/ngx_wa_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define _NGX_WA_METRICS_H_INCLUDED_


#include <ngx_wasm_shm_kv.h>
#include <ngx_wa_shm_kv.h>


#define ngx_wa_metrics_counter(m) m->slots[0].counter
Expand Down Expand Up @@ -68,10 +68,10 @@ typedef struct {

struct ngx_wa_metrics_s {
ngx_uint_t workers;
ngx_wasm_shm_t *shm;
ngx_wa_shm_t *shm;
ngx_wa_metrics_t *old_metrics;
ngx_wa_metrics_conf_t config;
ngx_wasm_shm_mapping_t *mapping;
ngx_wa_shm_mapping_t *mapping;
};


Expand Down
Loading

0 comments on commit 1d9b3f0

Please sign in to comment.