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 time-series transaction/page lifecycle, implement the smallest HA-safe concurrency fix, then add or enable a focused regression test and run the relevant engine tests.
- Assistant
The shard lock currently protects only the nested append, while the code’s claim that nested commits are independent conflicts with the observed deferred HA commit. I’m checking wrapper/local transaction stack behavior now so the fix preserves Raft WAL ownership rather than bypassing replication.
- Assistant
I found the important split: standalone nested commits apply immediately, but Raft commit releases file locks between WAL capture and local apply. The regression is already present but disabled; I’m enabling and running it first to establish whether this checkout reproduces standalone, HA-only, or both before changing lock scope.
- Assistant
The enabled test reproduces deterministically (58 missing of 240,000). The surprising part is that this also happens without Raft despite the nested commit being inside the shard lock, so I’m narrowing down which transaction actually owns the time-series pages; that distinction determines whether to extend lock lifetime or repair MVCC detection.
- Assistant
The loss survives synchronous page flushing, and the nested transaction is correctly created/restored with no time-series pages leaking into the outer transaction. I’m replacing the object-local mutex with the database’s file lock acquired before the slot read; that lock is shared across every engine/shard instance and is also held through Raft phase 1, consensus, and local phase 2.
- Assistant
The decisive finding is in compaction: phase 4a snapshots the current partial last page, then releases the write lock; phase 4c only rereads newly created pages. Samples appended into that same partial page during phase 4b are therefore omitted from sealed output and then cleared. I’m fixing the tail snapshot to resume from the exact row offset in the phase-4a page, preserving concurrent additions without holding the write lock during compression.
- Assistant
The full 48×5,000 regression now passes with all 240,000 samples while automatic compaction runs. I’m running the existing concurrent append/compaction and no-duplicate suites next, then I’ll inspect the final diff for accidental diagnostic changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.