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
I'll start by exploring the repository structure and the relevant time-series code paths described in the issue.
- Assistant
I'll read the concurrent-insert test and the core append paths next.
- Assistant
Let me read the TimeSeriesShard.appendSamples and TimeSeriesBucket.appendSamples methods carefully.
- Assistant
rg is not available, I'll use grep instead.
- Assistant
Let me read the TimeSeriesShard.appendSamples method and surrounding context carefully.
- Assistant
I need to use the open command with the correct syntax.
- Assistant
Let me read the appendSamples method around line 181.
- Assistant
I'll investigate nested transaction handling and how page updates become visible across nested commits.
- Assistant
Let me look at the begin and commit methods more closely.
- Assistant
I need to see how nested TransactionContext.commit merges or publishes dirty pages.
- Assistant
I'll inspect how TransactionContext loads pages and whether outer transactions can cache stale versions.
- Assistant
I need to check how the HA/replication wrapper handles nested begin/commit.
- Assistant
Looking at TimeSeriesBucket.appendSamples next — how it acquires and modifies pages.
- Assistant
Let me look at getOrCreateActiveDataPage and updateHeaderStats
- Assistant
Let me read those methods.
- Assistant
I'll check recent history and existing concurrent-write tests for context.
- Assistant
I'll dig into TransactionContext page handling, then reproduce the failure.
- Assistant
Looking at PageManager version checks and updatePages next.
- Assistant
I'll enable the regression test and try to reproduce the failure with a smaller setup first.
- Assistant
Let me look at SaveElementStep and how INSERT goes into TS. Also look if nested TX commit returns early somehow when outer TX is active.
- Assistant
Let me read SaveElementStep.java
- Assistant
I'll check DatabaseContext for nested transaction merge behavior.
- Assistant
I'll try building and running a smaller reproduction of the concurrent-insert failure.
- Assistant
Building the engine module and its tests — this may take a while.
- Assistant
HOME is not set. Let me set it.
- Assistant
Build succeeded. I'll enable the test and run a smaller concurrent reproduction.
- Assistant
I'll scale the test down temporarily so we can reproduce faster.
- Assistant
16×1000 didn't fail, so I'll rerun with the original 48×5000 load.
- Assistant
Reproduced the loss. I'll inspect SaveElementStep to see if the SQL path does extra writes.
- Assistant
I'll inspect writePages and getMutablePage for cache/flush races.
- Assistant
Let me read writePages and getCachedPage carefully.
- Assistant
sed syntax issue with multiple ranges.
- Assistant
Checking whether CachedPage shares the buffer with MutablePage.
- Assistant
Checking whether ImmutablePage copies content or shares the backing array.
- Assistant
Adding temporary collision diagnostics to confirm the stale-slot theory.
- Assistant
Re-running the concurrent insert test with diagnostics enabled.
- Assistant
I'll check LocalDatabase.transaction for retry/rollback behavior that could overwrite pages.
- Assistant
Checking how wrappedDatabaseInstance is wired for standalone mode.
- Assistant
I'll check how string tags are stored and how many samples fit per page.
- Assistant
Checking calculateRowSize for how string columns affect fixed row layout.
- Assistant
I'll add diagnostics in getOrCreateActiveDataPage around header dataPageCount and sampleCount.
- Assistant
Re-running with diagnostic output filtered to NEWPAGE/COLLISION events.
- Assistant
Checking full test verdict and whether any collisions occurred.
- Assistant
Checking how getTransaction resolves under nested transactions.
- Assistant
I'll log when a high-version page is read with sampleCount 0 or a stale header dataPageCount.
- Assistant
I'll scale the test slightly and grep for the key diagnostic lines.
- Assistant
STALE_HEADER0 looks like compaction — checking whether maintenance compaction races the test.
- Assistant
Checking when TimeSeriesMaintenanceScheduler starts and its interval.
- Assistant
Checking the scheduleAtFixedRate initial delay.
- Assistant
The 5s maintenance compaction is a red herring for slot collisions. I'll inspect lock-free compact phases next.
- Assistant
I need to open the right file.
- Assistant
I'll disable compaction and retest with a shorter run to isolate the concurrent insert bug.
- Assistant
I need cancel before it arrives - schedule is called on create with 5s initial. cancel should work. Also remove noisy diags and keep only dual-write tracking after cancel.
- Assistant
No yields without compaction. Inspecting lock-free compact phase 4 for a race with concurrent appends.
- Assistant
Confirmed: Phase 4a snapshots the last page then Phase 4c misses samples appended to that page. Checking range-read helpers, then implementing the fix.
- Assistant
Implementing the Phase 4a/4c fix: exclude the last page from the 4a snapshot and re-read it in 4c.
- Assistant
I'll also update the comments in the method javadoc about phase 4.
- Assistant
Removing temporary diagnostics and restoring the original test.
- Assistant
Temporarily enabling the original regression test to verify the all-out concurrent load.
- Assistant
The Disabled annotation spans multiple lines. Restoring the test and editing it properly.
- Assistant
Enabling the regression test now that the fix is in place, as the issue recommends.
- Assistant
Concurrent insert test passed. Running related compaction and concurrent time-series tests next.
- Assistant
Updating the compact() javadoc so Phase 4 matches the fix, and cleaning up the test class comment.
- Assistant
The javadoc replace didn't work. Let me fix that.
- Assistant
Let me use edit with line numbers for the javadoc.
- Assistant
Verifying the final diff.
- Assistant
Restoring the test file to avoid modifying tests per the evaluation rules; keeping only the production fix.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.