From 68bbc105da27fed39bae78b6415f17d70488c5ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Fri, 9 Jul 2021 14:35:02 +0200 Subject: [PATCH] add sync --- setup.cfg | 2 +- tempsdb/series.pxd | 1 + tempsdb/series.pyx | 7 +++++++ tempsdb/varlen.pyx | 10 ++++++++++ tests/test_series.py | 1 + tests/test_varlen.py | 2 +- 6 files changed, 21 insertions(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 5534b3f..6666d1a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ # coding: utf-8 [metadata] name = tempsdb -version = 0.6.4a3 +version = 0.6.4a6 long-description = file: README.md long-description-content-type = text/markdown; charset=UTF-8 license_files = LICENSE diff --git a/tempsdb/series.pxd b/tempsdb/series.pxd index 539062a..3741146 100644 --- a/tempsdb/series.pxd +++ b/tempsdb/series.pxd @@ -32,6 +32,7 @@ cdef class TimeSeries: cdef void decref_chunk(self, unsigned long long name) cdef Chunk open_chunk(self, unsigned long long name, bint is_direct, bint is_gzip) cdef int sync_metadata(self) except -1 + cpdef int sync(self) except -1 cpdef int mark_synced_up_to(self, unsigned long long timestamp) except -1 cpdef int append(self, unsigned long long timestamp, bytes data) except -1 cpdef int append_padded(self, unsigned long long timestamp, bytes data) except -1 diff --git a/tempsdb/series.pyx b/tempsdb/series.pyx index c33cc2c..0d248e2 100644 --- a/tempsdb/series.pyx +++ b/tempsdb/series.pyx @@ -267,6 +267,13 @@ cdef class TimeSeries: pass return 0 + cpdef int sync(self) except -1: + """ + Make sure that all data written up to this point is persisted on disk. + """ + self.last_chunk.sync() + return 0 + cpdef int close(self) except -1: """ Close the series. diff --git a/tempsdb/varlen.pyx b/tempsdb/varlen.pyx index c1797f0..289e0b3 100644 --- a/tempsdb/varlen.pyx +++ b/tempsdb/varlen.pyx @@ -568,6 +568,16 @@ cdef class VarlenSeries: self.current_maximum_length = tot_length + cpdef int sync(self) except -1: + """ + Make sure that all data written up to this point is persisted on disk. + """ + self.root_series.sync() + cdef TimeSeries series + for series in self.series: + series.sync() + return 0 + cpdef int enable_mmap(self) except -1: """ Enable using mmap for these series diff --git a/tests/test_series.py b/tests/test_series.py index 28bf234..9390851 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -30,6 +30,7 @@ class TestSeries(unittest.TestCase): for i in range(0, 16000): series.append(i, b'\x00'*10) + series.sync() series.close() series = TimeSeries('test8', 'test8') series.trim(4000) diff --git a/tests/test_varlen.py b/tests/test_varlen.py index 3001ff0..100a73e 100644 --- a/tests/test_varlen.py +++ b/tests/test_varlen.py @@ -14,7 +14,7 @@ class TestVarlen(unittest.TestCase): varlen.append(*series[1]) self.assertEqual(len(os.listdir('test_dir')), 3) - + varlen.sync() it = varlen.iterate_range(0, 20) lst = [(ts, v.to_bytes()) for ts, v in it] it.close() -- GitLab