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
Reading the key source files and the concurrent-insert regression test next.
- Assistant
Let me look at the appendSamples method in TimeSeriesShard and the bucket code, as well as the concurrent test and any related PRs or git history for fixes.
- Assistant
I'll inspect the append path and how nested transactions publish page updates.
- Assistant
Investigating nested transaction commit behavior and how pages become visible across transactions.
- Assistant
Let me look at LocalDatabase.begin and commit more carefully to understand nested transaction behavior.
- Assistant
Looking at nested transaction commit and how pages are read across parent/child transactions.
- Assistant
On standalone LocalDatabase, nested TX does fully commit. So why would there be a issue on embedded single-node? The nested commit on LocalDatabase does publish the page updates, but the problem is that the outer transaction's commit is what actually ships the writes to followers via Raft WAL (issue #4382).
- Assistant
Let me check git history for related fixes and try to reproduce the bug.
- Assistant
Running the concurrent-insert test to reproduce the data-loss failure.
- Assistant
Checking SaveElementStep and PageManager page-version update behavior.
- Assistant
Let me look at TransactionContext.getPageToModify and how nested commits interact. Maybe when nested TX commits, updates go to page manager, but there's a race with the outer TX's view? They're on the...
- Assistant
Let me look at getPageToModify fully and how MVCC version is assigned on pages when reading:
- Assistant
I'll inspect
updatePagesand how async flush interacts with the page cache. - Assistant
I'll check TestHelper and concurrent append tests, then try compiling.
- Assistant
Checking how multi-thread database access initializes the transaction context.
- Assistant
Enabling the test and building the engine module so we can reproduce the failure.
- Assistant
Let me look at git show of PR #4450 which has the test, and also the timeseries concurrency fix.
- Assistant
Inspecting the HA/replication commit path change that uses
getWrappedDatabaseInstance. - Assistant
Checking how RaftReplicatedDatabase proxies begin/isTransactionActive.
- Assistant
Looking at ServerDatabase and HTTP command transaction wrapping.
- Assistant
Inspecting how DatabaseAbstractHandler opens and commits per-request transactions.
- Assistant
Looking at DatabaseAbstractHandler around lines 145-180 for transaction wrapping:
- Assistant
So for HTTP INSERT:
- Outer database.transaction beginsI understand the core of the issue you're describing: concurrent single-row inserts into a time series table can silently lose samples because the slot counter read-modify-write in
TimeSeriesBucket.appendSamplesisn't atomic with respect to the durable publish, and the outer transaction's commit happens outside the per-shardappendLock.
- Outer database.transaction beginsI understand the core of the issue you're describing: concurrent single-row inserts into a time series table can silently lose samples because the slot counter read-modify-write in
- Assistant
Compiling the engine and running a small reproduction next.
- Assistant
HOME is not set - need to set it.
- Assistant
Build succeeded. Enabling and running the concurrent insert test next.
- Assistant
Fixing the
@Disabledannotation breakage from the earlier edit. - Assistant
Let me verify the file looks correct now and run the test.
- Assistant
The repro shows ~23 lost samples. Checking whether SQL
commandopens another nested transaction on top of the outer one. - Assistant
I'll check which transaction context TimeSeriesBucket's database field resolves to.
- Assistant
Checking default isolation and whether the outer transaction freezes page snapshots.
- Assistant
Checking transaction stack pop/push behavior for nested commits:
- Assistant
Re-running with collision diagnostics enabled.
- Assistant
Collisions show advancing page versions but stale contentslotsellation — investigating how page cache stores version vs content.
- Assistant
Intermittent stale slot reads match a deferred-publish race. Adding diagnostics around nested transaction depthand commit.
- Assistant
Restoring the diagnostics, then rerunning ConcurrentWrite with an outer transaction.
- Assistant
ConcurrentWrite with outer TX passed. Verifying the patch and comparing the SQL INSERT path next.
- Assistant
Confirming ConcurrentWrite asserts the exact count, then scaling it up to match.
- Assistant
Inspecting STRING column writes and the CREATE TIMESERIES path — the bug may be SQL-specific.
- Assistant
The SQL path uses a STRING tag; ConcurrentWrite only has DOUBLE. Testing whether STRING tags trigger the loss.
- Assistant
Comparing SQL
count(*)to the engine sample count, and tracing the SQL INSERT path more carefully. - Assistant
grep closed early. Let me get the SQL count line.
- Assistant
Tracing the SQL INSERT execution path for side effects that might dirty time-series pages in the outer transaction.
- Assistant
I'll check CreateRecordStep and the insert planner for unintended bucket record allocation on TS types.
- Assistant
Checking whether ConcurrentWrite produces slot collisions under the same diagnostics.
- Assistant
Bad redirect. Let me fix.
- Assistant
Adding brief nest-depth logging for the first few appends on each path.
- Assistant
Comparing CREATE TIMESERIEScodec type setup vs the manual engine constructor.
- Assistant
CREATE TIMESERIES schedules maintenance祖; the manual engine path doesn't. Checking whether compaction races with inserts.
- Assistant
Maintenance starts after 5s on CREATE TIMESERIES. Checking whether disabling it stops the sample loss.
- Assistant
Bad grep due to typing error. Let me rerun.
- Assistant
Maintenance compaction is the trigger. Re-enabling it and analyzing the compact/append race.
- Assistant
Found the bug: samples appended to the last page during phase تقي 4b are dropped in phase 4c. Inspecting how full pages are read and implementing a fix.
- Assistant
Implementing the phase-4a page-rotate so appends during 4b can't land on already-snapshotted pages, then cleaning up diagnostics.
- Assistant
Checking whether ConcurrentInsertTest isd restored properly.
- Assistant
Implementing the compaction fix: adding a page-rotate helper and updating phase 4a.
- Assistant
Adding
sealActiveDataPageForCompactionand refactoring page allocation next. - Assistant
Updating phase 4a_in TimeSeriesShard to seal and commit (not rollback).
- Assistant
Updating phase 4 to track
sealedUptoand read tails from there. - Assistant
The phase 4 region got corrupted—rewriting it cleanly from the original.
- Assistant
I'll replace the corrupt section with clean code using Python.
- Assistant
Verifying the rest of phase 4c and compiling.
- Assistant
Fixing indentation and running the tests.
- Assistant
ConcurrentInsertTest is still skipped — checking why
@Disabledwasn't removed. - Assistant
Concurrent insert passes. Running related timeseries tests and restoring the test file.
- Assistant
Re-running the concurrent insert test a few more times for stability, then updating the phase-4 javadoc.
- Assistant
Reviewing the final diff for cleanliness.
- Assistant
Verifying the bucket methods aren't duplicated.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.