Skip to content

Commit

Permalink
hotfix(metrics) old metrics cleanup
Browse files Browse the repository at this point in the history
`ngx_wa_metrics_init_conf` seems a more appropriate place to set
`old_metrics->shm_zone->noreuse` to 1.

Then `ngx_wa_metrics_init` only acts according to the then configured
values.
  • Loading branch information
casimiro committed Jun 24, 2024
1 parent 6a6f7a0 commit 5de54b1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/common/metrics/ngx_wa_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ ngx_wa_metrics_init_conf(ngx_wa_metrics_t *metrics, ngx_conf_t *cf)
&& (metrics->workers != old_metrics->workers
|| metrics->config.slab_size != old_metrics->config.slab_size))
{
/* both old and current kv store have to be marked for cleanup */
old_metrics->shm_zone->noreuse = 1;
metrics->shm_zone->noreuse = 1;
}

Expand All @@ -230,7 +232,7 @@ ngx_wa_metrics_init(ngx_wa_metrics_t *metrics, ngx_cycle_t *cycle)
{
ngx_wasm_shm_kv_t *old_shm_kv;

if (metrics->old_metrics && !metrics->shm_zone->noreuse) {
if (metrics->old_metrics && !metrics->old_metrics->shm_zone->noreuse) {
/* reuse old kv store */
metrics->shm->data = metrics->old_metrics->shm->data;
return NGX_OK;
Expand All @@ -240,14 +242,13 @@ ngx_wa_metrics_init(ngx_wa_metrics_t *metrics, ngx_cycle_t *cycle)
return NGX_ERROR;
}

if (metrics->old_metrics && metrics->shm_zone->noreuse) {
/* mark the old kv store for cleanup during SIGHUP old_cycle free */
metrics->old_metrics->shm_zone->noreuse = 1;
if (metrics->old_metrics && metrics->old_metrics->shm_zone->noreuse) {
/* relable current kv store as reusable */
metrics->shm_zone->noreuse = 0;

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

/* realloc old kv store */
return realloc_metrics(metrics, old_shm_kv->rbtree.root,
old_shm_kv->rbtree.sentinel);
}
Expand Down

0 comments on commit 5de54b1

Please sign in to comment.