Repository navigation
Description
Three follow-ups left over from the RESTORE work in #6096 / #6119 and #6120 / #6123. Filing them together since the first two share the same root cause: DatabaseInternal.restoreRecord deliberately does less than LocalDatabase.createRecordNoLock, and only the code says so.
1. RESTORE skips validate() and default values, so it can create a record that violates its type's constraints
createRecordNoLock calls setDefaultValues(record) and doc.validate() before writing. restoreRecord does neither, so:
RESTORE DOCUMENT MyType RID #1:0 SET someOptionalField = 'x'recreates the record even when MyType declares other properties MANDATORY or NOTNULL, and without applying any declared default values. The result is a persisted record the schema says cannot exist, produced by an ordinary successful statement.
This was a deliberate choice when restoreRecord was consolidated: RESTORE is emergency repair, and its most common form is a structure-only shell restore with no SET clause at all - gating that behind a mandatory-property check would make the operation unusable in exactly the situation it exists for (recovering a RID that other records still reference). The empty-shell case is not incidental; GraphEngine.restoreVertexAt restores a property-less vertex by design.
But the trade-off is currently invisible: nothing in the SQL reference says RESTORE bypasses constraint validation, and a caller reasonably assumes the schema holds for every write path.
Options, roughly in order of preference:
- Document it, and have the statement's result set report that validation was skipped (so the caller has something to act on rather than a silent success).
- Validate only when a
SET/CONTENTbody is supplied, leaving the empty-shell repair path unvalidated. Splits the difference, at the cost of a rule that is harder to explain. - Add an explicit opt-in/opt-out clause (
RESTORE ... VALIDATE).
Related: a restored record that violates MANDATORY will also fail a later CHECK DATABASE-style consistency pass, which is worth confirming before choosing.
2. RESTORE does not fire create events, so triggers never see the restored record
createRecordNoLock fires events.onBeforeCreate / onAfterCreate plus the per-type RecordEventsRegistry callbacks. restoreRecord fires none, so a restored record is invisible to every registered trigger, including application-level ones that maintain derived state.
This was also deliberate: running user-authored triggers - JS ones included - during an emergency repair is a much larger behavioural and security surface than recreating one record, and a repair that fires side effects is hard to reason about mid-incident.
I lean toward documenting the contract rather than changing the behaviour. Either way it should be stated in the SQL reference for RESTORE DOCUMENT/VERTEX/EDGE instead of living only in a code comment, since anything that rebuilds derived state from create events will silently drift after a restore.
The javadoc on DatabaseInternal.restoreRecord already lists both this and item 1 as the two intended departures from createRecordNoLock - the gap is user-facing documentation, not internal clarity.
3. Re-triage Issue5279ConcurrentUpdateTest.growingUpdatesUnderContentionKeepTheDatabaseConsistent
Currently treated as a chronic flake. During the #6096/#6120 work it failed on every local run - full-suite and in isolation, on clean main with all changes stashed as well as with them applied. That is consistent enough to warrant a second look rather than being written off as noise.
Failure shape is stable:
N thread(s) failed, first: com.arcadedb.exception.ConcurrentModificationException:
Concurrent modification on page PageId(Issue5279ConcurrentUpdateTest/1/0)
in file 'Growing_0.1.65536.v0.bucket' (current v.187 <> database v.188).
Please retry the operation
The thread count varies run to run (2-5 observed), the page and file do not. Given #5279's slot-merge machinery is meant to absorb exactly this false conflict for in-page growing updates, the test either found a real hole in growRecordInPage/slot-rebase or its retry budget is too tight for a fast multi-core machine. Both are worth knowing which.
Worth checking whether it also fails consistently in CI or only locally - if it is machine-speed dependent, that itself points at the retry budget rather than the merge logic.
Items 1 and 2 are contained to the RESTORE statement family and its docs. Item 3 is independent and can be picked up separately.
Activity
fix(#6127): run the restore preamble under the read lock, report an o…
fix(#6127): drop the redundant permission check, cover the database-l…
docs(#6127): flag the RESTORE EDGE afterCreate/adjacency interleaving
fix(#6127): cover the RESTORE EDGE arm, document the vertex event/adj…
docs(#6127): note why restoreRecord opens the implicit transaction be…
fix(#6127): RESTORE applies the type's schema and fires the create ev…
fix(engine): CHECK DATABASE finds the records that violate their own …