Repository navigation
Description
SEVERITY: MEDIUM
Summary
This is a latent guard gap, not a defect seen from a supported route: no shipped call path reaches
the affected arm with a deferred-existence scope visible, and the end state below came from a
synthetic harness. What is wrong today is that one of the two arms of a classifier cannot satisfy the
condition its own javadoc states, and the test the javadoc cites never exercises that arm.
DeferredExistenceChecks.retractJournaledWrites() gives a counted write back only when it was
classified property-less, and its javadoc states the condition that makes the classification sound:
the flag is reset by a save that reaches the page, never by the deferred update that is counted. The
classifier that produces it, LocalDatabase.countCompletedUpdate, is called from two arms. On one of
them the save has already reached the page by the time the flag is read, so the premise does not
hold: a real property write is classified property-less, the counted write is given back, and
TransactionContext.statementFailed no longer sees the write that should have refused the commit.
The comment states that guarantee as though both arms were covered, and the test it cites as the
thing that would fail without it never exercises the uncovered arm. The invariant is therefore
unenforced in both of the places that are supposed to enforce it, which is what makes the arm worth
fixing even while nothing reaches it.
The same javadoc cites a test name that does not exist in the repository.
Where (HEAD 21d2a0e)
- engine/src/main/java/com/arcadedb/database/DeferredExistenceChecks.java:426-431, the javadoc
asserting the flag "is reset by a save that reaches the page, never by the deferred update that is
counted". - engine/src/main/java/com/arcadedb/database/DeferredExistenceChecks.java:429, the cited test name
aPropertyWrittenWhileTheProvisionalRecordIsPendingStillRefusesTheCommit. The repository has no
such test. The nearest real one is
aPropertyWrittenWhileTheProvisionalRecordIsPendingIsTakenBack, at
engine/src/test/java/com/arcadedb/query/Issue10482StatementGuardGapsTest.java:286, and it asserts
the opposite outcome from the one the name in the comment promises: the write is taken back and
the commit succeeds, rather than the commit being refused. - engine/src/main/java/com/arcadedb/database/LocalDatabase.java:1872, the deferred arm, which counts
before the write reaches a page. - engine/src/main/java/com/arcadedb/database/LocalDatabase.java:1878-1879, the write-now arm, which
calls updateRecordNoLock and only then counts. - engine/src/main/java/com/arcadedb/database/LocalDatabase.java:1933-1938, countCompletedUpdate,
which derives the structural argument from document.arePropertiesAssigned() at the moment it is
called, with no record of which arm called it. - engine/src/main/java/com/arcadedb/engine/LocalBucket.java:4239 updateRecordInternal, whose
"if (!discardRecordAfter) setBuffer(buffer.getNotReusable())" sites at :4346, :4433, :4458 and
:4799 run on the caller's own instance. - engine/src/main/java/com/arcadedb/database/MutableDocument.java:141-147, setBuffer, which sets
propertiesAssigned to false. - engine/src/main/java/com/arcadedb/database/DeferredExistenceChecks.java:408, where structural ==
true leaves tally.content false, and :453-456, where a tally with content == false is given back.
Repro
Build, from the repository root, with the round's two maven flags and without -o (the root pom
carries a build extension that offline mode cannot resolve, and the settings file points at the
local repository, which offline mode also refuses):
./mvnw -q -s <settings> -Dmaven.repo.local=<repo> -pl engine -DskipTests \
-Dlicense.skip=true -Dspotless.check.skip=true -Drat.skip=true -Denforcer.skip=true test-compile
Step 1. The page write clears the flag on the caller's instance.
Instrumentation: a print either side of the updateRecordNoLock call on the write-now arm
(LocalDatabase:1878-1879), and a print in countCompletedUpdate (:1933) carrying the identity, the
flag, the computed structural value and which arm called. A probe test loads a saved document,
assigns a property, and drives it three ways. Recorded output, verbatim:
PROBE1 CONTROL arePropertiesAssigned before save() = true
PROBE countCompletedUpdate arm=DEFERRED(1872) rid=#1:0 arePropertiesAssigned=true structural=false scopeArmed=false
PROBE1 CONTROL arePropertiesAssigned after save() = true
PROBE1 TEST arePropertiesAssigned before writeNow = true
PROBE writeNow-arm rid=#1:0 arePropertiesAssigned BEFORE updateRecordNoLock=true AFTER=false discardRecordAfter=false
PROBE countCompletedUpdate arm=WRITE-NOW(1879) rid=#1:0 arePropertiesAssigned=false structural=true scopeArmed=false
PROBE1 TEST arePropertiesAssigned after writeNow = false
PROBE1 TEST2 arePropertiesAssigned before writeNow(disc)= true
PROBE writeNow-arm rid=#1:0 arePropertiesAssigned BEFORE updateRecordNoLock=true AFTER=true discardRecordAfter=true
PROBE countCompletedUpdate arm=WRITE-NOW(1879) rid=#1:0 arePropertiesAssigned=true structural=false scopeArmed=false
PROBE1 TEST2 arePropertiesAssigned after writeNow(disc)= true
The control on the deferred arm keeps the flag and classifies correctly (structural=false). The same
property write down the write-now arm reaches the classifier with the flag already cleared and is
classified structural=true. The third case records a detail the lead did not predict: with
discardRecordAfter true the setBuffer sites are skipped, the flag survives, and the classification is
correct again. The misclassification needs discardRecordAfter == false.
Step 2. The cited test never reaches the arm. Run the class the javadoc points at, with the same
instrumentation in place:
./mvnw -q -s <settings> -Dmaven.repo.local=<repo> -pl engine \
-Dlicense.skip=true -Dspotless.check.skip=true -Drat.skip=true -Denforcer.skip=true \
-Dtest=Issue10482StatementGuardGapsTest -DfailIfNoTests=false test
26 tests, 0 errors, 0 failures (engine/target/surefire-reports). The arm census over the captured
output, verbatim:
total PROBE lines: 30104
--- arm census:
30104 arm=DEFERRED(1872)
--- writeNow-arm lines:
0
--- scopeArmed=true distribution:
30065 arm=DEFERRED(1872) rid=X arePropertiesAssigned=false structural=true scopeArmed=true
5 arm=DEFERRED(1872) rid=X arePropertiesAssigned=true structural=false scopeArmed=true
Every one of the 30104 reaches is on the deferred arm. The five rows with structural=false are the
property writes the comment relies on to keep a commit refused, and they are all on the arm where the
premise does hold. Nothing in this class, including the test the comment cites, puts any load on the
arm at :1879.
Step 3. The end state, from a synthetic harness only. Harness: a test on the statement's own
thread registers an AfterRecordCreateListener which, on the creation of the provisional record, takes
a different pre-existing record, assigns a property to it, and writes it through
DatabaseInternal.updateRecordWithEventsNoLock (writeNow == true, discardRecordAfter == false). The
statement is an openCypher CREATE of a vertex whose MANDATORY property it never supplies, so the
scope's check deletes it and the statement fails. Further instrumentation prints the give-back in
retractJournaledWrites and the counters in statementFailed.
With the default savepoint budget the end state is safe: the savepoint's page undo log puts the
write-now page bytes back, and the property does not survive. To isolate the counter, which is the
fallback guard when the savepoint cannot take a statement back, both runs below set
TX_STATEMENT_SAVEPOINT_MAX_ENTRIES to 1, exactly as the shipped test
aStatementThatWritesPastTheLimitOfTheSavepointKeepsTheCommitRefused does.
Test case, the write-now arm. Recorded output, verbatim:
R28 TEST-NOSP listener: arePropertiesAssigned before writeNow = true
PROBE writeNow-arm rid=#1:1 arePropertiesAssigned BEFORE updateRecordNoLock=true AFTER=false discardRecordAfter=false
PROBE countCompletedUpdate arm=WRITE-NOW(1879) rid=#1:1 arePropertiesAssigned=false structural=true scopeArmed=true
PROBE retractJournaledWrites given=1 createdRecordStands=false lightEdgeConnected=false journal=2 completedBefore=3 writesAtOpen=2
PROBE statementFailed completedRecordWrites=2 writesBefore=2 savepoint=true hasChanges=true unrestorable=the statement changed more than 1 entries of the transaction
R28 TEST-NOSP statement failed = true listener fired = true
R28 TEST-NOSP commit refused = false
R28 TEST-NOSP after commit: T.note='x' rows = 1
R28 TEST-NOSP after commit: V rows = 0
Control, identical in every respect except that the listener saves the record the ordinary way, so
the write is counted on the deferred arm. Same statement, same listener, same savepoint budget, same
record. Recorded output, verbatim:
R28 CONTROL-SAME listener: arePropertiesAssigned before save = true
PROBE retractJournaledWrites given=0 createdRecordStands=false lightEdgeConnected=false journal=2 completedBefore=3 writesAtOpen=2
PROBE statementFailed completedRecordWrites=3 writesBefore=2 savepoint=true hasChanges=true unrestorable=the statement changed more than 1 entries of the transaction
R28 CONTROL-SAME statement failed = true listener fired = true
R28 CONTROL-SAME commit refused = true (TransactionException)
R28 CONTROL-SAME after commit: T.note='x' rows = 0
R28 CONTROL-SAME after commit: V rows = 0
The arm is the only variable. On the deferred arm the write is classified as content, given == 0, the
counter stays at 3 against a writesBefore of 2, the commit is refused and the property does not
survive. On the write-now arm the same write is classified property-less, given == 1, the counter
falls back to 2, statementFailed finds nothing to refuse, the commit succeeds, and the property
written by a statement that failed and had its own record deleted is on disk.
What the synthetic harness does that no shipped route does. It calls
updateRecordWithEventsNoLock from the statement's own thread. Nothing in the repository does that.
Census over the whole repository, every module, for the entry point that selects the arm:
- engine/src/main/java/com/arcadedb/database/async/DatabaseAsyncUpdateRecord.java:54 is the only
production caller. - server/src/main/java/com/arcadedb/server/ServerDatabase.java:482 and
ha-raft/src/main/java/com/arcadedb/server/ha/raft/RaftReplicatedDatabase.java:2034 are pass-through
overrides with no callers of their own. - Two tests call it, at
engine/src/test/java/com/arcadedb/query/sql/method/collection/SQLMethodTransformTest.java:325 (a
stub) and server/src/test/java/com/arcadedb/server/Issue8552ServerDatabaseDiscardRecordAfterTest.java:115.
The async task runs on a DatabaseAsyncExecutorImpl worker thread. The scope is keyed on
DatabaseContext, which is a plain ThreadLocal (DatabaseContext.java:36), not an inheritable one, and
DeferredExistenceChecks.scopeOf resolves it through contextOf, at DeferredExistenceChecks.java:813.
A worker thread therefore finds no scope and updateCounted returns at
DeferredExistenceChecks.java:333-335 without journaling, whatever the JVM-wide ARMED_SCOPES counter
says. The class javadoc states that thread-binding as a load-bearing assumption at
DeferredExistenceChecks.java:86-93.
Record tasks are also never caller-run: scheduleTask
(DatabaseAsyncExecutorImpl.java:2545) only offers to a worker queue and blocks or retries, so the
caller-runs rejection policy documented for runCommand at DatabaseAsyncExecutorImpl.java:1525-1531
does not apply to them. That was the one route that could have put the arm on a thread holding a
scope, and it does not carry record tasks.
Refutation attempted
- Is the savepoint a sufficient second guard, making the counter irrelevant? No, and this is why the
reproduction above lowers the savepoint budget rather than relying on the default. statementFailed
(TransactionContext.java:840-852) tries rollbackStatement first and only consults the counter when
the savepoint cannot take the statement back, which StatementSavepoint.java:52-57 lists reasons
for. With the default budget the savepoint's page undo log does cover the write-now page bytes, and
the first synthetic run confirmed that: commit allowed, T.note rows 0. The counter is the fallback,
and it is the fallback that misclassifies. - Is the write-now write journaled by the savepoint by some other means? No. The savepoint learns of
an update through TransactionContext.addUpdatedRecord, at :1674, which is the deferred arm only.
The write-now arm writes the page directly and never passes through it, so for that write the
counter is the only thing standing between a failed statement and a commit. - Is it harmless because discardRecordAfter is usually true? Partly, and it narrows the shape rather
than removing it. Measured in step 1: with discardRecordAfter true the setBuffer sites are skipped
and the classification is correct. DatabaseAsyncUpdateRecord.java:54 passes
onOkCallback == null, so the misclassifying shape is the one with a success callback. This is
worth stating in any fix, because it means the arm is correct for half its inputs by accident. - Is it dead code? No. updateCounted has one caller, countCompletedUpdate, with two call sites, and
both are live: the write-now arm runs on every asynchronous record update. What is absent is only
the coincidence of that arm with a visible scope. - Does the data come back next operation? No. The property is on disk after a commit the engine was
supposed to refuse, as the step 3 output shows.
Suggested fix (and then the guarantee)
Capture the flag before the write and pass it in, so both arms classify from the same observation.
In LocalDatabase.updateRecord, read arePropertiesAssigned() once at the top, before the if that
chooses the arm, and hand the captured boolean to countCompletedUpdate instead of letting it read the
record. The guarantee then becomes the one the comment already claims: the flag that decides the
classification is the one the caller's own set() left, and no page write can sit between the
assignment and the reading of it.
The alternative the lead proposed, making structural an explicit parameter of countCompletedUpdate so
each call site must state it, buys the same thing plus a compiler error for the next arm added. It is
the better of the two if a third call site is ever likely, and the weaker one if the two arms should
genuinely share one derivation.
Either way the comment at DeferredExistenceChecks.java:426-431 should stop asserting an ordering that
one of the two callers does not have, and the test name it cites should be corrected to
aPropertyWrittenWhileTheProvisionalRecordIsPendingIsTakenBack, whose actual assertion is that the
write is taken back and the commit succeeds. A regression test driving the write-now arm with a scope
armed would make the claim enforced rather than asserted, which is the gap step 2 measured.
Scope / confidence
Executed, not read: the engine module built and run under surefire at HEAD 21d2a0e, with prints
added to LocalDatabase.countCompletedUpdate and the write-now arm, to
DeferredExistenceChecks.retractJournaledWrites and to TransactionContext.statementFailed. The step 2
census is over one test class, Issue10482StatementGuardGapsTest, which is the class holding the test
the javadoc cites; the class passes unchanged with the instrumentation in place.
Read, not executed: the reachability argument of step 3. The census of updateRecordWithEventsNoLock
callers swept the whole repository, every module, not just engine. The thread-locality of
DatabaseContext and the absence of a caller-runs path for record tasks were read, not measured; a
measurement of those would mean arming a scope on one thread and observing a worker thread's
lookup find nothing, which is what the code says and which no run here contradicted.
Confidence: high on steps 1 and 2, which are measurements with a control beside each. High that no
shipped route reaches the arm today. The step 3 end state is real output from a harness that calls an
engine-internal method a supported route does not call, and it should be read as what would happen if
the arm were ever reached, not as a defect observed in normal use.
Dedup
Searched the full 1000-line title list, not a prefix. The only neighbouring issue is #10482
("Statement guard of #10413: a refused UPDATE of a record the transaction already updated is
committed, and a statement that took its records back still refuses the commit"), CLOSED, which is
the issue this code was written for and which the cited test belongs to. No hit for
propertiesAssigned, property-less, countCompletedUpdate, writeNow, updateRecordWithEventsNoLock,
retractJournaled, DeferredExistence or provisional.
Activity
fix(#11024, #11028, #11035): review - edge-list writes known positive…
fix(#11024, #11025, #11028, #11035): write-now update classification,…
lvca commentedon Nov 2, 2026
Fixed in #11172.
Confirmed: when a record was updated through the asynchronous (write-now) path while an openCypher statement still had a provisional record pending, a property change could be counted as a pure edge-list change. If that statement then failed and could not be taken back by its savepoint, the transaction was allowed to commit the property anyway.
The engine now decides whether an update only touched edge lists before anything is written, and only when it is known for certain (an edge segment, or a vertex whose edge-list head changed with no property set). Anything else, including a list or map changed in place, keeps the commit refused. The javadoc now names a test that exists.
As the report says, no supported route reached this case: it needed engine-internal calls from a listener.
❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.
fix(#11024, #11025, #11028, #11035): write-now update classification,…