From dc400adc1f614ecffd0f761df980552b810dbe08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Tue, 8 Dec 2020 21:42:16 +0100 Subject: [PATCH] support more error conditions --- README.md | 2 +- setup.py | 2 +- tempsdb/chunks.pyx | 9 ++++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 58d7212..48789b7 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ You will need to have both snakehouse and satella installed. ## v0.4.4 -* _TBA_ +* more error conditions during mmap will be supported as well ## v0.4.3 diff --git a/setup.py b/setup.py index 597764b..848e2c2 100644 --- a/setup.py +++ b/setup.py @@ -25,7 +25,7 @@ if 'CI' in os.environ: setup(name='tempsdb', - version='0.4.4a1', + version='0.4.4a2', packages=['tempsdb'], install_requires=['satella>=2.14.21', 'ujson'], ext_modules=build([Multibuild('tempsdb', find_pyx('tempsdb')), ], diff --git a/tempsdb/chunks.pyx b/tempsdb/chunks.pyx index 417c756..f3e7db6 100644 --- a/tempsdb/chunks.pyx +++ b/tempsdb/chunks.pyx @@ -30,7 +30,7 @@ cdef class AlternativeMMap: def __init__(self, io_file: io.BinaryIO, file_lock_object): self.io = io_file - self.io.seek(0, 2) + self.io.seek(0, io.SEEK_END) self.size = self.io.tell() self.file_lock_object = file_lock_object @@ -117,7 +117,10 @@ cdef class Chunk: try: self.mmap = mmap.mmap(self.file.fileno(), 0) except OSError as e: - if e.errno == 12: # Cannot allocate memory + if e.errno in (11, # EAGAIN - memory is too low + 12, # ENOMEM - no memory space available + 19, # ENODEV - fs does not support mmapping + 75): # EOVERFLOW - too many pages would have been used self.file_lock_object = threading.Lock() self.mmap = AlternativeMMap(self.file, self.file_lock_object) else: @@ -210,7 +213,7 @@ cdef class Chunk: self.file_lock_object.acquire() try: self.file_size += self.page_size - self.file.seek(0, 2) + self.file.seek(0, io.SEEK_END) ba = bytearray(self.page_size) ba[self.page_size-FOOTER_SIZE:self.page_size] = STRUCT_L.pack(self.entries) self.file.write(ba) -- GitLab