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
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
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);
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
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();
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
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);
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
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) {
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
}
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);
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
}
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);
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))) {
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,
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