Skip to content

Add Python bindings for native CDC - #13925

Merged
tclinkenbeard-oai merged 5 commits into
apple:mainfrom
tclinkenbeard-oai:dev/tclinkenbeard/python-native-cdc-bindings
Sep 18, 2026
Merged

tclinkenbeard-oai merged 5 commits into
apple:mainfrom
tclinkenbeard-oai:dev/tclinkenbeard/python-native-cdc-bindings

Conversation

@tclinkenbeard-oai

@tclinkenbeard-oai tclinkenbeard-oai commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Expose native CDC stream registration, listing, removal, consumer creation and resumption through the Python database API.
  • Support multi-range streams with register_cdc_stream(name, ranges=[(begin, end), ...]), while retaining the single-range register_cdc_stream(name, begin, end) form. Listed streams expose their canonical union as immutable, Python-owned CdcKeyRange records.
  • Add future-based consumption and explicit acknowledgement, immutable mutation/cursor records, and owned consumer handles with deterministic cleanup.
  • Load CDC symbols only on first use so ordinary database operations still work with client libraries that do not expose CDC.
  • Document retention, replay, and checkpoint/acknowledgement recovery semantics without changing the native protocol or server behavior.

Validation

  • python_native_cdc_tests: passed all 8 tests, including canonical range unions, binary result ownership, gap filtering, clipped clears, acknowledgement/resume, and single-range compatibility.
  • python_native_cdc_legacy_api_tests: passed with API version 740.
  • Existing python_unit_tests: passed.
  • Black 22.8.0 and Flake8 5.0.4: passed.
  • Sphinx dummy build with warnings treated as errors: passed.

Compatibility

CDC requires API version 800 or later, the multi-range native CDC implementation, and cluster admission for new streams. Earlier experimental single-range CDC binaries have an incompatible ABI; drain and remove their streams and finish retired cleanup before upgrading all CDC-capable clients and servers.

Closing a consumer neither acknowledges mutations nor removes its stream. All registered ranges share one cursor and acknowledgement frontier. Results own their bytes independently of native futures, and unknown raw mutation codes remain available to callers. Single-range stream metadata retains begin_key and end_key properties; multi-range callers use ranges.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@tclinkenbeard-oai tclinkenbeard-oai left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Generated by Codex.

Reviewed head: ee1fa01.

What is it trying to do?

Expose native CDC through Python: stream management, resumable consumers, asynchronous consumption and explicit acknowledgement, with owned result records and documented checkpoint/replay semantics.

Is it correct?

Yes, based on source inspection. The ctypes layouts and signatures match the C API, returned bytes are copied, repeated consumer-future retrieval preserves one Python owner, and native references protect outstanding operations after handle closure. API-version checks and lazy symbol resolution preserve ordinary non-CDC use.

The corrected restart example now waits for a fresh read version to cover the saved checkpoint before re-acknowledging. It bounds that wait, handles database locks, and does not indiscriminately retry invalid-operation errors.

Are there bugs?

I did not find any correctness bugs in this round. The previously identified restart failure is addressed in the published revision.

Are there omissions?

None that block this change. The principal remaining coverage gap is concurrent future retrieval, cancellation, and closing a consumer with an operation in flight. The ownership paths look sound, but the new tests do not directly exercise those races.

Are there better ways of doing things?

One small, nonblocking test improvement: assert that the consumer is closed immediately after the with block, before calling assert_closed(). That helper explicitly closes the consumer itself, so the current test would pass with a broken __exit__.

No broader restructuring looks necessary.

Should this CL be LGTMd?

Yes, LGTM, based on inspection of the binding ABI, ownership and error paths, checkpoint recovery, compatibility handling, and test integration. Concurrent lifecycle behavior remains the highest residual runtime risk.

At review time, clang-format, clang-tidy, and Windows Boost checks pass; platform builds and cluster tests remain pending. No current-head failure is visible. PR checks.

No builds, tests, simulations, or other validation were run in this review round.

@tclinkenbeard-oai
tclinkenbeard-oai marked this pull request as ready for review August 21, 2026 07:29
@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@mengxu-oai

Copy link
Copy Markdown
Contributor

@tclinkenbeard-oai I asked codex to review all the related PRs together and found this issue

P1 when integrating with #13971 — ctypes still declares and calls the old ABI.

The registration call passes seven arguments, and CdcStreamInfoStruct embeds a single key range. #13971's C registration function takes a range-array pointer/count, and its stream-info record uses a pointer/count instead of that embedded range.

These are the same exported symbol names. API 800 and successful symbol lookup do not identify which layout is loaded. On a combined build, registration can reinterpret key bytes as structs; listing can interpret other fields as pointers or lengths. This can produce invalid memory access, not just a missing Python feature.

Update signatures, argument construction, immutable stream-info records, copying, examples, and C-backed tests to the final multi-range API. Do not release these two heads together unchanged.

@mengxu-oai mengxu-oai 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.

lgtm. the comment is known to Trevor. He needs one of the PRs to be merged so that he can resolve the issue.

@tclinkenbeard-oai tclinkenbeard-oai added the CDC Relates to the FDB native CDC feature label Sep 6, 2026
@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-macos-m1 on macOS 14.x

  • Commit ID: 59268af
  • Duration 0:32:07
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-clang-ide on Linux RHEL 9

  • Commit ID: 59268af
  • Duration 0:43:16
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-clang-arm on Linux RHEL 9

  • Commit ID: 59268af
  • Duration 0:50:27
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr on Linux RHEL 9

  • Commit ID: 59268af
  • Duration 1:10:32
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-clang on Linux RHEL 9

  • Commit ID: 59268af
  • Duration 1:29:24
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-cluster-tests on Linux RHEL 9

  • Commit ID: 59268af
  • Duration 1:42:08
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)
  • Cluster Test Logs zip file of the test logs (available for 30 days)

@tclinkenbeard-oai
tclinkenbeard-oai merged commit 7d3fa1e into apple:main Sep 18, 2026
9 of 10 checks passed
@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-macos on macOS 14.x

  • Commit ID: 59268af
  • Duration 0:47:36
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CDC Relates to the FDB native CDC feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants