Improve journal v2 file creation on startup (#20619)
On startup when building jv2 files, do not yield the processor
Stelios Fragkakis committed
Jul 2, 2025 at 18:02 UTC
0f8a7788235f4f6ce8234e331113e09d9e7dd9e1
4 files changed
+37
-8
src/database/engine/cache.c
+13
-3
@@ -2418,7 +2418,15 @@ size_t pgc_hot_and_dirty_entries(PGC *cache) {
2418
return entries;
2419
}
2420
2421
-void pgc_open_cache_to_journal_v2(PGC *cache, Word_t section, unsigned datafile_fileno, uint8_t type, migrate_to_v2_callback cb, void *data) {
2421
+void pgc_open_cache_to_journal_v2(
2422
+ PGC *cache,
2423
+ Word_t section,
2424
+ unsigned datafile_fileno,
2425
+ uint8_t type,
2426
+ migrate_to_v2_callback cb,
2427
+ void *data,
2428
+ bool startup)
2429
+{
2430
__atomic_add_fetch(&rrdeng_cache_efficiency_stats.journal_v2_indexing_started, 1, __ATOMIC_RELAXED);
2431
p2_add_fetch(&cache->stats.p2_workers_jv2_flush, 1);
2432
@@ -2555,7 +2563,8 @@ void pgc_open_cache_to_journal_v2(PGC *cache, Word_t section, unsigned datafile_
2563
page_release(cache, page, false);
2564
}
2565
2558
- yield_the_processor(); // do not lock too aggressively
2566
+ if (likely(false == startup))
2567
+ yield_the_processor(); // do not lock too aggressively
2568
pgc_queue_lock(cache, &cache->hot, PGC_QUEUE_LOCK_PRIO_LOW);
2569
}
2570
@@ -2578,7 +2587,8 @@ void pgc_open_cache_to_journal_v2(PGC *cache, Word_t section, unsigned datafile_
2587
while ((PValue2 = JudyLFirstThenNext(mi->JudyL_pages_by_start_time, &start_time, &start_time_first))) {
2588
struct jv2_page_info *pi = *PValue2;
2589
2581
- yield_the_processor(); // do not lock too aggressively
2590
+ if (likely(false == startup))
2591
+ yield_the_processor(); // do not lock too aggressively
2592
if (likely(success))
2593
page_set_clean(cache, pi->page, true, false, PGC_QUEUE_LOCK_PRIO_LOW);
2594
else
src/database/engine/cache.h
+8
-1
@@ -228,7 +228,14 @@ void pgc_page_hot_set_end_time_s(PGC *cache, PGC_PAGE *page, time_t end_time_s,
228
bool pgc_page_to_clean_evict_or_release(PGC *cache, PGC_PAGE *page);
229
230
typedef bool (*migrate_to_v2_callback)(Word_t section, unsigned datafile_fileno, uint8_t type, Pvoid_t JudyL_metrics, Pvoid_t JudyL_extents_pos, size_t count_of_unique_extents, size_t count_of_unique_metrics, size_t count_of_unique_pages, void *data);
231
-void pgc_open_cache_to_journal_v2(PGC *cache, Word_t section, unsigned datafile_fileno, uint8_t type, migrate_to_v2_callback cb, void *data);
231
+void pgc_open_cache_to_journal_v2(
232
+ PGC *cache,
233
+ Word_t section,
234
+ unsigned datafile_fileno,
235
+ uint8_t type,
236
+ migrate_to_v2_callback cb,
237
+ void *data,
238
+ bool startup);
239
void pgc_open_evict_clean_pages_of_datafile(PGC *cache, struct rrdengine_datafile *datafile);
240
size_t pgc_count_clean_pages_having_data_ptr(PGC *cache, Word_t section, void *ptr);
241
size_t pgc_count_hot_pages_having_data_ptr(PGC *cache, Word_t section, void *ptr);
src/database/engine/journalfile.c
+8
-2
@@ -1585,8 +1585,14 @@ int journalfile_load(struct rrdengine_instance *ctx, struct rrdengine_journalfil
1585
return 0;
1586
}
1587
1588
- pgc_open_cache_to_journal_v2(open_cache, (Word_t) ctx, (int) datafile->fileno, ctx->config.page_type,
1589
- journalfile_migrate_to_v2_callback, (void *) datafile->journalfile);
1588
+ pgc_open_cache_to_journal_v2(
1589
+ open_cache,
1590
+ (Word_t)ctx,
1591
+ (int)datafile->fileno,
1592
+ ctx->config.page_type,
1593
+ journalfile_migrate_to_v2_callback,
1594
+ (void *)datafile->journalfile,
1595
+ true);
1596
1597
if (is_last_file)
1598
ctx->loading.create_new_datafile_pair = true;
src/database/engine/rrdengine.c
+8
-2
@@ -1838,8 +1838,14 @@ static void *journal_v2_indexing_tp_worker(struct rrdengine_instance *ctx, void
1838
}
1839
nd_log_daemon(NDLP_INFO, "DBENGINE: journal file \"%s\" is ready to be indexed", path);
1840
1841
- pgc_open_cache_to_journal_v2(open_cache, (Word_t) ctx, (int) datafile->fileno, ctx->config.page_type,
1842
- journalfile_migrate_to_v2_callback, (void *) datafile->journalfile);
1841
+ pgc_open_cache_to_journal_v2(
1842
+ open_cache,
1843
+ (Word_t)ctx,
1844
+ (int)datafile->fileno,
1845
+ ctx->config.page_type,
1846
+ journalfile_migrate_to_v2_callback,
1847
+ (void *)datafile->journalfile,
1848
+ false);
1849
1850
index_once = true;
1851