@cryptotaxi247 / netdata-1 / commits / 5af2aba6d

Schedule journal file indexing after database file rotation (#20264)

* Add indexing flag to track and enqueue journal indexing after database rotation * Remove unused job

Stelios Fragkakis committed May 9, 2025 at 20:05 UTC 5af2aba6d1523ca1db34ffa31d5080215310e2b9
4 files changed +6 -3
src/daemon/libuv_workers.c
-1
@@ -26,7 +26,6 @@ static void register_libuv_worker_jobs_internal(void) {
26 worker_register_job_name(UV_EVENT_DBENGINE_FLUSHED_TO_OPEN, "flushed to open");
27
28 // datafile full
29 - worker_register_job_name(UV_EVENT_DBENGINE_JOURNAL_INDEX_WAIT, "jv2 index wait");
29 worker_register_job_name(UV_EVENT_DBENGINE_JOURNAL_INDEX, "jv2 indexing");
30
31 // db rotation related
src/daemon/libuv_workers.h
-1
@@ -24,7 +24,6 @@ enum event_loop_job {
24 UV_EVENT_DBENGINE_FLUSHED_TO_OPEN,
25
26 // datafile full
27 - UV_EVENT_DBENGINE_JOURNAL_INDEX_WAIT,
27 UV_EVENT_DBENGINE_JOURNAL_INDEX,
28
29 // db rotation related
src/database/engine/rrdengine.c
+5 -1
@@ -919,6 +919,8 @@ done:
919
920 static void after_database_rotate(struct rrdengine_instance *ctx __maybe_unused, void *data __maybe_unused, struct completion *completion __maybe_unused, uv_work_t* req __maybe_unused, int status __maybe_unused) {
921 __atomic_store_n(&ctx->atomic.now_deleting_files, false, __ATOMIC_RELAXED);
922 + if (__atomic_load_n(&ctx->atomic.needs_indexing, __ATOMIC_RELAXED))
923 + rrdeng_enq_cmd(ctx, RRDENG_OPCODE_JOURNAL_INDEX, NULL, NULL, STORAGE_PRIORITY_INTERNAL_DBENGINE, NULL, NULL);
924 }
925
926 struct uuid_first_time_s {
@@ -1675,7 +1677,6 @@ NOT_INLINE_HOT void pdc_route_synchronously_first(struct rrdengine_instance *ctx
1677
1678 static void *journal_v2_indexing_tp_worker(struct rrdengine_instance *ctx __maybe_unused, void *data __maybe_unused, struct completion *completion __maybe_unused, uv_work_t *uv_work_req __maybe_unused) {
1679 unsigned count = 0;
1678 - worker_is_busy(UV_EVENT_DBENGINE_JOURNAL_INDEX_WAIT);
1680
1681 struct rrdengine_datafile *datafile = ctx->datafiles.first;
1682 worker_is_busy(UV_EVENT_DBENGINE_JOURNAL_INDEX);
@@ -2180,8 +2181,11 @@ void dbengine_event_loop(void* arg) {
2181 struct rrdengine_datafile *datafile = cmd.data;
2182 if (NOT_INDEXING_OR_DELETING_FILES(ctx) && ctx_is_available_for_queries(ctx)) {
2183 __atomic_store_n(&ctx->atomic.migration_to_v2_running, true, __ATOMIC_RELAXED);
2184 + __atomic_store_n(&ctx->atomic.needs_indexing, false, __ATOMIC_RELAXED);
2185 work_dispatch(ctx, datafile, NULL, opcode, journal_v2_indexing_tp_worker, after_journal_v2_indexing);
2186 }
2187 + else
2188 + __atomic_store_n(&ctx->atomic.needs_indexing, true, __ATOMIC_RELAXED);
2189 break;
2190 }
2191
src/database/engine/rrdengine.h
+1
@@ -396,6 +396,7 @@ struct rrdengine_instance {
396
397 PAD64(bool) migration_to_v2_running;
398 PAD64(bool) now_deleting_files;
399 + PAD64(bool) needs_indexing;
400 PAD64(unsigned) extents_currently_being_flushed; // non-zero until we commit data to disk (both datafile and journal file)
401
402 PAD64(time_t) first_time_s;