Skip to content

Commit 8d27d26

Browse files
committed
division by zero error
1 parent 2bcd505 commit 8d27d26

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

opteryx/__version__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# THIS FILE IS AUTOMATICALLY UPDATED DURING THE BUILD PROCESS
22
# DO NOT EDIT THIS FILE DIRECTLY
33

4-
__build__ = 1674
4+
__build__ = 1675
55
__author__ = "@joocer"
6-
__version__ = "0.26.0-beta.1674"
6+
__version__ = "0.26.0-beta.1675"
77

88
# Store the version here so:
99
# 1) we don't load dependencies by storing it in __init__.py

opteryx/compiled/structures/memory_pool.pyx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ cdef class MemoryPool:
110110
self._print_stats()
111111

112112
cdef void _print_stats(self):
113-
cdef int64_t total_free = 0
114-
cdef int64_t total_used = 0
115-
cdef int64_t fragmentation = 0
116-
cdef int64_t free_blocks = 0
113+
cdef int64_t total_free = 0
114+
cdef int64_t total_used = 0
115+
cdef double fragmentation = 0.0
116+
cdef int64_t free_blocks = 0
117117

118118
for i in range(self.segments.size()):
119119
if self.segments[i].is_free:
@@ -123,7 +123,12 @@ cdef class MemoryPool:
123123
total_used += self.segments[i].length
124124

125125
if total_free > 0 and free_blocks > 1:
126-
fragmentation = (free_blocks - 1) * 100 / (total_free / 1024) # Simplified fragmentation metric
126+
# Avoid integer division by zero when total_free < 1024.
127+
cdef double denom = total_free / 1024.0
128+
if denom > 0.0:
129+
fragmentation = (free_blocks - 1) * 100.0 / denom # Simplified fragmentation metric
130+
else:
131+
fragmentation = 0.0
127132

128133
print(f"Memory Pool ({self.name}) <"
129134
f"size={self.size}, used={total_used}, free={total_free}, "

opteryx/connectors/disk_connector.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,14 @@ def read_blob(
157157

158158
# On Linux advise the kernel that access will be sequential to improve readahead
159159
if IS_LINUX:
160-
try:
160+
# if anything goes wrong, ignore
161+
with contextlib.suppress(Exception):
161162
libc = ctypes.CDLL("libc.so.6")
162163
# MADV_SEQUENTIAL is 2 on Linux, but don't hardcode if available
163164
MADV_SEQUENTIAL = 2
164165
addr = ctypes.c_void_p(ctypes.addressof(ctypes.c_char.from_buffer(_map)))
165166
length = ctypes.c_size_t(size)
166167
libc.madvise(addr, length, MADV_SEQUENTIAL)
167-
except Exception:
168-
# best-effort: if anything goes wrong, ignore
169-
pass
170168

171169
# pass a memoryview of the mmap to decoders - this makes intent explicit
172170
# and lets decoders that can accept memoryviews avoid extra copies

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "opteryx"
3-
version = "0.26.0-beta.1674"
3+
version = "0.26.0-beta.1675"
44
description = "Query your data, where it lives"
55
requires-python = '>=3.11'
66
readme = {file = "README.md", content-type = "text/markdown"}

0 commit comments

Comments
 (0)