diff --git a/tempsdb/chunks.pxd b/tempsdb/chunks.pxd index 4a05a41d6fbdd2877c92468ae7e8cf94601d3618..34dece150b282e1b59764cfd85b3dfbedcaa912c 100644 --- a/tempsdb/chunks.pxd +++ b/tempsdb/chunks.pxd @@ -25,7 +25,7 @@ cdef class Chunk: cpdef object iterate_indices(self, unsigned long starting_entry, unsigned long stopping_entry) cpdef void close(self) - cpdef tuple get_piece_at(self, unsigned int index) + cdef tuple get_piece_at(self, unsigned int index) cpdef int append(self, unsigned long long timestamp, bytes data) except -1 cpdef int sync(self) except -1 cpdef unsigned int find_left(self, unsigned long long timestamp) diff --git a/tempsdb/chunks.pyx b/tempsdb/chunks.pyx index dbea93a3897b68953ee453ab119f86921c126759..13b5541154e9745c5bfd143c57ade9ac198b22f3 100644 --- a/tempsdb/chunks.pyx +++ b/tempsdb/chunks.pyx @@ -225,7 +225,7 @@ cdef class Chunk: def __del__(self): self.close() - cpdef tuple get_piece_at(self, unsigned int index): + cdef tuple get_piece_at(self, unsigned int index): """ Return a piece of data at a particular index, numbered from 0 diff --git a/tempsdb/series.pxd b/tempsdb/series.pxd index 153a3f4c738f9e68000c7bf0735f526fbe9afba0..0725547f5a7225c827338cea878006020fe21b15 100644 --- a/tempsdb/series.pxd +++ b/tempsdb/series.pxd @@ -32,6 +32,7 @@ cdef class TimeSeries: cpdef int close_chunks(self) except -1 cpdef Iterator iterate_range(self, unsigned long long start, unsigned long long stop) cpdef unsigned int get_index_of_chunk_for(self, unsigned long long timestamp) + cpdef int trim(self, unsigned long long timestamp) except -1 cpdef TimeSeries create_series(str path, unsigned int block_size, int max_entries_per_chunk, int page_size=*) diff --git a/tempsdb/series.pyx b/tempsdb/series.pyx index d1dbf1a2488a589085fcc9affc402d9da72a020c..5a19b4f16c58bd172834fad5fea291572c2c903e 100644 --- a/tempsdb/series.pyx +++ b/tempsdb/series.pyx @@ -111,6 +111,18 @@ cdef class TimeSeries: self.refs_chunks[name] += 1 return self.open_chunks[name] + cpdef int trim(self, unsigned long long timestamp) except -1: + """ + Delete all entries earlier than timestamp. + + Note that this will drop entire chunks, so it may be possible that some entries will linger + on. This will not delete opened chunks, but it will delete them on release. + + :param timestamp: timestamp to delete entries earlier than + :type timestamp: int + """ + # todo: write it + cpdef void close(self): """ Close the series. diff --git a/tests/test_db.py b/tests/test_db.py index d070e0e14481574c6d0d9ba743422be5029120ba..105fb27c9a80f98ad97692a12351b1bf48e889d3 100644 --- a/tests/test_db.py +++ b/tests/test_db.py @@ -35,9 +35,9 @@ class TestDB(unittest.TestCase): self.assertEqual(chunk.min_ts, 0) self.assertEqual(chunk.max_ts, 4) self.assertEqual(chunk.block_size, 4) - self.assertEqual(chunk.get_piece_at(0), (0, b'ala ')) - self.assertEqual(chunk.get_piece_at(1), (1, b'ma ')) - self.assertEqual(chunk.get_piece_at(2), (4, b'kota')) + self.assertEqual(chunk[0], (0, b'ala ')) + self.assertEqual(chunk[1], (1, b'ma ')) + self.assertEqual(chunk[2], (4, b'kota')) self.assertEqual(len(chunk), 3) self.assertEqual(list(iter(chunk)), data) chunk.append(5, b'test')