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-version behavior and existing time-series tests, then implement the narrowest conflict-safe fix and run the focused regression plus related engine tests.
- Assistant
The regression is already present but disabled. The key inconsistency is now clear: the shard lock covers the nested commit, while the page mutation can remain owned by the caller’s outer transaction. I’m enabling the test first to establish the exact behavior on this checkout before changing transaction ownership.
- Assistant
The fix will keep the per-shard append lock until the enclosing transaction actually finishes, preserving the parent Raft/WAL path. I’m adding a transaction-completion callback (fires on both commit and rollback) so the lock cannot leak when a request fails.
- Assistant
The first fix attempt did not change the failing count, which rules out the outer-commit window as the only issue in this checkout. I’m checking shard/engine instance identity next; if SQL resolves a fresh shard object per command, the current instance-local lock never serializes those writers at all.
- Assistant
The diagnostic exposed a second, concrete lost-update window in the same regression: maintenance compaction starts at 5 seconds, snapshots the current partial page, then permits appends into that same page while compressing; finalization only rereads newly created pages and clears the appended rows in the existing page. I’m fixing that delta capture directly and removing the unsuccessful transaction-callback experiment.
- Assistant
The enabled 240,000-row regression now passes exactly, along with shard and concurrent append/compact tests. The decisive fix captures the row offset of the partial page at Phase 4a and rereads from that offset during Phase 4c, so samples arriving during compression are sealed before the mutable pages are cleared.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.