diff --git a/setup.cfg b/setup.cfg index 5534b3f905c00bb14027a9ea54e55777e6fb85ae..6666d1a558015e987196a483b1a7b3f82c2067f8 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 539062a6f2d6fe4d6d4d0cfe69c4e969fe1be3a5..3741146d37e32091670ea42d705d20f44be10850 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 c33cc2c7c49f80823baa27c6150fe492abfa8484..0d248e2589356706ece8dc423af431c5ad1c7243 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 c1797f024fbf113baf4322ef5579f5f62958243d..289e0b32540fff070f9d7226615053ee9151a094 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 28bf234f3a00d707bfc7a0a426bb7d2704e8d049..939085162e62786d07838f67739d159b72714670 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 3001ff01318c7762c2a5671e7532f24a43031fc6..100a73e863779580f0daf21066aa2f0b3f916139 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()