Skip to content

support replication - #43

Merged
codeboost merged 5 commits into
masterfrom
replication
Nov 2, 2026
Merged

codeboost merged 5 commits into
masterfrom
replication

Conversation

@xeubie

@xeubie xeubie commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

This adds support for replication of xitdb files via io/copy.

xeubie and others added 4 commits October 24, 2026 21:00
replica-state returns a zero state for a truncated or invalid replica, which replicationStart already treats as “send everything”.
codeboost added a commit that referenced this pull request Nov 2, 2026
An existing file now opens in the mode its header records: clj1 in Clojure
mode, any other header in compat mode, so files written by other languages
open without passing :mode. New files are still created as clj1 unless
{:mode :compat} is given. An explicit :mode is still checked against the
header of an existing file, for code that relies on one mode.

Add db-mode, which returns :clojure or :compat for an open database.

Old unversioned xitdb-clj files have header ID 0 like Java files and would
now open in compat mode. They are only rejected once xitdb-java's new file
format lands in #43, so this must be merged after it. Until then the legacy
fixture tests pass {:mode :clojure} explicitly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codeboost
codeboost force-pushed the replication branch 2 times, most recently from f915849 to a3f0c4c Compare November 2, 2026 16:54
xitdb-java 0.46.0 changed the file format, so files written by xitdb-clj
0.5.0 and earlier no longer open. open-database turns the engine's
InvalidVersionException into an IllegalArgumentException that says how to
migrate, the README upgrade note covers the change, and the version is
bumped to 0.6.0. A current-format file with another key hasher, whether
its digest has another ID or another size, is refused the same way, and
both cases are covered by tests since the legacy fixture stops at the
version check.

Replication lives in its own namespace, xitdb.replication, which extends
databases to clojure.java.io when loaded and keeps xitdb.db lean; its only
hook into xitdb.db is the now public lock-file. It gains two small
primitives so apps can harden it themselves. replicate! applies an update
stream and, unlike with-open around both streams, throws the read error
when a connection drops, with the failed commit attached as suppressed; it
returns whether the update was a full copy along with the replica state,
read while the write lock is still held. can-extend? tells a source
beforehand whether a replica's next update extends it or replaces it.

A full copy is applied in place, as the engine does it, and the README
states the limitations: reads throw while it runs, values read before it
must not be used afterwards, an interrupted copy leaves the replica
unreadable until the next sync (replica-state describes it as empty so that
sync is a full copy again), and only xitdb-clj databases should be
replicated into each other. An incremental sync that ends early is
truncated back to the replica's committed size, so leftover buffered bytes
can't be flushed over data another handle commits later. Nothing is
discarded for an update the engine refused, which never wrote anything, or
once the engine has begun committing, since its header may already point
at the new bytes.

compact no longer calls rootCursor to refresh the source's header, since
rootCursor doesn't reread it in current xitdb-java; the test is renamed to
what it still checks.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@codeboost
codeboost merged commit 806121f into master Nov 2, 2026
1 check passed
@xeubie
xeubie deleted the replication branch November 2, 2026 18:49
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.

2 participants