From 40872e61869f2c39d819dbe465132b327b626ee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Tue, 1 Dec 2020 17:20:44 +0100 Subject: [PATCH] add series.name --- README.md | 1 + setup.py | 2 +- tempsdb/database.pyx | 4 ++-- tempsdb/series.pxd | 5 +++-- tempsdb/series.pyx | 11 ++++++++--- tests/test_db.py | 6 ++---- 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 44902c9..2767752 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ So no variable encoding for you! * added `get_all_series` * added `get_first_entry_for` * added `close_all_open_series` +* added `TimeSeries.name` ## v0.1 diff --git a/setup.py b/setup.py index f0afab2..b1d66c2 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ def find_pyx(*path) -> tp.List[str]: # setup(name='tempsdb', - version='0.2_a5', + version='0.2_a6', packages=['tempsdb'], install_requires=['satella>=2.14.21', 'ujson'], ext_modules=build([Multibuild('tempsdb', find_pyx('tempsdb')), ], diff --git a/tempsdb/database.pyx b/tempsdb/database.pyx index e644cda..c7714b7 100644 --- a/tempsdb/database.pyx +++ b/tempsdb/database.pyx @@ -70,7 +70,7 @@ cdef class Database: return self.open_series[name] if not os.path.isdir(path): raise DoesNotExist('series %s does not exist' % (name, )) - self.open_series[name] = result = TimeSeries(path) + self.open_series[name] = result = TimeSeries(path, name) if self.mpm is not None: result.register_memory_pressure_manager(self.mpm) return result @@ -154,7 +154,7 @@ cdef class Database: raise ValueError('Invalid block size, pick larger page') if os.path.isdir(os.path.join(self.path, name)): raise AlreadyExists('Series already exists') - cdef TimeSeries series = create_series(os.path.join(self.name, name), + cdef TimeSeries series = create_series(os.path.join(self.name, name), name, block_size, entries_per_chunk, page_size=page_size) self.open_series[name] = series diff --git a/tempsdb/series.pxd b/tempsdb/series.pxd index 24a6ac3..e4f9b8f 100644 --- a/tempsdb/series.pxd +++ b/tempsdb/series.pxd @@ -8,6 +8,7 @@ cdef class TimeSeries: object lock # lock to hold while writing object open_lock # lock to hold while opening or closing chunks readonly str path + readonly str name unsigned int max_entries_per_chunk readonly unsigned long long last_entry_synced readonly unsigned int block_size @@ -38,5 +39,5 @@ cdef class TimeSeries: cdef inline int get_references_for(self, unsigned long long timestamp): return self.refs_chunks.get(timestamp, 0) -cpdef TimeSeries create_series(str path, unsigned int block_size, - int max_entries_per_chunk, int page_size=*) +cpdef TimeSeries create_series(str path, str name, unsigned int block_size, + int max_entries_per_chunk, int page_size=4096): diff --git a/tempsdb/series.pyx b/tempsdb/series.pyx index 038cb1a..326d318 100644 --- a/tempsdb/series.pyx +++ b/tempsdb/series.pyx @@ -21,9 +21,14 @@ cdef class TimeSeries: :ivar last_entry_synced: timestamp of the last synchronized entry (int) :ivar block_size: size of the writable block of data (int) :ivar path: path to the directory containing the series (str) + + .. versionadded:: 0.2 + + :ivar name: name of the series (str) """ - def __init__(self, path: str): + def __init__(self, path: str, name: str): self.mpm = None + self.name = name self.lock = threading.RLock() self.open_lock = threading.RLock() self.refs_chunks = {} @@ -356,7 +361,7 @@ cdef class TimeSeries: shutil.rmtree(self.path) -cpdef TimeSeries create_series(str path, unsigned int block_size, +cpdef TimeSeries create_series(str path, str name, unsigned int block_size, int max_entries_per_chunk, int page_size=4096): if os.path.exists(path): raise AlreadyExists('This series already exists!') @@ -370,4 +375,4 @@ cpdef TimeSeries create_series(str path, unsigned int block_size, 'page_size': page_size }, f_out ) - return TimeSeries(path) + return TimeSeries(path, name) diff --git a/tests/test_db.py b/tests/test_db.py index 58b3529..d669e74 100644 --- a/tests/test_db.py +++ b/tests/test_db.py @@ -1,12 +1,11 @@ import os -import sys import unittest class TestDB(unittest.TestCase): def test_write_series(self): from tempsdb.series import create_series - series = create_series('test3', 10, 4096) + series = create_series('test3', 'test3', 10, 4096) for i in range(8000): series.append(i, b'\x00'*10) series.trim(4100) @@ -17,7 +16,7 @@ class TestDB(unittest.TestCase): def test_create_series(self): from tempsdb.series import create_series - series = create_series('test', 1, 10) + series = create_series('test', 'test', 1, 10) start, ts = 127, 100 for i in range(20): series.append(ts, bytes(bytearray([start]))) @@ -32,7 +31,6 @@ class TestDB(unittest.TestCase): self.do_verify_series(series, 0, 1200) self.do_verify_series(series, 0, 1800) series.close() - print(f'after close') def do_verify_series(self, series, start, stop): it = series.iterate_range(start, stop) -- GitLab