Repository navigation
DEV-1347: Fix TDB1 query failures when a writer promotes the same block - #7
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
razvan-danit-tq
force-pushed
the
DEV-1230-bptree
branch
from
September 23, 2026 13:01
3119e8e to
c7dd5c4
Compare
cygri
reviewed
Sep 23, 2026
cygri
left a comment
There was a problem hiding this comment.
The commit message states that there is a race between two readers. Claude tells me this is wrong and a reader race cannot happen; it is a race between a reader and a writer. It proposes this commit message instead:
TDB1: decode B+tree nodes without mutating the shared block buffer
formatBPTreeNode decoded a node with relative position(), limit(), slice() and
rewind() calls on block.getByteBuffer(). That returns the block's single buffer
instance, and the same Block is shared across transactions: after a writer
commits while readers are active, later transactions are stacked on its
BlockMgrJournal, whose getRead hands out its writeBlocks entries directly
(BlockMgrCache.getRead shares cached blocks the same way in direct file mode).
When the next writer takes such a block for writing, BlockMgrJournal._promote
copies it via Block.replicate, which moves the shared buffer's position and
limit without holding the block monitor. A reader decoding the same block at
that moment slices the wrong byte range and reads a garbage child pointer. It
surfaces as BlockException: BlockAccessBase: Bounds exception on node2id.dat,
from find() in a read transaction with no journal replay involved.
Use absolute slice(index, length) instead, so decoding neither reads nor
changes the shared buffer's position.
Reported in DEV-1230; the fix is the one sketched there.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
A similar inaccuracy is in the PR description.
razvan-danit-tq
force-pushed
the
DEV-1230-bptree
branch
from
September 23, 2026 13:45
c7dd5c4 to
6f4909d
Compare
formatBPTreeNode decoded a node with relative position(), limit(), slice() and rewind() calls on block.getByteBuffer(). That returns the block's single buffer instance, and the same Block is shared across transactions: after a writer commits while readers are active, later transactions are stacked on its BlockMgrJournal, whose getRead hands out its writeBlocks entries directly (BlockMgrCache.getRead shares cached blocks the same way in direct file mode). When the next writer takes such a block for writing, BlockMgrJournal._promote copies it via Block.replicate, which moves the shared buffer's position and limit without holding the block monitor. A reader decoding the same block at that moment slices the wrong byte range and reads a garbage child pointer. It surfaces as BlockException: BlockAccessBase: Bounds exception on node2id.dat, from find() in a read transaction with no journal replay involved. Use absolute slice(index, length) instead, so decoding neither reads nor changes the shared buffer's position. Reported in DEV-1230 and split out as DEV-1347; the fix is the one sketched there. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
razvan-danit-tq
force-pushed
the
DEV-1230-bptree
branch
from
September 23, 2026 15:08
6f4909d to
ca266c3
Compare
cygri
approved these changes
Sep 23, 2026
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.
Internal patched build of Apache Jena, published as
6.2.0-tq-2. Cumulative on top of6.2.0-tq-1: it carries the journal write-back fix from #5 as well as this one.BPTreeNodeMgr.formatBPTreeNodedecoded a node with relativeposition(),limit(),slice()andrewind()calls onblock.getByteBuffer(). That returns the block's single buffer instance, and the sameBlockis shared across transactions: after a writer commits while readers are active, later transactions are stacked on itsBlockMgrJournal, whosegetReadhands out itswriteBlocksentries directly (BlockMgrCache.getReadshares cached blocks the same way in direct file mode).When the next writer takes such a block for writing,
BlockMgrJournal._promotecopies it viaBlock.replicate, which moves the shared buffer's position and limit without holding the block monitor. A reader decoding the same block at that moment slices the wrong byte range and reads a garbage child pointer. It surfaces asBlockException: BlockAccessBase: Bounds exceptiononnode2id.dat, fromfind()in a read transaction with no journal replay involved.The fix uses absolute
slice(index, length), so decoding neither reads nor changes the shared buffer's position. Six lines in, twelve out, and no lock.Tracked as DEV-1347. This is the second race described in DEV-1230, the one the write-back patch does not address; it has its own ticket because it is a separate Jena bug with its own symptoms. The approach is the one sketched in DEV-1230.
Validation
6.2.0-tq-1failed 2 of 10, bothBlockExceptiononnode2id.datwith no data loss;6.2.0-tq-2failed 0 of 10.Not urgent. Master is on
6.2.0-tq-1and that build is being observed. This is ready whenever it is wanted;tq-1remains published and tagged, so moving between them is a one-line change tover.jena.(Supersedes #6, which was merged prematurely by mistake and has been undone —
base-jena-6.2.0is back at thetq-1state.)🤖 Generated with Claude Code