ISSUE DESCRIPTION Time series: concurrent single-row SQL INSERTs silently lose samples…
- User
ISSUE DESCRIPTION
Time series: concurrent single-row SQL INSERTs silently lose samples (sealed-slot lost update)
Summary
Under many concurrent single-row
INSERT INTO <timeseriesType> SET ts=…, <tag>=…, <field>=…statements (each in its own transaction, as happens over the HTTP/wire protocols), the time series engine silently drops samples. The client receives success on every insert (HTTP 200, no exception, noConcurrentModificationException), yet the stored row count comes up short. Confirmed real data loss: a full table scan returns the same short count ascount(*), and aGROUP BY sensor_idshows specific series missing rows.The batched InfluxDB line-protocol path (
POST /api/v1/ts/{db}/write, which appends many samples in one engine call/transaction) is not affected. Single-threaded inserts are not affected.Impact
Silent, unacknowledged data loss on the time series write path under concurrency. Severity is high because there is no error surfaced to the client — an application doing concurrent per-row ingestion over SQL (HTTP or gRPC) loses samples without any signal.
Environment
- Observed on
26.6.1-SNAPSHOT(== thearcadedata/arcadedb:latestimage at time of writing). - Reproduced both embedded (in-process engine) and over HTTP against the Docker image.
Reproduction
A. Embedded (fast, deterministic at high concurrency)
A disabled regression test is included in PR #4450:
engine/src/test/java/com/arcadedb/engine/timeseries/TimeSeriesConcurrentInsertTest.javaIt creates a
TIMESERIES TYPE … SHARDS 1, runs 48 threads × 5000 single-rowINSERTs (each in its owndatabase.transaction(...)), then assertscount(*) == 48*5000. Result: e.g. 239911 / 240000 — 89 samples lost, with no exception and no failed transaction.Enable it by removing the
@Disabledannotation.B. Over HTTP (against the published image)
CREATE TIMESERIES TYPE sensor TIMESTAMP ts TAGS (sid STRING) FIELDS (v DOUBLE) SHARDS 1Then 16 threads, each POSTing 5000 distinct single-row inserts to
POST /api/v1/command/{db}:{"language":"sql","command":"INSERT INTO sensor SET ts=<unique>, sid='s<thread>', v=<i>"}SELECT count(*) FROM sensorreturns short by out of 80000 across runs. - Observed on
Assistant
Good, disabled removed. Let's check build tooling (maven wrapper) and try running just this test.
Assistant
Build works offline. Now let's run the specific test.
Assistant
Good, reproduced the issue (240000 expected vs 239949 actual). Now let's dig into the actual root cause more precisely by examining page cache/version mechanics.
Assistant
Now let's write a small standalone reproduction script that runs fewer threads for faster debugging, and dumps the DIAG_LOG at the end to find collisions.
Assistant
Now let's re-enable the maintenance scheduler in the single-thread diag test and run it to see the compaction diagnostics around the missing rows.
Assistant
Let's revert the diagnostic instrumentation in the main source files, then apply the real fix cleanly.
Assistant
Now let's view the exact current code for the read methods and compaction phases to apply a precise fix.
Assistant
Now let's add the overload with skip support and a helper to get a page's current sample count.
Assistant
Now let's update
TimeSeriesShard.compactInternalto capture the boundary page's sample count in Phase 4a and use it in Phase 4c.Assistant
Good, this uses
tailDatacorrectly (checks for null). Now let's build and test.Assistant
Compiles cleanly. Now let's re-add the diagnostic single-thread and multi-thread tests (temporarily) to validate the fix, and also run the official disabled test (now enabled).
Assistant
Single-threaded test now passes with no loss. Now let's run the concurrent (48-thread) official test.
Assistant
Test passed (no failures reported). Let's run it a few more times to make sure it's stable, plus run the other timeseries-related tests to check for regressions.
Assistant
All 3 runs passed consistently. Now let's clean up my temporary diagnostic test file and run the broader timeseries test suite to check for regressions.
Assistant
Let's run the entire timeseries test package (excluding slow benchmark, but including all others) to make sure nothing broke.
Assistant
It's tagged "benchmark". Let's run the full timeseries suite while excluding that tag, and get proper summary.
Assistant
All 365 tests pass, including the now-enabled
TimeSeriesConcurrentInsertTest. Let's also run the full engine test suite more broadly to check for wider regressions (at least a significant subset, since the full suite might take very long).Assistant
This looks good. Now let's check the test diff (the disabled test change) and finalize.
Assistant
Let's rebuild and re-run the full timeseries suite one more time to confirm everything is clean.
Assistant
All 365 tests pass. Now let's also run the wider engine test suite for any other regressions, particularly around schema, engine, and database transaction tests, given caution about broader impact.
Assistant
Confirmed: these failures are pre-existing environment issues (running as root, so permission-denial tests can't work), unrelated to our change. Let's rebuild with our fix applied.
Assistant
Let's do a final review of the diff and clean up any leftover files.
Assistant
This is clean. Let's do a final confirmation run of the previously-disabled regression test plus a couple more stress runs to ensure stability, then submit.
Assistant
Both runs pass consistently. Now let's go through the checklist.
Checklist review
- Reproduced the reported error: Yes. I enabled the previously-
@Disabledregression test (TimeSeriesConcurrentInsertTest) and confirmed the failure (239949–239988/240000, varying per run). I also built dedicated diagnostic tests (with a synchronized per-append log and an atomic in-critical-section counter) to empirically rule out the hypothesis in the issue (a stale slot read due to theappendLock/nested-transaction interaction) — I proved the per-shardappendLockdoes fully serialize appends (zero concurrent entries observed). I then isolated the true root cause: the backgroundTimeSeriesMaintenanceScheduler's automaticcompactAll()(which fires ~5s after a TimeSeries type is created) silently drops a contiguous run of samples that were appended to the "boundary" (still-active) mutable data page in the narrow window between compaction's Phase 4a snapshot and Phase 4c's final re-lock — reproducible even single-threaded, confirming it's a compaction bug, not a pure append-concurrency bug (concurrency just makes it much more likely to be observed within a short test window because it generates enough volume to trigger page growth during that window).
- Reproduced the reported error: Yes. I enabled the previously-
Assistant
-
Confirmed the fix resolves the error: Yes. After the fix,
TimeSeriesConcurrentInsertTest(48 threads × 5000 rows,SHARDS 1) passes reliably across multiple runs, and my single-threaded 240,000-row reproduction (which also lost rows before the fix) now shows zero missing timestamps. -
Thought about edge cases: Yes — I explicitly handled: (1) the boundary page having 0 samples at the Phase 4a snapshot (brand-new page just rolled to), (2) the boundary page becoming completely full and rolling over to one or more new pages between Phase 4a and Phase 4c, (3) the boundary page staying the same page but gaining more rows (no rollover), (4) no new data at all between phases (fromPage==toPage, skip==count, contributes zero rows — matching prior behavior), and (5) bucket-aligned compaction (
compactionBucketIntervalMs > 0, exercised byBucketAlignedCompactionTest, still passes).
-
Assistant
- Ran existing tests and confirmed they pass: Yes — all 365 tests in the
com.arcadedb.engine.timeseriespackage pass (including compaction-specific tests likeBucketAlignedCompactionTest,TimeSeriesConcurrentAppendCompactTest,TimeSeriesCrashRecoveryTest,TimeSeriesRetentionTest,TimeSeriesDownsamplingTest,TimeSeriesSealedStoreTest). I also ran the broaderengine,database, andschematest packages (735 tests) and confirmed the only 2 failures (FileManagerTestpermission tests) are pre-existing environment artifacts (running as root, unrelated to this change — verified identical failures on the unmodified code viagit stash).
Let's do one final check of the complete diff before submitting.
- Ran existing tests and confirmed they pass: Yes — all 365 tests in the
Assistant
This is a clean, minimal, well-tested fix. Let's submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.