Skip to content
Snippets Groups Projects
Commit 8c632b52 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

fix the docs

parent 115f26cd
No related branches found
No related tags found
No related merge requests found
How this does work?
===================
Data is stored in so called chunks. A chunk's last page can be actively appended to, or a chunk
is immutable.
When there is a request to fetch some data, a chunk is loaded into memory. It will not
be automatically unloaded, to do this, you must periodically call
:meth:`~tempsdb.series.TimeSeries.close_chunks`.
Usage Usage
===== =====
...@@ -23,3 +33,4 @@ You retrieve their data via Iterators: ...@@ -23,3 +33,4 @@ You retrieve their data via Iterators:
Appending the data is done via :meth:`~tempsdb.series.TimeSeries.append`. Since time series are Appending the data is done via :meth:`~tempsdb.series.TimeSeries.append`. Since time series are
allocated in entire pages, so your files will be padded to a page in size. This makes writes allocated in entire pages, so your files will be padded to a page in size. This makes writes
quite fast, as in 99.9% cases it is just a memory operation. quite fast, as in 99.9% cases it is just a memory operation.
...@@ -3,12 +3,12 @@ from .series cimport TimeSeries ...@@ -3,12 +3,12 @@ from .series cimport TimeSeries
cdef class Database: cdef class Database:
cdef: cdef:
str path readonly str path
bint closed bint closed
object lock object lock
object mpm object mpm
cpdef void close(self) cpdef int close(self) except -1
cpdef TimeSeries get_series(self, str name) cpdef TimeSeries get_series(self, str name)
cpdef void register_memory_pressure_manager(self, object mpm) cpdef void register_memory_pressure_manager(self, object mpm)
cpdef TimeSeries create_series(self, str name, int block_size, cpdef TimeSeries create_series(self, str name, int block_size,
......
...@@ -10,6 +10,8 @@ cdef class Database: ...@@ -10,6 +10,8 @@ cdef class Database:
A basic TempsDB object. A basic TempsDB object.
:param path: path to the directory with the database :param path: path to the directory with the database
:ivar path: path to the directory with the database (str)
""" """
def __init__(self, path: str): def __init__(self, path: str):
self.path = path self.path = path
...@@ -65,6 +67,7 @@ cdef class Database: ...@@ -65,6 +67,7 @@ cdef class Database:
:type page_size: int :type page_size: int
:return: new series :return: new series
:rtype: TimeSeries :rtype: TimeSeries
:raises AlreadyExists: series with given name already exists
""" """
if os.path.isdir(os.path.join(self.path, name)): if os.path.isdir(os.path.join(self.path, name)):
raise AlreadyExists('Series already exists') raise AlreadyExists('Series already exists')
...@@ -86,12 +89,13 @@ cdef class Database: ...@@ -86,12 +89,13 @@ cdef class Database:
self.mpm = mpm self.mpm = mpm
cdef TimeSeries series cdef TimeSeries series
for series in self.open_series.values(): for series in self.open_series.values():
series.register_memory_pressure_manager(mpm) if not series.closed:
series.register_memory_pressure_manager(mpm)
def __del__(self): def __del__(self):
self.close() self.close()
cpdef void close(self): cpdef int close(self) except -1:
""" """
Close this TempsDB database Close this TempsDB database
""" """
......
...@@ -282,7 +282,7 @@ cdef class TimeSeries: ...@@ -282,7 +282,7 @@ cdef class TimeSeries:
cpdef int close_chunks(self) except -1: cpdef int close_chunks(self) except -1:
""" """
Close all superficially opened chunks Close all superficially opened chunks.
""" """
if self.last_chunk is None: if self.last_chunk is None:
return 0 return 0
...@@ -295,12 +295,14 @@ cdef class TimeSeries: ...@@ -295,12 +295,14 @@ cdef class TimeSeries:
with self.open_lock: with self.open_lock:
for chunk_name in chunks: for chunk_name in chunks:
if chunk_name != last_chunk_name: if chunk_name == last_chunk_name:
continue continue
elif not self.refs_chunks[chunk_name]: elif not self.refs_chunks.get(chunk_name, 0):
self.open_chunks[chunk_name].close() self.open_chunks[chunk_name].close()
del self.open_chunks[chunk_name] try:
del self.refs_chunks[chunk_name] del self.refs_chunks[chunk_name]
except KeyError:
pass
return 0 return 0
cpdef int append(self, unsigned long long timestamp, bytes data) except -1: cpdef int append(self, unsigned long long timestamp, bytes data) except -1:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment