Time series: concurrent single-row SQL INSERTs silently lose samples (sealed-slot lost…
- User
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)
codeCREATE 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}:json - Observed on
- Assistant
I’ll trace the transaction/page visibility path, inspect the existing regression coverage, then implement the narrowest fix that preserves the parent WAL/HA behavior and run focused time-series tests.
- Assistant
The regression test is present and disabled. The key complication is confirmed in current code: the shard lock ends after the nested wrapper commit, while an enclosing SQL transaction may still own the effective page publication. I’m checking whether the transaction layer already has commit hooks/locks we can reuse instead of weakening HA replication.
- Assistant
I’ve enabled the supplied regression and started it with the repository’s already-cached test runtime (offline). It is exercising the full 48×5000 workload now; meanwhile I’m avoiding a transaction-lifetime lock design that could deadlock multi-shard transactions.
- Assistant
The failing run exposed the decisive pattern: slot reuse begins when compaction resets the mutable page, not at ordinary nested commits. Phase 4a snapshots the current partial page, releases the lock, and Phase 4c only rereads newly created pages; rows appended meanwhile to that same partial page are omitted from sealed output and then cleared. I’m fixing that boundary by leaving the active partial page for the final locked snapshot.
- Assistant
The full 240,000-insert regression now passes with an exact count. The fix keeps all immutable pages in the lock-free compression phase but defers the active partial page to Phase 4c, where the write lock guarantees its final row count is captured before the mutable bucket is cleared. I’m running the existing append/compact and shard concurrency suites next.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.