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, the
@Disabledannotation is removed. Let's also reduce thread/iteration counts temporarily for faster reproduction, then run.Assistant
Now let's try running this test with maven to reproduce the issue.
Assistant
Now let's revert the test file too, then reapply just the
@Disabledremoval cleanly.Assistant
Clean slate. Now let's implement the real fix in
TimeSeriesBucket.javaandTimeSeriesShard.java.Assistant
Now let's add the overload with a starting row offset for the first page, plus a helper to get a page's current sample count.
Assistant
Now let's update
TimeSeriesShard.compactInternal()Phase 4a/4c logic:Assistant
Compiles. Now let's enable the disabled test and run it to verify the fix resolves the data loss.
Assistant
Now let's run the test (full scale, with default scheduler timing) multiple times to make sure the fix holds reliably.
Assistant
Test passed (no failure output). Let's run it a few more times to be confident about flakiness resolution, given the race is timing-dependent.
Assistant
All three runs pass consistently. Let's also verify against a similar potential edge case — the
Phase 1/readFullPagesForCompactionboundary andapplyRetention/applyDownsamplingpaths which might have similar page-boundary assumptions. Let's check those.Assistant
Good — those only touch the sealed store, unaffected by mutable-page RMW concerns. Now let's run the broader TimeSeries test suite to ensure nothing broke.
Assistant
All 236 tests pass, including the newly-enabled regression test. Let's also run the broader engine test suite (or at least other tests referencing PageManager/TransactionContext) to make sure nothing else broke.
Assistant
I didn't touch PageManager, so these should be unaffected, but let's run them briefly for safety, plus the schema TimeSeries tests.
Assistant
Passed. Let's also check the schema TimeSeriesTypeBuilder related tests and run the full engine module test suite for schema package as a final sanity check (targeted, not the entire massive suite, to keep runtime reasonable).
Assistant
All pass. Let's view the final diff to review everything before submission.
Assistant
Formatting looks clean. Now let's view the full
TimeSeriesShard.javadiff area in context to double check correctness once more.Assistant
This looks correct and matches the intended fix. Let's run the concurrent insert test a few more times (with different scales) to ensure robustness, and also run the related compaction-specific concurrency tests again for extra confidence.
Assistant
All tests pass consistently. Let's do a final review of the complete diff and clean up any leftover artifacts.
Assistant
The changes are clean and minimal. Let's go through the checklist:
Assistant
Everything is consistent. Let's do one final full run of the specific regression test plus the surrounding timeseries suite to be thorough before finishing.
Assistant
All 236 tests pass. Let's review the checklist explicitly:
Checklist review:
-
Reproduced the error: Yes — enabling the disabled
TimeSeriesConcurrentInsertTestreproduced the exact silent sample loss (e.g. 239994/240000, matching the issue's reported magnitude of loss). -
Confirmed the fix resolves it: Yes — after identifying the true root cause (a race in the lock-free compaction's Phase 4a→Phase 4c window, where the bucket's mutable page can receive additional appended rows without the header's changing, so those extra rows were never captured into the sealed store before wiped the page), I implemented a fix and reran the regression test multiple times at full scale (48 threads × 5000 inserts) — it passes reliably every time.
-
Assistant
Ready to submit. Let's finalize.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.