Skip to content

fix: implement WriteApi.flush() for batching mode - #714

Open
sankalpsthakur wants to merge 1 commit into
influxdata:masterfrom
sankalpsthakur:fix/write-api-flush-697
Open

fix: implement WriteApi.flush() for batching mode#714
sankalpsthakur wants to merge 1 commit into
influxdata:masterfrom
sankalpsthakur:fix/write-api-flush-697

Conversation

@sankalpsthakur

Copy link
Copy Markdown

Proposed Changes

WriteApi.flush() was documented as a stable API but implemented as a TODO / pass no-op (#697).

This implements flush() for batching mode by adding a flush boundary subject that forces the current batch window to close and send pending points over HTTP — the same approach used by the C# and Java client batch writers.

Behavior

  • Forces immediate write of any buffered data (does not wait for batch_size or flush_interval)
  • Does not dispose the write pipeline — WriteApi remains usable after flush() (unlike close())
  • No-op for synchronous / asynchronous write types

Implementation notes

  • Pipeline uses ops.publish + ops.window(rx.merge(time/count windows, flush_subject)), mirroring C# WriteApi / Java FlowableBufferTimedFlushable
  • Empty flushes do not send HTTP requests (existing batch.size > 0 filter)

Fixes #697

Checklist

  • CHANGELOG.md updated
  • Rebased/mergeable
  • A test has been added if appropriate
  • pytest tests/test_WriteApiBatching.py completes successfully (new flush tests + existing batching tests)
  • Commit messages are conventional
  • Sign CLA (if not already signed)

Tests

pytest tests/test_WriteApiBatching.py -v --timeout=60

New coverage:

  • test_flush_partial_batch — single point under batch_size is written on flush()
  • test_flush_allows_reuse — further writes work after flush()
  • test_flush_empty_is_noop — empty buffer does not HTTP
  • test_flush_synchronous_is_noop — sync mode does not raise

AI disclosure

AI assistance was used to locate the incomplete flush() stub, compare C#/Java batch-writer flush designs, draft the Rx boundary-window change, and write unit tests. The change was reviewed, kept scoped to the batching pipeline + tests + changelog, and verified with the batching unit tests above.

AI/LLM disclosure

  • AI coding tools (including Grok and/or Codex agent-assisted editing) were used to help draft or modify code and this PR description.
  • I reviewed the complete change, understand the reasoning, and ran the reported local tests before submitting.
  • This submission is original work of authorship under the project CLA / contributor terms; AI output was not pasted unreviewed.

WriteApi.flush() was documented as a stable API but was a TODO no-op.
Implement it by adding a flush boundary subject that forces the current
batch window to close, matching the C#/Java batch writer design.

- Flush sends pending points without waiting for batch_size/flush_interval
- WriteApi remains usable after flush (unlike close())
- No-op for synchronous/asynchronous write types
- Unit tests for partial batch, reuse, empty buffer, and sync mode

Fixes influxdata#697
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.43%. Comparing base (9ca599f) to head (1a8f07a).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #714      +/-   ##
==========================================
+ Coverage   90.38%   90.43%   +0.04%     
==========================================
  Files          40       40              
  Lines        3546     3554       +8     
==========================================
+ Hits         3205     3214       +9     
+ Misses        341      340       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bednar
bednar requested a review from karel-rehor August 3, 2026 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] WriteApi.flush() method is incomplete despite being documented in stable API

2 participants