Skip to content

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

Merged
karel-rehor merged 2 commits into
influxdata:masterfrom
sankalpsthakur:fix/write-api-flush-697
Aug 7, 2026
Merged

fix: implement WriteApi.flush() for batching mode#714
karel-rehor merged 2 commits into
influxdata:masterfrom
sankalpsthakur:fix/write-api-flush-697

Conversation

@sankalpsthakur

Copy link
Copy Markdown
Contributor

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

codecov-commenter commented Aug 1, 2026

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.46%. Comparing base (f54c45f) to head (da486fb).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #714      +/-   ##
==========================================
+ Coverage   90.41%   90.46%   +0.04%     
==========================================
  Files          40       40              
  Lines        3547     3555       +8     
==========================================
+ Hits         3207     3216       +9     
+ Misses        340      339       -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

@karel-rehor karel-rehor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sankalpsthakur

Thank you for this contribution.

Looks good to me. 🚴 🏁

@karel-rehor
karel-rehor merged commit 5e924ea into influxdata:master Aug 7, 2026
14 checks passed
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

3 participants