Repository navigation
Add compatibility mode for files shared with other languages - #44
Merged
Merged
Conversation
Collaborator
|
Big improvement suggestion: Automatically go into compat mode if the database isn't |
xitdb-clj hashes keys with a format tag and refuses files whose header
isn't clj1, so it can't look up keys in files written by the Java library.
`(xit-db path {:mode :compat})` opens those files. The mode is checked
against the header rather than picking the hashing, since a wrong choice
silently loses lookups and creates duplicate keys: clj1 files only open in
Clojure mode and every other file only opens in compat mode. New compat
files get the header ID sha1, which keeps them distinct from old unversioned
Clojure files.
In a non-clj1 file, string keys hash as raw UTF-8, as Java's put(String)
does. Writing any other key or set member throws, reading one finds nothing
and removing one does nothing. Native maps and sets are written plain so
Java's ReadHashMap and ReadHashSet can read them.
Clojure mode keeps its hashing and counted collections. Emptying a map or
set in place now keeps its kind, because the wrapper keeps expecting it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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, but the
file format check from xitdb-java 0.46.0 rejects them before their header
ID is read, so they never open in compat mode.
A full copy during replication brings the source's header, so the replica
takes the source's mode. Document this, and test it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
codeboost
force-pushed
the
compat-mode
branch
from
November 2, 2026 19:50
f5348aa to
2c633c0
Compare
map-contains-key? was the one read path still hashing through db-key-hash and catching its exception; it now uses db-lookup-hash like the other lookups, keeping the catch for key types no file can hold. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
xitdb-clj hashes keys with a format tag (header ID
clj1), so it can't look up keys in files written by the Java or TypeScript libraries, and they can't look up keys in its files.Compat mode hashes string keys as raw UTF-8, as Java's
put(String)does, so both sides can read and write the same file.Mode comes from the header. An existing file opens in the mode its header records:
clj1in Clojure mode, any other header in compat mode, so files from other languages open with no option.db-modereturns:clojureor:compatfor an open database. New files areclj1unless created with(xit-db path {:mode :compat}), which gives them the header IDsha1. An explicit:modefor an existing file is checked against its header, and a mismatch throws without modifying the file.Compat mode rules. Hash map keys and set members must be strings at every depth. Writing anything else throws and leaves the database unchanged, reading one finds nothing, and removing one does nothing. Native maps and sets are written plain, so Java's
ReadHashMapandReadHashSetcan read them. Clojure mode keeps its hashing and counted collections. Emptying a map or set in place now keeps its kind, because the wrapper keeps expecting it.Interaction with 0.6.0.
compactkeeps the header, so a compacted database stays in its mode. A full copy during replication brings the source's header, so the replica takes the source's mode, even if it was opened with:mode.The README documents all of this, including a table of how each kind of file opens with each
:mode.🤖 Generated with Claude Code