@cryptotaxi247 / netdata-1 / commits / c24c7427b

Improve DBENGINE log messages for datafile rotation and startup (#22047)

* Refactor log messages for enhanced clarity in data and journal file operations, emphasizing tier-specific deletion and retention handling. * Improve clarity in log messages for metric deletion and journal file operations. Adjust retention handling descriptions and documentation for consistency. * Refactor log messages and type declarations in database engine for improved clarity, consistency, and correctness across journal file and data file operations. * Enhance logging and deletion handling in DBENGINE for journal file operations - Improve log clarity with standardized type formats (`PRIu64`, `uint64_t`) and error preservation during readiness checks. - Refactor journal file deletion to integrate `uv_fs_unlink()` with detailed error logging and cleanups. - Introduce expected journal file validation to ensure accurate deletion reporting and handling for `.njf` and `.njfv2` files. * Refactor journal file operations: separate `uv_fs_t` instances for V1 and V2, improve cleanup handling, and update V2 data availability check logic.

Stelios Fragkakis committed Mar 26, 2026 at 21:46 UTC c24c7427b0caa318e3fab45d1c062e121d9886a3
6 files changed +137 -77
src/database/engine/cache.c
+2 -1
@@ -2468,7 +2468,8 @@ void pgc_open_cache_to_journal_v2(
2468
2469 struct section_pages *sp = *section_pages_pptr;
2470 if(!spinlock_trylock(&sp->migration_to_v2_spinlock)) {
2471 - netdata_log_info("DBENGINE: migration to journal v2 for datafile %u is postponed, another jv2 indexer is already running for this section", datafile_fileno);
2471 + netdata_log_info("DBENGINE: migration to journal v2 for datafile %u (section %" PRIu64 ") is postponed, another jv2 indexer is already running for this section",
2472 + datafile_fileno, (uint64_t)section);
2473 pgc_queue_unlock(cache, &cache->hot);
2474 return;
2475 }
src/database/engine/datafile.c
+9 -12
@@ -134,8 +134,8 @@ bool datafile_acquire_for_deletion(struct rrdengine_datafile *df, bool is_shutdo
134 spinlock_unlock(&df->users.spinlock);
135
136 if(marked_pending)
137 - netdata_log_info("DBENGINE: datafile %u of tier %d is pending deletion (%s)",
138 - df->fileno, datafile_ctx(df)->config.tier, is_shutdown ? "shutdown" : "runtime");
137 + netdata_log_info("DBENGINE: tier %d: " DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL " is pending deletion (%s)",
138 + datafile_ctx(df)->config.tier, datafile_ctx(df)->config.tier, df->fileno, is_shutdown ? "shutdown" : "runtime");
139
140 if(can_be_deleted)
141 return true;
@@ -158,8 +158,8 @@ bool datafile_acquire_for_deletion(struct rrdengine_datafile *df, bool is_shutdo
158 if(!writers_running && !flushed_to_open_running) {
159 if(df->users.available) {
160 df->users.available = false;
161 - netdata_log_info("DBENGINE: datafile %u of tier %d entered deletion phase-2 (new users blocked)",
162 - df->fileno, datafile_ctx(df)->config.tier);
161 + netdata_log_info("DBENGINE: tier %d: " DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL " entered deletion phase-2 (new users blocked)",
162 + datafile_ctx(df)->config.tier, datafile_ctx(df)->config.tier, df->fileno);
163 }
164
165 if(!df->users.lockers)
@@ -428,7 +428,7 @@ static int scan_data_files(struct rrdengine_instance *ctx)
428 ctx_fs_error(ctx);
429 return ret;
430 }
431 - netdata_log_info("DBENGINE: found %d files in path %s", ret, ctx->config.dbfiles_path);
431 + netdata_log_info("DBENGINE: tier %d: found %d files in path %s", ctx->config.tier, ret, ctx->config.dbfiles_path);
432
433 Pvoid_t datafiles_JudyL = NULL;
434 Pvoid_t journafile_JudyL = NULL;
@@ -533,7 +533,7 @@ static int scan_data_files(struct rrdengine_instance *ctx)
533 (void) JudyLFreeArray(&datafiles_JudyL, NULL);
534
535
536 - netdata_log_info("DBENGINE: loading %d data/journal of tier %d...", matched_files, ctx->config.tier);
536 + netdata_log_info("DBENGINE: tier %d: loading %d data/journal files...", ctx->config.tier, matched_files);
537 for (failed_to_load = 0, i = 0 ; i < matched_files ; ++i) {
538 uint8_t must_delete_pair = 0;
539
@@ -589,7 +589,6 @@ int create_new_datafile_pair(struct rrdengine_instance *ctx)
589 struct rrdengine_journalfile *journalfile;
590 unsigned fileno = ctx_last_fileno_get(ctx) + 1;
591 int ret;
592 - char path[RRDENG_PATH_MAX];
592
593 nd_log(NDLS_DAEMON, NDLP_DEBUG,
594 "DBENGINE: creating new data and journal files in path \"%s\"",
@@ -600,16 +599,14 @@ int create_new_datafile_pair(struct rrdengine_instance *ctx)
599 if(ret)
600 goto error_after_datafile;
601
603 - generate_datafilepath(datafile, path, sizeof(path));
604 - nd_log(NDLS_DAEMON, NDLP_INFO, "DBENGINE: created data file \"%s\".", path);
605 -
602 journalfile = journalfile_alloc_and_init(datafile);
603 ret = journalfile_create(journalfile, datafile);
604 if (ret)
605 goto error_after_journalfile;
606
611 - journalfile_v1_generate_path(datafile, path, sizeof(path));
612 - nd_log(NDLS_DAEMON, NDLP_INFO, "DBENGINE: created journal file \"%s\".", path);
607 + nd_log(NDLS_DAEMON, NDLP_INFO,
608 + "DBENGINE: tier %d: created " DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL " (.ndf, .njf).",
609 + ctx->config.tier, ctx->config.tier, datafile->fileno);
610
611 ctx_current_disk_space_increase(ctx, datafile->pos + journalfile->unsafe.pos);
612 datafile_list_insert(ctx, datafile);
src/database/engine/journalfile.c
+25 -11
@@ -544,10 +544,12 @@ int journalfile_unlink(struct rrdengine_journalfile *journalfile)
544 return ret;
545 }
546
547 -int journalfile_destroy_unsafe(struct rrdengine_journalfile *journalfile, struct rrdengine_datafile *datafile)
547 +uint8_t journalfile_destroy_unsafe(struct rrdengine_journalfile *journalfile, struct rrdengine_datafile *datafile)
548 {
549 struct rrdengine_instance *ctx = datafile_ctx(datafile);
550 int ret;
551 + uv_fs_t req_v2 = { 0 };
552 + uv_fs_t req_v1 = { 0 };
553 char path[RRDENG_PATH_MAX];
554 char path_v2[RRDENG_PATH_MAX];
555
@@ -563,18 +565,29 @@ int journalfile_destroy_unsafe(struct rrdengine_journalfile *journalfile, struct
565 journalfile_v2_data_unmap_permanently(journalfile);
566
567 // Now safe to delete the files - no threads are accessing them
566 - int deleted = 0;
567 - UNLINK_FILE(ctx, path_v2, ret);
568 + uint8_t deleted = 0;
569 +
570 + ret = uv_fs_unlink(NULL, &req_v2, path_v2, NULL);
571 if (ret == 0)
569 - deleted++;
572 + deleted |= JOURNALFILE_DELETED_V2;
573 + else if (ret != UV_ENOENT) {
574 + netdata_log_error("DBENGINE: uv_fs_unlink(\"%s\"): %s", path_v2, uv_strerror(ret));
575 + ctx_fs_error(ctx);
576 + }
577 + uv_fs_req_cleanup(&req_v2);
578
571 - UNLINK_FILE(ctx, path, ret);
579 + ret = uv_fs_unlink(NULL, &req_v1, path, NULL);
580 if (ret == 0)
573 - deleted++;
581 + deleted |= JOURNALFILE_DELETED_V1;
582 + else if (ret != UV_ENOENT) {
583 + netdata_log_error("DBENGINE: uv_fs_unlink(\"%s\"): %s", path, uv_strerror(ret));
584 + ctx_fs_error(ctx);
585 + }
586 + uv_fs_req_cleanup(&req_v1);
587
575 - __atomic_add_fetch(&ctx->stats.journalfile_deletions, deleted, __ATOMIC_RELAXED);
588 + __atomic_add_fetch(&ctx->stats.journalfile_deletions, __builtin_popcount(deleted), __ATOMIC_RELAXED);
589
577 - return ret;
590 + return deleted;
591 }
592
593 int journalfile_create(struct rrdengine_journalfile *journalfile, struct rrdengine_datafile *datafile)
@@ -1360,8 +1373,8 @@ bool journalfile_migrate_to_v2_callback(Word_t section, unsigned datafile_fileno
1373
1374 journalfile_v2_generate_path(datafile, path, sizeof(path));
1375
1363 - netdata_log_info("DBENGINE: indexing file \"%s\": extents %zu, metrics %zu, pages %zu",
1364 - path,
1376 + netdata_log_info("DBENGINE: tier %d: indexing " DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL ".njfv2: extents %zu, metrics %zu, pages %zu",
1377 + datafile_ctx(datafile)->config.tier, datafile_ctx(datafile)->config.tier, datafile->fileno,
1378 number_of_extents,
1379 number_of_metrics,
1380 number_of_pages);
@@ -1554,7 +1567,8 @@ bool journalfile_migrate_to_v2_callback(Word_t section, unsigned datafile_fileno
1567
1568 char size_for_humans[128];
1569 size_snprintf(size_for_humans, sizeof(size_for_humans), total_file_size, "B", false);
1557 - netdata_log_info("DBENGINE: migrated journal file \"%s\", file size %zu bytes (%s)", path, total_file_size, size_for_humans);
1570 + netdata_log_info("DBENGINE: tier %d: migrated " DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL ".njfv2, %s",
1571 + ctx->config.tier, ctx->config.tier, datafile->fileno, size_for_humans);
1572
1573 // msync(data_start, total_file_size, MS_SYNC);
1574 journalfile_v2_data_set(journalfile, fd_v2, data_start, total_file_size);
src/database/engine/journalfile.h
+9 -1
@@ -262,7 +262,15 @@ struct rrdengine_journalfile *journalfile_alloc_and_init(struct rrdengine_datafi
262 int journalfile_v1_extent_write(struct rrdengine_instance *ctx, struct rrdengine_datafile *datafile, struct wal *wal);
263 int journalfile_close(struct rrdengine_journalfile *journalfile, struct rrdengine_datafile *datafile);
264 int journalfile_unlink(struct rrdengine_journalfile *journalfile);
265 -int journalfile_destroy_unsafe(struct rrdengine_journalfile *journalfile, struct rrdengine_datafile *datafile);
265 +#define JOURNALFILE_DELETED_V1 (1u << 0) // .njf was deleted
266 +#define JOURNALFILE_DELETED_V2 (1u << 1) // .njfv2 was deleted
267 +#define JOURNALFILE_DELETED_ALL (JOURNALFILE_DELETED_V1 | JOURNALFILE_DELETED_V2)
268 +/*
269 + * Destroys the journal file and returns a JOURNALFILE_DELETED_* bitmask
270 + * indicating which on-disk journal files were deleted. This is not a
271 + * 0 / -errno style status code.
272 + */
273 +uint8_t journalfile_destroy_unsafe(struct rrdengine_journalfile *journalfile, struct rrdengine_datafile *datafile);
274 int journalfile_create(struct rrdengine_journalfile *journalfile, struct rrdengine_datafile *datafile);
275 int journalfile_load(struct rrdengine_instance *ctx, struct rrdengine_journalfile *journalfile,
276 struct rrdengine_datafile *datafile);
src/database/engine/rrdengine.c
+86 -50
@@ -1375,7 +1375,7 @@ static void update_metrics_first_time_s(struct rrdengine_instance *ctx, struct r
1375 }
1376
1377 netdata_log_info(
1378 - "DBENGINE: recalculating tier %d retention for %zu metrics starting with datafile %u",
1378 + "DBENGINE: tier %d: recalculating retention for %zu metrics starting with datafile %u",
1379 ctx->config.tier,
1380 count,
1381 first_datafile_remaining ? first_datafile_remaining->fileno : 0);
@@ -1400,7 +1400,7 @@ static void update_metrics_first_time_s(struct rrdengine_instance *ctx, struct r
1400 if(worker)
1401 worker_is_busy(UV_EVENT_DBENGINE_POPULATE_MRG);
1402
1403 - netdata_log_info("DBENGINE: updating tier %d metrics registry retention for %zu metrics", ctx->config.tier, added);
1403 + netdata_log_info("DBENGINE: tier %d: updating metrics registry retention for %zu metrics", ctx->config.tier, added);
1404
1405 size_t deleted_metrics = 0, zero_retention_referenced = 0, zero_disk_retention = 0, zero_disk_but_live = 0;
1406 for (size_t index = 0; index < added; ++index) {
@@ -1456,8 +1456,9 @@ static void update_metrics_first_time_s(struct rrdengine_instance *ctx, struct r
1456 goto done;
1457
1458 internal_error(zero_disk_retention,
1459 - "DBENGINE: deleted %zu metrics, zero retention but referenced %zu (out of %zu total, of which %zu have main cache retention) zero on-disk retention tier %d metrics from metrics registry",
1460 - deleted_metrics, zero_retention_referenced, zero_disk_retention, zero_disk_but_live, ctx->config.tier);
1459 + "DBENGINE: tier %d: deleted %zu metrics from metrics registry; %zu still had zero retention but were referenced "
1460 + "(out of %zu total zero on-disk retention metrics, of which %zu have main cache retention)",
1461 + ctx->config.tier, deleted_metrics, zero_retention_referenced, zero_disk_retention, zero_disk_but_live);
1462
1463 if(global_first_time_s != LONG_MAX)
1464 __atomic_store_n(&ctx->atomic.first_time_s, global_first_time_s, __ATOMIC_RELAXED);
@@ -1476,6 +1477,9 @@ void datafile_delete(
1477 bool disk_time,
1478 bool worker)
1479 {
1480 + unsigned tier = ctx->config.tier;
1481 + unsigned fileno = datafile->fileno;
1482 +
1483 if(worker)
1484 worker_is_busy(UV_EVENT_DBENGINE_DATAFILE_DELETE_WAIT);
1485
@@ -1493,9 +1497,10 @@ void datafile_delete(
1497 // pending_deletion is already set, blocking new acquires.
1498 // Bail out and let the next rotation cycle retry - lockers
1499 // will drain over time since no new ones can be added.
1496 - netdata_log_error("DBENGINE: datafile %u of tier %d could not be acquired for deletion "
1497 - "after %zu attempts (%u lockers remain) - will retry on next rotation",
1498 - datafile->fileno, ctx->config.tier, attempts, datafile->users.lockers);
1500 + netdata_log_error("DBENGINE: tier %d: " DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL
1501 + " could not be acquired for deletion after %zu attempts (%u lockers remain)"
1502 + " - will retry on next rotation",
1503 + tier, tier, fileno, attempts, datafile->users.lockers);
1504
1505 if(worker)
1506 worker_is_idle();
@@ -1503,22 +1508,15 @@ void datafile_delete(
1508 return;
1509 }
1510
1506 - netdata_log_info("DBENGINE: waiting for data file '%s/"
1507 - DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL DATAFILE_EXTENSION
1508 - "' to be available for deletion, "
1509 - "it is in use currently by %u users.",
1510 - ctx->config.dbfiles_path, datafile->tier, datafile->fileno, datafile->users.lockers);
1511 + netdata_log_info("DBENGINE: tier %d: waiting for " DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL
1512 + " to be available for deletion, in use by %u users.",
1513 + tier, tier, fileno, datafile->users.lockers);
1514
1515 __atomic_add_fetch(&rrdeng_cache_efficiency_stats.datafile_deletion_spin, 1, __ATOMIC_RELAXED);
1516 sleep_usec(1 * USEC_PER_SEC);
1517 }
1518 }
1519
1517 - netdata_log_info("DBENGINE: acquired data file \"%s/"
1518 - DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL DATAFILE_EXTENSION
1519 - "\" for deletion.",
1520 - ctx->config.dbfiles_path, datafile->tier, datafile->fileno);
1521 -
1520 if (update_retention)
1521 update_metrics_first_time_s(ctx, datafile, get_next_datafile(datafile, NULL, false), worker);
1522
@@ -1530,18 +1528,18 @@ void datafile_delete(
1528 // }
1529
1530 __atomic_add_fetch(&rrdeng_cache_efficiency_stats.datafile_deletion_started, 1, __ATOMIC_RELAXED);
1533 - netdata_log_info("DBENGINE: deleting data file \"%s/"
1534 - DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL DATAFILE_EXTENSION
1535 - "\".",
1536 - ctx->config.dbfiles_path, datafile->tier, datafile->fileno);
1531 + netdata_log_info("DBENGINE: tier %d: deleting " DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL " to maintain %s.",
1532 + tier, tier, fileno, disk_time ? "disk quota" : "time retention");
1533
1534 if(worker)
1535 worker_is_busy(UV_EVENT_DBENGINE_DATAFILE_DELETE);
1536
1537 struct rrdengine_journalfile *journal_file;
1538 size_t deleted_bytes, journal_file_bytes, datafile_bytes;
1539 + uint8_t deleted_journal_files = 0;
1540 + uint8_t expected_journal_files = JOURNALFILE_DELETED_V1;
1541 + bool deleted_datafile = false;
1542 int ret;
1544 - char path[RRDENG_PATH_MAX];
1543
1544 netdata_rwlock_wrlock(&ctx->datafiles.rwlock);
1545 datafile_list_delete_unsafe(ctx, datafile);
@@ -1550,23 +1548,21 @@ void datafile_delete(
1548 journal_file = datafile->journalfile;
1549 datafile_bytes = datafile->pos;
1550 journal_file_bytes = journalfile_current_size(journal_file);
1553 - deleted_bytes = journalfile_v2_data_size_get(journal_file);
1554 -
1555 - netdata_log_info("DBENGINE: deleting data and journal files to maintain %s", disk_time ? "disk quota" : "time retention");
1556 - // This will delete journalfile_v2 and journalfile_v1
1557 - ret = journalfile_destroy_unsafe(journal_file, datafile);
1558 - if (!ret) {
1559 - journalfile_v1_generate_path(datafile, path, sizeof(path));
1560 - netdata_log_info("DBENGINE: deleted journal file \"%s\".", path);
1561 - journalfile_v2_generate_path(datafile, path, sizeof(path));
1562 - netdata_log_info("DBENGINE: deleted journal file \"%s\".", path);
1551 + size_t journal_v2_bytes = journalfile_v2_data_size_get(journal_file);
1552 + if (journalfile_v2_data_available(journal_file))
1553 + expected_journal_files |= JOURNALFILE_DELETED_V2;
1554 + deleted_bytes = 0;
1555 +
1556 + // This will delete journalfile_v2 and journalfile_v1 (returns bitmask of JOURNALFILE_DELETED_V1/V2)
1557 + deleted_journal_files = journalfile_destroy_unsafe(journal_file, datafile);
1558 + if (deleted_journal_files & JOURNALFILE_DELETED_V1)
1559 deleted_bytes += journal_file_bytes;
1564 - }
1560 + if (deleted_journal_files & JOURNALFILE_DELETED_V2)
1561 + deleted_bytes += journal_v2_bytes;
1562 // This will delete the datafile
1563 ret = destroy_data_file_unsafe(datafile);
1564 if (!ret) {
1568 - generate_datafilepath(datafile, path, sizeof(path));
1569 - netdata_log_info("DBENGINE: deleted data file \"%s\".", path);
1565 + deleted_datafile = true;
1566 deleted_bytes += datafile_bytes;
1567 }
1568
@@ -1581,7 +1577,48 @@ void datafile_delete(
1577 ctx_current_disk_space_decrease(ctx, deleted_bytes);
1578 char size_for_humans[128];
1579 size_snprintf(size_for_humans, sizeof(size_for_humans), deleted_bytes, "B", false);
1584 - netdata_log_info("DBENGINE: reclaimed %zu bytes (%s) of disk space.", deleted_bytes, size_for_humans);
1580 +
1581 + bool del_ndf = deleted_datafile;
1582 + bool del_njf = deleted_journal_files & JOURNALFILE_DELETED_V1;
1583 + bool del_njfv2 = deleted_journal_files & JOURNALFILE_DELETED_V2;
1584 + bool exp_njf = expected_journal_files & JOURNALFILE_DELETED_V1;
1585 + bool exp_njfv2 = expected_journal_files & JOURNALFILE_DELETED_V2;
1586 +
1587 + if (del_ndf && del_njf && del_njfv2)
1588 + netdata_log_info("DBENGINE: tier %d: deleted " DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL " (.ndf, .njf, .njfv2), reclaimed %s.",
1589 + tier, tier, fileno, size_for_humans);
1590 + else if (del_ndf && del_njf && !exp_njfv2)
1591 + netdata_log_info("DBENGINE: tier %d: deleted " DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL " (.ndf, .njf), reclaimed %s.",
1592 + tier, tier, fileno, size_for_humans);
1593 + else if (del_ndf || del_njf || del_njfv2) {
1594 + BUFFER *removed = buffer_create(0, NULL);
1595 + BUFFER *failed = buffer_create(0, NULL);
1596 + const char *sep;
1597 +
1598 + sep = "";
1599 + if (del_ndf) { buffer_strcat(removed, sep); buffer_strcat(removed, ".ndf"); sep = ", "; }
1600 + if (del_njf) { buffer_strcat(removed, sep); buffer_strcat(removed, ".njf"); sep = ", "; }
1601 + if (del_njfv2) { buffer_strcat(removed, sep); buffer_strcat(removed, ".njfv2"); }
1602 +
1603 + sep = "";
1604 + if (!del_ndf) { buffer_strcat(failed, sep); buffer_strcat(failed, ".ndf"); sep = ", "; }
1605 + if (exp_njf && !del_njf) { buffer_strcat(failed, sep); buffer_strcat(failed, ".njf"); sep = ", "; }
1606 + if (exp_njfv2 && !del_njfv2) { buffer_strcat(failed, sep); buffer_strcat(failed, ".njfv2"); }
1607 +
1608 + if(buffer_strlen(failed))
1609 + netdata_log_error("DBENGINE: tier %d: partial delete of " DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL
1610 + " - removed: %s, failed: %s, reclaimed %s.",
1611 + tier, tier, fileno,
1612 + buffer_tostring(removed), buffer_tostring(failed), size_for_humans);
1613 + else
1614 + netdata_log_info("DBENGINE: tier %d: deleted " DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL " (%s), reclaimed %s.",
1615 + tier, tier, fileno, buffer_tostring(removed), size_for_humans);
1616 + buffer_free(removed);
1617 + buffer_free(failed);
1618 + }
1619 + else
1620 + netdata_log_error("DBENGINE: tier %d: failed to delete " DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL " to maintain %s.",
1621 + tier, tier, fileno, disk_time ? "disk quota" : "time retention");
1622 }
1623
1624 static void *database_rotate_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) {
@@ -1688,7 +1725,7 @@ static void *populate_mrg_tp_worker(
1725 netdata_rwlock_rdunlock(&ctx->datafiles.rwlock);
1726
1727 if (total_datafiles == 0) {
1691 - nd_log_daemon(NDLP_WARNING, "DBENGINE: No datafiles to populate MRG");
1728 + nd_log_daemon(NDLP_WARNING, "DBENGINE: tier %d: no datafiles to populate MRG", tier);
1729 worker_is_idle();
1730 return data;
1731 }
@@ -1739,7 +1776,7 @@ static void *populate_mrg_tp_worker(
1776 nd_log_limit_static_thread_var(erl, 10, 0);
1777 size_t completed = __atomic_load_n(&populated_datafiles, __ATOMIC_RELAXED);
1778 nd_log_limit(&erl, NDLS_DAEMON, NDLP_INFO,
1742 - "DBENGINE: Tier %d MRG population completed: %.2f%% (%zu/%zu)",
1779 + "DBENGINE: tier %d: MRG population completed: %.2f%% (%zu/%zu)",
1780 tier, (completed * 100.0) / total_datafiles, completed, total_datafiles);
1781 }
1782 } while(1);
@@ -1752,7 +1789,7 @@ static void *populate_mrg_tp_worker(
1789 nd_log_limit_static_thread_var(erl, 10, 0);
1790 size_t completed = __atomic_load_n(&populated_datafiles, __ATOMIC_RELAXED);
1791 nd_log_limit(&erl, NDLS_DAEMON, NDLP_INFO,
1755 - "DBENGINE: Tier %d MRG population completed: %.2f%% (%zu/%zu), waiting for %zu workers",
1792 + "DBENGINE: tier %d: MRG population completed: %.2f%% (%zu/%zu), waiting for %zu workers",
1793 tier, (completed * 100.0) / total_datafiles, completed, total_datafiles, pending);
1794 sleep_usec(10 * USEC_PER_MS);
1795 }
@@ -1938,7 +1975,8 @@ static struct rrdengine_datafile *release_and_aquire_next_datafile_for_indexing(
1975 netdata_rwlock_rdunlock(&ctx->datafiles.rwlock);
1976 return datafile;
1977 }
1941 - nd_log_daemon(NDLP_INFO, "DBENGINE: Datafile %u CANNOT be locked for indexing after retries; skipping", datafile->fileno);
1978 + nd_log_daemon(NDLP_INFO, "DBENGINE: tier %d: " DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL " cannot be locked for indexing after retries; skipping",
1979 + ctx->config.tier, ctx->config.tier, datafile->fileno);
1980 datafile = get_next_datafile(datafile, NULL, true);
1981 }
1982 netdata_rwlock_rdunlock(&ctx->datafiles.rwlock);
@@ -1954,7 +1992,6 @@ static void *journal_v2_indexing_tp_worker(struct rrdengine_instance *ctx, void
1992
1993 worker_is_busy(UV_EVENT_DBENGINE_JOURNAL_INDEX);
1994 struct rrdengine_datafile *datafile = NULL;
1957 - char path[RRDENG_PATH_MAX];
1995
1996 bool index_once = false;
1997 while ((datafile = release_and_aquire_next_datafile_for_indexing(ctx, datafile))) {
@@ -1963,24 +2000,23 @@ static void *journal_v2_indexing_tp_worker(struct rrdengine_instance *ctx, void
2000 bool available = (datafile->writers.running || datafile->writers.flushed_to_open_running) ? false : true;
2001 spinlock_unlock(&datafile->writers.spinlock);
2002
1966 - journalfile_v1_generate_path(datafile, path, sizeof(path));
1967 -
2003 if(!available) {
2004 nd_log_daemon(NDLP_NOTICE,
1970 - "DBENGINE: journal file \"%s\" needs to be indexed, but it has writers working on it - "
1971 - "skipping it for now",
1972 - path);
2005 + "DBENGINE: tier %d: " DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL
2006 + " needs to be indexed, but it has writers working on it - skipping it for now",
2007 + ctx->config.tier, ctx->config.tier, datafile->fileno);
2008 continue;
2009 }
2010
2011 if (index_once && unlikely(rrdeng_ctx_tier_cap_exceeded(ctx))) {
2012 nd_log_daemon(
1978 - NDLP_INFO, "DBENGINE: tier %d reached quota limit, stopping journal indexing", ctx->config.tier);
2013 + NDLP_INFO, "DBENGINE: tier %d: reached quota limit, stopping journal indexing", ctx->config.tier);
2014 __atomic_store_n(&ctx->atomic.needs_indexing, true, __ATOMIC_RELAXED);
2015 datafile_release(datafile, DATAFILE_ACQUIRE_INDEXING);
2016 break;
2017 }
1983 - nd_log_daemon(NDLP_INFO, "DBENGINE: journal file \"%s\" is ready to be indexed", path);
2018 + nd_log_daemon(NDLP_INFO, "DBENGINE: tier %d: " DATAFILE_PREFIX RRDENG_FILE_NUMBER_PRINT_TMPL " is ready to be indexed",
2019 + ctx->config.tier, ctx->config.tier, datafile->fileno);
2020
2021 pgc_open_cache_to_journal_v2(
2022 open_cache,
@@ -2005,8 +2041,8 @@ static void *journal_v2_indexing_tp_worker(struct rrdengine_instance *ctx, void
2041 errno_clear();
2042 if(count)
2043 nd_log(NDLS_DAEMON, NDLP_DEBUG,
2008 - "DBENGINE: journal indexing done; %u files processed",
2009 - count);
2044 + "DBENGINE: tier %d: journal indexing done; %u files processed",
2045 + ctx->config.tier, count);
2046
2047 worker_is_idle();
2048
src/database/engine/rrdengineapi.c
+6 -2
@@ -1123,7 +1123,7 @@ static void rrdeng_populate_mrg(struct rrdengine_instance *ctx)
1123 if(cpus < 1)
1124 cpus = 1;
1125
1126 - netdata_log_info("DBENGINE: populating retention to MRG from %zu journal files of tier %d, using a shared pool of %zd threads...", datafiles, ctx->config.tier, cpus);
1126 + netdata_log_info("DBENGINE: tier %d: populating retention to MRG from %zu journal files, using a shared pool of %zd threads...", ctx->config.tier, datafiles, cpus);
1127
1128 completion_init(&ctx->loading.load_mrg);
1129 rrdeng_enq_cmd(
@@ -1143,7 +1143,11 @@ void rrdeng_readiness_wait(struct rrdengine_instance *ctx) {
1143 if(__atomic_load_n(&ctx->atomic.first_time_s, __ATOMIC_RELAXED) == LONG_MAX)
1144 __atomic_store_n(&ctx->atomic.first_time_s, now_realtime_sec(), __ATOMIC_RELAXED);
1145
1146 - netdata_log_info("DBENGINE: tier %d is ready for data collection and queries", ctx->config.tier);
1146 + // Preserve the caller's errno while avoiding stale errno values in this informational readiness log.
1147 + int saved_errno = errno;
1148 + errno_clear();
1149 + netdata_log_info("DBENGINE: tier %d: ready for data collection and queries", ctx->config.tier);
1150 + errno = saved_errno;
1151 }
1152
1153 /*