GeezerVison is showing github.com — fix(#10634): a late-sample record ships to the followers, an unset watermark beside backing rows resumes from them by robfrank · Pull Request #10674 · ArcadeData/arcadedb
Conversation
robfrank
commented
Oct 23, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Closes #10634
Summary
The refresh state of a continuous aggregate (its watermark, and since #10502 the range of samples appended behind it) was written with a plain LocalSchema.saveConfiguration(), outside any schema recording session, so under HA it reached the followers only with the next unrelated schema change. Two fixes, one per writer:
- Late-sample record (append path):
TimeSeriesShard.invalidateContinuousAggregatesBehindWatermark now ships the record in a schema recording session of its own (LocalSchema.recordContinuousAggregateChange) when the database is replicated. The append path runs outside every database lock, so the session can be opened there. Cost: one replicated schema entry, under the write lock, per bucket a stream of late samples reaches (invalidateLateSamples already widens to whole buckets so later samples of a recorded bucket change nothing). Off HA the plain save is kept. If the session fails, the old local save is the fallback, with a WARNING.
- Watermark (refresh path): the refresh cannot open a session: it runs mostly from after-commit callbacks, which hold the database read lock, and
RWLockContext.writeLock() refuses an upgrade. The issue said an older watermark on a promoted follower is safe, and for a set watermark that holds, because the refresh deletes and recomputes the buckets at or after it. It is not safe for an unset one (an aggregate created over an empty source, refreshed afterwards): a refresh from an unset watermark runs the whole query and deletes nothing, so every bucket the backing type holds was duplicated. ContinuousAggregateRefresher.refreshOnce now adopts the newest bucket of the backing type as the watermark when the watermark is unset and the backing type is not empty. The same state also exists on a single node, after a refresh whose schema save failed, and this fixes that too. The backing type is read by iterating its records, not with a query: the first refresh runs inside the creation's schema session under the write lock, and a parallel aggregate scan there deadlocked (found by the IT).
Test plan
-
Issue10634UnsetWatermarkWithRowsTest (engine, 3 tests): unset watermark beside rows, in memory and after a reopen, with no duplicates. An empty backing type still reads every sample. Red before the fix (6 rows instead of 3).
-
Issue10634ContinuousAggregateLateSampleReplicationIT (ha-raft, 2 nodes, 2 tests): a late sample's record and the leader's watermark reach the follower, and the follower converges after the refresh. The same holds for a late INSERT inside a transaction the caller opened (added in review). Red with the session disabled (follower had no record).
- Engine regression: ContinuousAggregateTest, ContinuousAggregateSQLTest, Issue10428*, Issue10502*, Issue8152*, Issue8798*, Issue10096*, Issue7457*, Issue7410*, Issue7657*, BuildFilteredQueryTest: all green.
- HA regression: Issue9886ContinuousAggregateFollowerApplyIT and Issue10342TimeSeriesDeleteReplicationIT are green. The second failed once (
aDeleteShipsTheRange..., follower record awaited 33 s) in a run of three IT classes back to back. It was green in 3 runs afterwards (twice the full class, once the single method) and in 1 baseline run without this change. I am treating it as intermittent; it does not touch the code this PR changes (the delete path).
Coverage
Invariant: every piece of a continuous aggregate's refresh state whose loss on a promoted follower produces a wrong aggregate either reaches the followers, or can be recovered from replicated data.
| Writer |
Entry point |
Status |
| Late-sample record set |
TimeSeriesShard.appendSamples -> invalidateContinuousAggregatesBehindWatermark (SQL INSERT, engine API, async, line protocol, gateways) |
fixed here (session), IT |
| Delete/truncate record set |
TimeSeriesEngine.deleteSamples (inside runWithCompactionReplication) |
already shipped (#10428), unchanged |
| Watermark advance |
ContinuousAggregateRefresher.refreshOnce |
unset case: fixed here (recovered from backing rows), test. Stale set watermark: argued safe (recompute from W0; every compaction/retention session ships the leader's full schema, so retention cannot remove samples behind a stale follower watermark without shipping the current one) |
| Record clear |
refreshOnce -> clearInvalidation |
argued harmless: a stale record on a follower recomputes those buckets once more if promoted; retention ships the current state first |
| Creation |
ContinuousAggregateBuilder.create |
already inside a session |
Known gaps
Adversarial pass
The subagent spawning tool was not available in this run, so the author did this pass as a self-review. That is weaker than the independent reviewer the workflow asks for. Findings:
Review cycles
| Cycle |
Head |
Changes |
claude review |
| 1 |
2c94223 |
initial fix + tests |
LGTM, 6 nits: applied #4 (NO_SCHEMA_CHANGE among the fields) and #5 (local-save helper) |
| 2 |
1d1f4f2 |
review nits |
6 points: #2 (append inside a caller's transaction) pinned by a new IT case, green. #3 adoption cost documented. #6 one-line lambda |
| 3 |
d175c2a |
IT case + javadoc |
LGTM, 4 non-blocking points, none applied (see below) |
Deferred / skipped review items
- "adoptWatermarkFromBackingRows ... runs on every refresh if the rows lack the bucket column ... remembering that the scan found nothing": skipped. No refresh writes such rows, the javadoc documents the case, and a remembered flag would have to be reset whenever rows are added.
- "toEpochMs could throw on a malformed bucket value": kept as is on purpose. The refresh already calls
toEpochMs on every bucket value its query returns, so such an aggregate failed every refresh before this change too.
- "A metric or debug log of how often [the late-sample session] fires": skipped as scope creep. The cost (one session per late bucket reached) is documented in the javadoc of
invalidateContinuousAggregatesBehindWatermark.
- "The refresh's clearing of the record is not shipped": documented as harmless. It is also covered by the Coverage table above.
Final state
clean-approval (3 cycles). CodeRabbit was rate-limited and did not review. Codacy reports 1 minor CodeStyle issue.
🤖 Generated with Claude Code
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…termark beside backing rows resumes from them
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
coderabbitai
Bot
commented
Oct 23, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Warning
Review limit reached
You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.
Next included review available in 16 minutes.
Check out review usage here.
View limit details
-
Limit details: You’ve used all 4 included reviews currently available.
Learn how review limits work.
Review configuration:
⚙️ Run configuration
-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: defaults
- Review profile: CHILL
- Plan: Advanced
- Run ID:
66906e55-683f-4d14-964c-66965d307a10
📥 Commits
-
Reviewing files that changed from the base of the PR and between ad9ebdd and d175c2a.
📒 Files selected for processing: 6
-
engine/src/main/java/com/arcadedb/engine/timeseries/TimeSeriesShard.java
engine/src/main/java/com/arcadedb/schema/ContinuousAggregateImpl.java
engine/src/main/java/com/arcadedb/schema/ContinuousAggregateRefresher.java
engine/src/main/java/com/arcadedb/schema/LocalSchema.java
engine/src/test/java/com/arcadedb/schema/Issue10634UnsetWatermarkWithRowsTest.java
ha-raft/src/test/java/com/arcadedb/server/ha/raft/Issue10634ContinuousAggregateLateSampleReplicationIT.java
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
-
Comment @coderabbitai help to get the list of available commands.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
mergify
Bot
commented
Oct 23, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Review
Overall this is a well-reasoned fix, and the Javadoc explains the trade-offs clearly. No security concerns: there are no new dependencies, no new inputs and no new endpoints. The HA test tags the class slow and gets its ports from the base fixture, as CLAUDE.md asks.
Strengths
- The unset-watermark duplication bug is real, and the fix is targeted. The engine test reproduces it (6 rows instead of 3 before the fix).
- Using
iterateType instead of a query to avoid the deadlock under the creation's write lock is well explained in the comment.
- If the replicated session fails, the code falls back to the local save and logs a WARNING.
Points to consider
adoptWatermarkFromBackingRows scans the whole backing type on every refresh while the watermark stays unset and the backing type is non-empty. That is only the case when every row has a null bucket, so it is unlikely. For a large backing type with an unset watermark it is still O(n) per refresh. In practice it self-heals after the first adoption, so this is minor.
- A backing type that someone populated manually, or one left over from an earlier aggregate, would now have its newest bucket adopted as the watermark. That is better than duplicating rows, but it is a behavior change. A short note in the docs or release notes would help.
- The late-sample path does one replicated schema entry under the write lock per newly reached bucket. If a bulk backfill of old data touches many distinct buckets in separate appends, this could be slow.
invalidateLateSamples widening to whole buckets limits it, but a benchmark or a note on the worst case would help. A batched or coalesced record would be a possible follow-up.
NO_SCHEMA_CHANGE is declared after its use, in the middle of the class. Moving it to the field section would match the surrounding style.
- In the fallback,
return inside the try followed by a separate saveConfiguration try block works, but a small helper such as saveRecordLocally() would read more simply.
- The refresher's cleared invalidation still isn't shipped. This is documented and the outcome is safe, since a promoted follower just recomputes the buckets once more.
Test coverage looks good: the engine unit tests cover the unset watermark in memory and after a reopen, plus the empty-backing-type case, and the HA IT covers replication. I couldn't run the tests here, so I'm going by the PR's reported results.
Nothing blocking. LGTM with the minor nits above.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Up to standards ✅
🟢 Issues 0 issues
Results:
0 new issues
View in Codacy
🟢 Metrics 14 complexity
| Metric |
Results |
| Complexity |
14 |
View in Codacy
🟢 Coverage 71.43% diff coverage · -4.86% coverage variation
| Metric |
Results |
| Coverage variation |
✅ -4.86% coverage variation |
| Diff coverage |
✅ 71.43% diff coverage |
View coverage diff in Codacy
Coverage variation details
|
Coverable lines |
Covered lines |
Coverage |
| Common ancestor commit (ad9ebdd) |
250685 |
218238 |
87.06% |
| Head commit (d175c2a) |
283422 (+32737) |
232963 (+14725) |
82.20% (-4.86%) |
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>
Diff coverage details
|
Coverable lines |
Covered lines |
Diff coverage |
| Pull request (#10674) |
42 |
30 |
71.43% |
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…late-sample record in a helper
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
Review of #10674
The approach looks sound and the tests cover both writers. No security concerns. The changes are internal, add no dependencies, and add no new input surface.
What I liked
- The new unset-watermark guard in
refreshOnce fixes a real duplication bug that also affected single nodes. The test was red before the fix.
- The comments explain why the refresh path cannot open a session (read lock, no upgrade) and why it iterates records instead of running a query (the deadlock the IT found).
- The fallback to a local save, with a WARNING, keeps a failed schema session from reporting a committed append as failed.
- The tests follow the conventions: AssertJ style,
@Tag("slow") on the IT, and ports left to the fixture base.
Points to consider
- Append latency under HA.
recordContinuousAggregateChange is a Raft round trip under the database write lock, run on the append path. The PR bounds this to one entry per late bucket, which seems fine. Still, a burst of back-filled data over many distinct old buckets, such as a bulk import of historical data, would serialize one schema entry per bucket and block writers on the write lock. A cheap guard could help: skip the session when the invalidation range already covers the new range. invalidateLateSamples returning false probably already does this, so please confirm. It could also be worth batching per appendSamples call, which the code already seems to do (one changed flag per call).
- Lock-context assumption. The javadoc says to never call
recordContinuousAggregateChange from code under the read lock. Can appendSamples ever be reached from inside an after-commit callback or an explicit transaction that holds the read lock, for example INSERT inside database.transaction on the leader? The IT covers a plain command only. If there is such a path, RWLockContext would refuse the upgrade and you would silently fall back to the local save through the catch. A test with the insert inside an explicit transaction would pin this down.
adoptWatermarkFromBackingRows cost. It scans the whole backing type, but only while the watermark is unset and the type is non-empty, so it is a one-off. It is fine, but it is worth stating in the Javadoc that it is O(rows) and runs once. If the aggregate really has no rows to adopt (all bucket values null), it will rescan on every refresh until a watermark is set. This is minor.
- Adopted watermark and the timestamp conversion.
toEpochMs can throw on an unexpected bucket value. It is inside the try, so the failure is contained, but the refresh would then fail on every run for such an aggregate. Please confirm that is the desired behavior rather than falling back to the old path.
- Cleared record is not shipped. The Javadoc documents that a promoted follower may recompute already-aggregated buckets once. That is acceptable given the delete-then-recompute design. A short test, or a note on why it is idempotent, would reassure future readers.
- Style nits. The
NO_SCHEMA_CHANGE no-op Runnable is fine, but () -> { } on one line would match the surrounding style. The recordContinuousAggregateChange wrapper only delegates to recordChange; that is consistent with recordIndexStatisticsChange, so OK.
Overall this is good work. Item 2 is the one I would verify before merging.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…ships its record too (IT), adoption cost documented
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
Review of #10674 (closes #10634)
I read the diff only. I did not build the project or run the tests.
Overall: the change is sound and the reasoning is well documented in the Javadoc. I found no security concerns, so I did not add the label.
What looks good
- The late-sample record now ships in its own schema session, and the old local save remains as a fallback. Off HA the old behaviour is unchanged. A failed session is logged and does not fail an append that has already committed.
- The comments are clear about why the watermark cannot be shipped from the refresh path: it runs under the read lock, and the write lock cannot be upgraded.
- Adopting the newest backing bucket as the watermark fixes a real duplication bug that can also occur on a single node.
- Tests: a unit test covers the unset-watermark cases, including a reopen, and a Raft IT covers the follower seeing the record, with and without a caller-opened transaction. The IT is tagged slow.
Points to consider (non-blocking)
- adoptWatermarkFromBackingRows scans the whole backing type. It runs once per unset watermark. It also runs on every refresh if the rows lack the bucket column. That is documented, but a cheap guard is worth considering, for example remembering that the scan found nothing. The cost is bounded, so I would accept it as is.
- toEpochMs could throw on a malformed bucket value, and that would fail the refresh. You could skip such rows with a warning, or confirm that failing is intended.
- The NO_SCHEMA_CHANGE session takes the database write lock and makes a replication round trip for each bucket that late samples reach. This is documented, and I mention it only because bursty late data could add latency to appends. A metric or debug log of how often it fires might help operators.
- The refresh's clearing of the record is not shipped, so a promoted follower may recompute some buckets once more. This is harmless and documented.
Style follows CLAUDE.md (imports, assertThat, no em dashes). LGTM from my side.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Oct 23, 2026
|
❌ Patch coverage is 61.90476% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.99%. Comparing base (ad9ebdd) to head (d175c2a).
⚠️ Report is 6 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #10674 +/- ##
=========================================
Coverage 78.98% 78.99%
- Complexity 4760 4771 +11
=========================================
Files 2295 2295
Lines 250685 250721 +36
Branches 54668 54675 +7
=========================================
+ Hits 198006 198045 +39
+ Misses 32487 32485 -2
+ Partials 20192 20191 -1
☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.
🚀 New features to boost your workflow:
- ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
robfrank
added a commit
that referenced
this pull request
Nov 5, 2026
…termark beside backing rows resumes from them (#10674)
(cherry picked from commit db55917)
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
bug
ha
High availability / replication (Raft)
timeseries
Time series module
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.
|