Periodic sync data on windows (#21175)
Stelios Fragkakis committed
Oct 20, 2025 at 20:24 UTC
feefb7481b60ed6a3585595ce34b551bf15b9cec
3 files changed
+40
src/database/engine/datafile.c
+16
@@ -1,6 +1,15 @@
1
// SPDX-License-Identifier: GPL-3.0-or-later
2
#include "rrdengine.h"
3
4
+#ifdef OS_WINDOWS
5
+void sync_uv_file_data(uv_file file)
6
+{
7
+ uv_fs_t req;
8
+ (void) uv_fs_fsync(NULL, &req, file, NULL);
9
+ uv_fs_req_cleanup(&req);
10
+}
11
+#endif
12
+
13
void datafile_list_insert(struct rrdengine_instance *ctx, struct rrdengine_datafile *datafile)
14
{
15
netdata_rwlock_wrlock(&ctx->datafiles.rwlock);
@@ -9,6 +18,13 @@ void datafile_list_insert(struct rrdengine_instance *ctx, struct rrdengine_dataf
18
fatal("DBENGINE: cannot insert datafile %u of tier %d into the datafiles list",
19
datafile->fileno, ctx->config.tier);
20
*Pvalue = datafile;
21
+
22
+#ifdef OS_WINDOWS
23
+ sync_uv_file_data(datafile->file);
24
+ sync_uv_file_data(datafile->journalfile->file);
25
+ datafile->writers.last_sync_time = now_realtime_sec();
26
+#endif
27
+
28
netdata_rwlock_wrunlock(&ctx->datafiles.rwlock);
29
}
30
src/database/engine/datafile.h
+7
@@ -69,6 +69,9 @@ struct rrdengine_datafile {
69
SPINLOCK spinlock;
70
size_t running;
71
size_t flushed_to_open_running;
72
+#ifdef OS_WINDOWS
73
+ time_t last_sync_time;
74
+#endif
75
} writers;
76
77
struct {
@@ -115,4 +118,8 @@ static struct rrdengine_instance *datafile_ctx(struct rrdengine_datafile *datafi
118
return datafile->ctx;
119
}
120
121
+#ifdef OS_WINDOWS
122
+void sync_uv_file_data(uv_file file);
123
+#endif
124
+
125
#endif /* NETDATA_DATAFILE_H */
\ No newline at end of file
src/database/engine/rrdengine.c
+17
@@ -726,8 +726,19 @@ extent_flush_to_open(struct rrdengine_instance *ctx, struct extent_io_descriptor
726
727
static bool datafile_is_full(struct rrdengine_instance *ctx, struct rrdengine_datafile *datafile) {
728
bool ret = false;
729
+
730
spinlock_lock(&datafile->writers.spinlock);
731
732
+#ifdef OS_WINDOWS
733
+ time_t now = now_realtime_sec();
734
+ if (now - datafile->writers.last_sync_time > 60) {
735
+ nd_log_daemon(NDLP_INFO, "DBENGINE: datafile %d, last sync time: %ld, now: %ld", datafile->fileno, datafile->writers.last_sync_time, now);
736
+ sync_uv_file_data(datafile->file);
737
+ sync_uv_file_data(datafile->journalfile->file);
738
+ datafile->writers.last_sync_time = now_realtime_sec();
739
+ }
740
+#endif
741
+
742
if(datafile->pos > rrdeng_target_data_file_size(ctx))
743
ret = true;
744
@@ -862,6 +873,12 @@ static struct rrdengine_datafile *get_datafile_to_write_extent(struct rrdengine_
873
// release the writers on the old datafile
874
spinlock_lock(&old_datafile->writers.spinlock);
875
old_datafile->writers.running--;
876
+#ifdef OS_WINDOWS
877
+ sync_uv_file_data(old_datafile->file);
878
+ sync_uv_file_data(old_datafile->journalfile->file);
879
+ datafile->writers.last_sync_time = now_realtime_sec();
880
+ old_datafile->writers.last_sync_time = now_realtime_sec();
881
+#endif
882
spinlock_unlock(&old_datafile->writers.spinlock);
883
}
884