Repository navigation
fix(db): restore :max-tx of pipeline transactions - #13468
Merged
Merged
Conversation
The worker pipeline extends a transaction with 1 or 2 more d/with calls, each its own tx id, and the stored tail keeps their datoms as 1 entry. A restore replays the entry, whose datoms keep their own tx ids, and sets :max-tx to its first datom's tx, below the :max-tx the graph had. The next transaction then took a tx id that datoms of the graph already carried, and since the sync checksum is stored with the :max-tx it covers, every reopen after an edit that went through the pipeline recomputed the whole-graph checksum. Take the largest tx among the tail's datoms.
Contributor
|
The current unit-test job has failures already present in the exact master-parent CI run at
The focused storage-reopen regression and clj-kondo passed after the conflict-resolution merge. No changes were made to repair these preexisting failures. |
devin-ai-integration Bot
pushed a commit
that referenced
this pull request
Sep 30, 2026
Signed-off-by: Tienson Qin <[email protected]>
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Sep 30, 2026
logseq#13545, logseq#13546 and logseq#13547 replace the 9 open pull requests they bundle; logseq#13468, logseq#13437, logseq#13475 and logseq#13528 are in upstream master.
devin-ai-integration Bot
pushed a commit
that referenced
this pull request
Oct 1, 2026
The worker pipeline extends a transaction with 1 or 2 more d/with calls, each its own tx id, and the stored tail keeps their datoms as 1 entry. A restore replays the entry, whose datoms keep their own tx ids, and sets :max-tx to its first datom's tx, below the :max-tx the graph had. The next transaction then took a tx id that datoms of the graph already carried, and since the sync checksum is stored with the :max-tx it covers, every reopen after an edit that went through the pipeline recomputed the whole-graph checksum. Take the largest tx among the tail's datoms. Co-authored-by: Tienson Qin <[email protected]>
devin-ai-integration Bot
pushed a commit
that referenced
this pull request
Oct 1, 2026
Signed-off-by: Tienson Qin <[email protected]>
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Oct 1, 2026
logseq#13545, logseq#13546 and logseq#13547 replace the 9 open pull requests they bundle; logseq#13468, logseq#13437, logseq#13475 and logseq#13528 are in upstream master.
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Oct 4, 2026
logseq#13545, logseq#13546 and logseq#13547 replace the 9 open pull requests they bundle; logseq#13468, logseq#13437, logseq#13475 and logseq#13528 are in upstream master.
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Oct 8, 2026
logseq#13545, logseq#13546 and logseq#13547 replace the 9 open pull requests they bundle; logseq#13468, logseq#13437, logseq#13475 and logseq#13528 are in upstream master.
devin-ai-integration Bot
pushed a commit
that referenced
this pull request
Oct 8, 2026
The worker pipeline extends a transaction with 1 or 2 more d/with calls, each its own tx id, and the stored tail keeps their datoms as 1 entry. A restore replays the entry, whose datoms keep their own tx ids, and sets :max-tx to its first datom's tx, below the :max-tx the graph had. The next transaction then took a tx id that datoms of the graph already carried, and since the sync checksum is stored with the :max-tx it covers, every reopen after an edit that went through the pipeline recomputed the whole-graph checksum. Take the largest tx among the tail's datoms. Co-authored-by: Tienson Qin <[email protected]>
devin-ai-integration Bot
pushed a commit
that referenced
this pull request
Oct 8, 2026
Signed-off-by: Tienson Qin <[email protected]>
devin-ai-integration Bot
pushed a commit
that referenced
this pull request
Oct 8, 2026
The worker pipeline extends a transaction with 1 or 2 more d/with calls, each its own tx id, and the stored tail keeps their datoms as 1 entry. A restore replays the entry, whose datoms keep their own tx ids, and sets :max-tx to its first datom's tx, below the :max-tx the graph had. The next transaction then took a tx id that datoms of the graph already carried, and since the sync checksum is stored with the :max-tx it covers, every reopen after an edit that went through the pipeline recomputed the whole-graph checksum. Take the largest tx among the tail's datoms. Co-authored-by: Tienson Qin <[email protected]>
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Oct 11, 2026
logseq#13545, logseq#13546 and logseq#13547 replace the 9 open pull requests they bundle; logseq#13468, logseq#13437, logseq#13475 and logseq#13528 are in upstream master.
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Oct 13, 2026
logseq#13545, logseq#13546 and logseq#13547 replace the 9 open pull requests they bundle; logseq#13468, logseq#13437, logseq#13475 and logseq#13528 are in upstream master.
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Oct 16, 2026
logseq#13545, logseq#13546 and logseq#13547 replace the 9 open pull requests they bundle; logseq#13468, logseq#13437, logseq#13475 and logseq#13528 are in upstream master.
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.
What changes
Since #13415, opening a graph in the db worker recomputes the whole-graph sync checksum when the tx the stored checksum covers differs from the graph's
:max-tx(reconcile-local-checksum!,src/main/frontend/worker/sync.cljs). After a session whose last transaction went through the worker pipeline, the reopened graph's:max-txis below the one the graph had when it closed, so nearly every open after an edit recomputes. On a graph of 157,614 checksum-eligible entities (1.33 million:eavtdatoms, imported from a file graph), that recompute is most of the worker start: 5.56 s against 0.04 s in the release build.Why the
:max-txfalls short:ldb/transact!applies a transaction withd/with, and the worker'stransact-pipelineextends it with 1 or 2 mored/withcalls (derived tx data, then rebuilt refs and:block/tx-idstamps). Each call takes the next tx id.transact-syncstores the joined report withdc/store-after-transact!, which appends it to the stored tail as 1 entry.(:max-tx (:db-after tx-report)), the last of those ids.d/restore-connreplays each tail entry, then sets:max-txto the tx of the entry's first datom (db-with-tailin the datascript fork'sstorage.cljs), the first of those ids.A unit test on master, with 1 block edit through the pipeline and a reopen through
get-storage-conn, shows what the restore does with the other ids::block/tx-idstamp at 536870916.:max-txis 536870915.get-storage-conn(deps/db/src/logseq/db/common/sqlite.cljs) now sets:max-txto the largest tx among the replayed tail's datoms when that is larger. Every restore in Logseq goes through it: the worker's graph open, the sync download, the db-sync server's storage and the CLI.The reopened graph keeps its
:max-tx, its next transaction takes a new tx id, and the checksum stored after the last edit still covers it.Worker start on the imported graph, whose import session ended with a pipeline transaction (a new journal page: 7 tail datoms at tx 536873413, 3 at 536873414), from the worker's first log line to its ready line, 3 runs per build:
:max-txis 536873413, and the start recomputes the checksum and stores it as covering 536873413.:max-txis 536873414 and the stored checksum, covering 536873414, is kept. These builds also carried the recompute changes ofperf/checksum-one-walkand 1 change to the sqlite read path; this start runs no recompute, so they do not act on it. Master's own start with the recompute skipped (the stored covered tx set by hand to the:max-txmaster restores) took 0.04 s (0.03 - 0.04) release and 0.05 s (0.04 - 0.06) dev, 3 runs each.One case stays (read in code, not observed): when the last
d/withof a pipeline transaction writes no datom, no tail datom carries the final tx id, and the reopen after it still recomputes once.Where the root fix could go
The first-datom rule is right when 1 tail entry is 1 transaction, as with datascript's own
transact!; upstream datascript'sstorage.cljhas the same rule. Logseq stores severald/withcalls as 1 entry. The restore is the one place that sees every datom it replays, so the guarantee that:max-txis at least every tx on the restored datoms fits best in the fork'sdb-with-tail. A drafted change for logseq/datascript:With that fork change on the classpath and master's
get-storage-conn, the new test below passes (frontend.worker.db-sync-test234 tests, 2229 assertions, 0 failures). The change adds a case to the fork'sdatascript.test.storage, 1 tail entry spanning 2 tx ids; run inside Logseq's test build, that namespace has 3 tests and 59 assertions, with 0 failures with the change and 2 without it. That route needs a fork commit and the sha bump in the 5deps.ednfiles that pin the fork, after which the check inget-storage-connnever fires and can go. This PR keeps the Logseq-side change, since it covers every restore Logseq does and needs no dependency bump. I can send the fork change as a pull request to logseq/datascript if you prefer that route.Tests
reopened-graph-keeps-max-tx-of-pipeline-transaction-testinfrontend.worker.db-sync-test: builds a storage-backed graph, edits 1 block throughldb/transact!with the worker pipeline registered, and reopens it withget-storage-conn. It checks that the edit's tail entry spans 2 tx ids, that the replayed datoms keep their tx ids, that the reopened:max-txequals the one before, that no datom carries a tx above it, and thatreconcile-local-checksum!keeps the stored checksum. On master it fails 3 times::max-tx536870915 against 536870916, the stamp datom at 536870916 above it, and the stored checksum replaced by a recompute. With this change it passes.frontend.worker.db-sync-test234 tests, 2229 assertions;frontend.worker.sync.client-op-test6 tests, 22 assertions;logseq.db-sync.checksum-test(run fromdeps/db-sync) 28 tests, 78 assertions: 0 failures.TZ=Etc/GMT+12(2503 tests, 12504 assertions) and its time-zone-dependent namespaces atTZ=Pacific/Kiritimati(1470 tests, 9063 assertions): 0 failures, 0 errors.Allow edits from maintainers.
Merge integration
Merged master at
768f52591697ca1fdc6b667c054448dd466c570e, preserving both sets of checksum tests. The reopen regression now marks its graph remote before seeding storage, so master's new remote-graph guard still exercises checksum reconciliation.Validation after the merge:
frontend.worker.db-sync-test: 239 tests, 2,245 assertions, 1 failure inapply-history-action-redo-replays-upsert-property-test. The same assertion also fails when run alone on the exact master parent above (1 test, 13 assertions, 1 failure), independently of this PR.Link to Devin session: https://app.devin.ai/sessions/a288f458ecce4451a2fd7a526509ee89
Open in Devin Desktop: https://app.devin.ai/desktop/session/a288f458ecce4451a2fd7a526509ee89?variant=devin
Requested by: @tiensonqin