Fix multi-host DB corruption when legacy metrics reside in localhost. (#9855)
Markos Fountoulakis committed
Sep 1, 2020 at 11:32 UTC
d521566bc264788413a8d176d4c75045c873f0a8
1 file changed
+7
-3
database/engine/rrdengineapi.c
+7
-3
@@ -56,7 +56,8 @@ void rrdeng_metric_init(RRDDIM *rd, uuid_t *dim_uuid)
56
uuid_t legacy_uuid;
57
Pvoid_t *PValue;
58
struct pg_cache_page_index *page_index = NULL;
59
- int replace_instead_of_generate = 0;
59
+ int replace_instead_of_generate = 0, is_multihost_child = 0;
60
+ RRDHOST *host = rd->rrdset->rrdhost;
61
62
ctx = get_rrdeng_ctx_from_host(rd->rrdset->rrdhost);
63
if (unlikely(!ctx)) {
@@ -67,6 +68,8 @@ void rrdeng_metric_init(RRDDIM *rd, uuid_t *dim_uuid)
68
69
rrdeng_generate_legacy_uuid(rd->id, rd->rrdset->id, &legacy_uuid);
70
rd->state->metric_uuid = callocz(1, sizeof(uuid_t));
71
+ if (host != localhost && host->rrdeng_ctx == &multidb_ctx)
72
+ is_multihost_child = 1;
73
74
uv_rwlock_rdlock(&pg_cache->metrics_index.lock);
75
PValue = JudyHSGet(pg_cache->metrics_index.JudyHS_array, &legacy_uuid, sizeof(uuid_t));
@@ -74,8 +77,9 @@ void rrdeng_metric_init(RRDDIM *rd, uuid_t *dim_uuid)
77
page_index = *PValue;
78
}
79
uv_rwlock_rdunlock(&pg_cache->metrics_index.lock);
77
- if (NULL == PValue) {
78
- /* First time we see the legacy UUID, drop legacy support, normal path */
80
+ if (is_multihost_child || NULL == PValue) {
81
+ /* First time we see the legacy UUID or metric belongs to child host in multi-host DB.
82
+ * Drop legacy support, normal path */
83
84
if (NULL != dim_uuid) {
85
replace_instead_of_generate = 1;