Skip to content

Commit b44de77

Browse files
committed
fix: fixed defaulting logic for https auto_flush_rows
1 parent f56ce04 commit b44de77

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

src/questdb/ingress.pyx

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,12 @@ cdef bint _is_tcp_protocol(line_sender_protocol protocol):
539539
(protocol == line_sender_protocol_tcps))
540540

541541

542+
cdef bint _is_http_protocol(line_sender_protocol protocol):
543+
return (
544+
(protocol == line_sender_protocol_http) or
545+
(protocol == line_sender_protocol_https))
546+
547+
542548
cdef class SenderTransaction:
543549
"""
544550
A transaction for a specific table.
@@ -1428,7 +1434,7 @@ cdef uint64_t _timedelta_to_millis(object timedelta):
14281434

14291435

14301436
cdef int64_t auto_flush_rows_default(line_sender_protocol protocol):
1431-
if protocol == line_sender_protocol_http:
1437+
if _is_http_protocol(protocol):
14321438
return 75000
14331439
else:
14341440
return 600
@@ -2203,6 +2209,46 @@ cdef class Sender:
22032209
"""Maximum length of a table or column name."""
22042210
return self._max_name_len
22052211

2212+
@property
2213+
def auto_flush(self) -> bint:
2214+
"""
2215+
Auto-flushing is enabled.
2216+
2217+
Consult the `.auto_flush_rows`, `.auto_flush_bytes` and
2218+
`.auto_flush_interval` properties for the current active thresholds.
2219+
"""
2220+
return self._auto_flush_mode.enabled
2221+
2222+
@property
2223+
def auto_flush_rows(self) -> Optional[int]:
2224+
"""
2225+
Row count threshold for the auto-flush logic, or None if disabled.
2226+
"""
2227+
if not self._auto_flush_mode.enabled:
2228+
return None
2229+
if self._auto_flush_mode.row_count == -1:
2230+
return None
2231+
return self._auto_flush_mode.row_count
2232+
2233+
@property
2234+
def auto_flush_bytes(self) -> Optional[int]:
2235+
"""
2236+
Byte-count threshold for the auto-flush logic, or None if disabled.
2237+
"""
2238+
if not self._auto_flush_mode.enabled:
2239+
return None
2240+
if self._auto_flush_mode.byte_count == -1:
2241+
return None
2242+
return self._auto_flush_mode.byte_count
2243+
2244+
@property
2245+
def auto_flush_interval(self) -> Optional[timedelta]:
2246+
if not self._auto_flush_mode.enabled:
2247+
return None
2248+
if self._auto_flush_mode.interval == -1:
2249+
return None
2250+
return timedelta(milliseconds=self._auto_flush_mode.interval)
2251+
22062252
def establish(self):
22072253
"""
22082254
Prepare the sender for use.

test/test.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,48 @@ def test_independent_buffer(self):
457457
# The buffer is now auto-cleared.
458458
self.assertEqual(str(buf), '')
459459

460+
def test_auto_flush_settings_defaults(self):
461+
for protocol in ('tcp', 'tcps', 'http', 'https'):
462+
sender = self.builder(protocol, 'localhost', 9009)
463+
self.assertTrue(sender.auto_flush)
464+
self.assertEqual(sender.auto_flush_bytes, None)
465+
self.assertEqual(
466+
sender.auto_flush_rows,
467+
75000 if protocol.startswith('http') else 600)
468+
self.assertEqual(sender.auto_flush_interval, datetime.timedelta(seconds=1))
469+
470+
def test_auto_flush_settings_off(self):
471+
for protocol in ('tcp', 'tcps', 'http', 'https'):
472+
sender = self.builder(protocol, 'localhost', 9009, auto_flush=False)
473+
self.assertFalse(sender.auto_flush)
474+
self.assertEqual(sender.auto_flush_bytes, None)
475+
self.assertEqual(sender.auto_flush_rows, None)
476+
self.assertEqual(sender.auto_flush_interval, None)
477+
478+
def test_auto_flush_settings_on(self):
479+
for protocol in ('tcp', 'tcps', 'http', 'https'):
480+
sender = self.builder(protocol, 'localhost', 9009, auto_flush=True)
481+
# Same as default.
482+
self.assertEqual(sender.auto_flush_bytes, None)
483+
self.assertEqual(
484+
sender.auto_flush_rows,
485+
75000 if protocol.startswith('http') else 600)
486+
self.assertEqual(sender.auto_flush_interval, datetime.timedelta(seconds=1))
487+
488+
def test_auto_flush_settings_specified(self):
489+
for protocol in ('tcp', 'tcps', 'http', 'https'):
490+
sender = self.builder(
491+
protocol,
492+
'localhost',
493+
9009,
494+
auto_flush_bytes=1024,
495+
auto_flush_rows=100,
496+
auto_flush_interval=datetime.timedelta(milliseconds=50))
497+
self.assertTrue(sender.auto_flush)
498+
self.assertEqual(sender.auto_flush_bytes, 1024)
499+
self.assertEqual(sender.auto_flush_rows, 100)
500+
self.assertEqual(sender.auto_flush_interval, datetime.timedelta(milliseconds=50))
501+
460502
def test_auto_flush(self):
461503
with Server() as server:
462504
with self.builder(

0 commit comments

Comments
 (0)