From d350725f6117b579d18b25bae2b93109fef66c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Mon, 14 Dec 2020 20:22:34 +0100 Subject: [PATCH] force closing var series --- tempsdb/database.pyx | 2 +- tempsdb/varlen.pxd | 2 +- tempsdb/varlen.pyx | 7 +++++-- tests/test_database.py | 1 - 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tempsdb/database.pyx b/tempsdb/database.pyx index d79343a..fd2e3f3 100644 --- a/tempsdb/database.pyx +++ b/tempsdb/database.pyx @@ -322,7 +322,7 @@ cdef class Database: series.close() # because already closed series won't close themselves self.open_series = {} for var_series in self.open_varlen_series.values(): - var_series.close() + var_series.close(True) self.open_varlen_series = {} self.closed = True return 0 diff --git a/tempsdb/varlen.pxd b/tempsdb/varlen.pxd index 1657ccc..76990ed 100644 --- a/tempsdb/varlen.pxd +++ b/tempsdb/varlen.pxd @@ -18,7 +18,7 @@ cdef class VarlenSeries: int gzip_level cpdef int mark_synced_up_to(self, unsigned long long timestamp) except -1 - cpdef int close(self) except -1 + cpdef int close(self, bint force=*) except -1 cpdef int delete(self) except -1 cpdef tuple get_current_value(self) cdef int get_length_for(self, int index) diff --git a/tempsdb/varlen.pyx b/tempsdb/varlen.pyx index 99d252c..36c9f1d 100644 --- a/tempsdb/varlen.pyx +++ b/tempsdb/varlen.pyx @@ -300,6 +300,7 @@ cdef class VarlenIterator: def __init__(self, parent: VarlenSeries, start: int, stop: int, direct_bytes: bool = False): self.parent = parent + self.parent.references += 1 self.start = start self.stop = stop self.direct_bytes = direct_bytes @@ -596,18 +597,20 @@ cdef class VarlenSeries: """ return self.length_profile[-1 if index >= len(self.length_profile) else index] - cpdef int close(self) except -1: + cpdef int close(self, bint force=False) except -1: """ Close this series. No-op if already closed. + :param force: set to True to ignore open references + :raises StillOpen: some references are being held """ if self.closed: return 0 - if self.references: + if self.references and not force: raise StillOpen('still some iterators around') self.closed = True diff --git a/tests/test_database.py b/tests/test_database.py index 24ab246..c46991e 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -31,7 +31,6 @@ class TestDatabase(unittest.TestCase): ser = self.db.get_varlen_series('hello-world') self.assertEqual(ser.get_current_value(), (20, b'\x00\x00\x00')) - self.assertEqual(ser.last_entry_ts, 20) ser.close() self.db.delete_varlen_series('hello-world') -- GitLab