DBENGINE v2 - bug fixes (#14413)
* fix https://github.com/netdata/netdata/issues/14411 * take into account jv2 files to the total size of the db * take into account jv1 files when there are jv2 available
Costa Tsaousis committed
Feb 2, 2023 at 16:34 UTC
cf8881b91eae992f17fbe6cbd139952bbb34b0a1
2 files changed
+31
-15
database/engine/journalfile.c
+27
-14
@@ -1023,6 +1023,8 @@ int journalfile_v2_load(struct rrdengine_instance *ctx, struct rrdengine_journal
1023
// Initialize the journal file to be able to access the data
1024
journalfile_v2_data_set(journalfile, fd, data_start, journal_v2_file_size);
1025
1026
+ ctx_current_disk_space_increase(ctx, journal_v2_file_size);
1027
+
1028
// File is OK load it
1029
return 0;
1030
}
@@ -1378,7 +1380,7 @@ void journalfile_migrate_to_v2_callback(Word_t section, unsigned datafile_fileno
1380
error("DBENGINE: failed to resize file '%s'", path);
1381
}
1382
else
1381
- ctx_current_disk_space_increase(ctx, sizeof(struct journal_v2_header));
1383
+ ctx_current_disk_space_increase(ctx, resize_file_to);
1384
}
1385
1386
int journalfile_load(struct rrdengine_instance *ctx, struct rrdengine_journalfile *journalfile,
@@ -1389,36 +1391,48 @@ int journalfile_load(struct rrdengine_instance *ctx, struct rrdengine_journalfil
1391
int ret, fd, error;
1392
uint64_t file_size, max_id;
1393
char path[RRDENG_PATH_MAX];
1394
+ bool loaded_v2 = false;
1395
1393
- // Do not try to load the latest file
1394
- if (datafile->fileno != ctx_last_fileno_get(ctx)) {
1395
- if (likely(!journalfile_v2_load(ctx, journalfile, datafile)))
1396
- return 0;
1397
- }
1396
+ // Do not try to load jv2 of the latest file
1397
+ if (datafile->fileno != ctx_last_fileno_get(ctx))
1398
+ loaded_v2 = journalfile_v2_load(ctx, journalfile, datafile) == 0;
1399
1400
journalfile_v1_generate_path(datafile, path, sizeof(path));
1401
1402
fd = open_file_for_io(path, O_RDWR, &file, use_direct_io);
1403
if (fd < 0) {
1404
ctx_fs_error(ctx);
1405
+
1406
+ if(loaded_v2)
1407
+ return 0;
1408
+
1409
return fd;
1410
}
1411
1412
ret = check_file_properties(file, &file_size, sizeof(struct rrdeng_df_sb));
1408
- if (ret)
1409
- goto error;
1413
+ if (ret) {
1414
+ error = ret;
1415
+ goto cleanup;
1416
+ }
1417
+
1418
+ if(loaded_v2) {
1419
+ journalfile->unsafe.pos = file_size;
1420
+ error = 0;
1421
+ goto cleanup;
1422
+ }
1423
+
1424
file_size = ALIGN_BYTES_FLOOR(file_size);
1425
+ journalfile->unsafe.pos = file_size;
1426
+ journalfile->file = file;
1427
1428
ret = journalfile_check_superblock(file);
1429
if (ret) {
1430
info("DBENGINE: invalid journal file '%s' ; superblock check failed.", path);
1415
- goto error;
1431
+ error = ret;
1432
+ goto cleanup;
1433
}
1434
ctx_io_read_op_bytes(ctx, sizeof(struct rrdeng_jf_sb));
1435
1419
- journalfile->file = file;
1420
- journalfile->unsafe.pos = file_size;
1421
-
1436
info("DBENGINE: loading journal file '%s'", path);
1437
1438
max_id = journalfile_iterate_transactions(ctx, journalfile);
@@ -1441,8 +1455,7 @@ int journalfile_load(struct rrdengine_instance *ctx, struct rrdengine_journalfil
1455
1456
return 0;
1457
1444
-error:
1445
- error = ret;
1458
+cleanup:
1459
ret = uv_fs_close(NULL, &req, file, NULL);
1460
if (ret < 0) {
1461
error("DBENGINE: uv_fs_close(%s): %s", path, uv_strerror(ret));
database/engine/rrdengineapi.c
+4
-1
@@ -861,7 +861,10 @@ static bool rrdeng_load_page_next(struct storage_engine_query_handle *rrddim_han
861
else {
862
position = (handle->now_s - page_start_time_s) * (entries - 1) / (page_end_time_s - page_start_time_s);
863
time_t point_end_time_s = page_start_time_s + position * page_update_every_s;
864
- if(point_end_time_s < handle->now_s && position + 1 < entries) {
864
+ while(point_end_time_s < handle->now_s && position + 1 < entries) {
865
+ // https://github.com/netdata/netdata/issues/14411
866
+ // we really need a while() here, because the delta may be
867
+ // 2 points at higher tiers
868
position++;
869
point_end_time_s = page_start_time_s + position * page_update_every_s;
870
}