Repository navigation
Description
Summary
executeTransaction runs the queued commands inside database.transaction(...), which retries the block
on an MVCC conflict or a concurrency-induced duplicated key. The #8037 fix moved the reply accumulator
inside the block so a retry cannot publish the discarded attempt's replies, and did the same for hSet's
and hDel's counters. All three are now correct.
What the block ALSO contains is the RAM commands - SET, GET, GETDEL, INCR, INCRBY,
INCRBYFLOAT, DECR, DECRBY - and those do not write to the transaction at all. They write to
database.setGlobalVariable(...), an ordinary ConcurrentHashMap on the database object. A rollback does
not touch it. So the rollback that resets the replies leaves every RAM mutation the failed attempt made
standing, and the next attempt applies it again.
The counter is the case that matters, because a counter is what people put in a MULTI block: INCR seq
followed by HSET Order {...} is the canonical use. One retry makes seq jump by two for one logical
EXEC. If the retry eventually commits, the caller is told it succeeded and the sequence has a hole nobody
reports; if it does not commit, the caller is told it failed and the sequence advanced anyway.
The retry budget is arcadedb.txRetries (default 3) for a conflict, and exactly one extra attempt for a
duplicated key (#4959's fail-fast), so the inflation is bounded but not small.
Where (HEAD 6fefb26)
redisw/src/main/java/com/arcadedb/redis/query/RedisQueryEngine.java:257
database.transaction(() -> {
final List<Object> attemptResults = new ArrayList<>(commands.size());
for (final String command : commands) {
final Object result = executeSingleCommandInternal(command);
attemptResults.add(result);
}
committed[0] = attemptResults;
});executeSingleCommandInternal dispatches case "INCR" -> incrBy(parts, false) at :307, and incrBy
ends with database.setGlobalVariable(key, newValue) at :424 - outside the transaction's reach, by
construction: LocalDatabase.setGlobalVariable is globalVariables.put(name, value) on a map the
TransactionContext knows nothing about.
The retry that re-enters it, engine/src/main/java/com/arcadedb/database/LocalDatabase.java:1877
} catch (final NeedRetryException | DuplicatedKeyException e) {
if (!createdNewTx)
throw e;
// RETRY
lastException = e;
if (wrappedDatabaseInstance.isTransactionActive())
wrappedDatabaseInstance.rollback();Repro
A Person type with a unique index on name, one document {"name":"dup"} already committed, then one
EXEC block that increments a counter and inserts the same name again - so the commit raises
DuplicatedKeyException, the block is retried once, and the second attempt fails the same way:
EXEC failed with DuplicatedKeyException: Duplicated key [dup] found on index 'Person[name]'
already assigned to record #1:0
counter 'c' after the FAILED EXEC = 2 (the block ran INCR once per attempt; nothing was committed)
Person count after the FAILED EXEC = 1
Nothing the block wrote was committed and the caller got an exception, yet c stands at 2.
Suggested fix
The honest options are to make the RAM commands transactional, or to keep them out of the retried block.
The cheap and local one is the second: buffer the RAM mutations the block performs and apply them after
database.transaction(...) returns, the same way the fix now publishes the replies - which also makes the
replies and the stored values agree, since today a retried INCR's reply is the inflated value.
Whichever is chosen, executeTransaction's javadoc should stop saying "Executes commands in a database
transaction (atomically)" without qualification: the RAM half of the command set is not in the
transaction and never was.
Scope / confidence
Tried to refute it three ways. (1) Maybe global variables ARE rolled back and I missed the hook:
LocalDatabase.setGlobalVariable is a plain put on globalVariables, nothing in TransactionContext
references that map, and the repro's c = 2 after a wholly rolled-back block settles it. (2) Maybe the
block never retries in practice because it always joins a caller transaction - in which case
LocalDatabase.transaction propagates instead of retrying (if (!createdNewTx) throw e): it does join
under the HTTP auto-commit wrapper, but then the retry happens one level up and re-runs the whole command,
which re-applies the INCR just the same; and on the embedded path (Database.command("redis", ...) with
no open transaction) it creates its own and retries here. (3) Maybe a retry is rare enough not to matter:
a duplicated key needs only one racing insert and a conflict only one racing writer on the same page,
which is the ordinary condition a retry loop exists for. Rated MEDIUM rather than HIGH because it needs a
block mixing RAM and persistent commands and a conflict to fire, and it corrupts a counter rather than a
record.
Activity
ruispereira commentedon Sep 24, 2026
Still valid at HEAD
1865ae08fd, and worth saying before anyone assumes #8248 covered it.The #8248 fix (
1bbfaef525) rewrote these exact lines ontocomputeGlobalVariable. That fixed the atomicity of a single INCR, butcomputeGlobalVariableis stillglobalVariables.compute(...)on a non-transactional map, so the rewrite made this issue's double-apply more deterministic rather than less: a retried EXEC still advances the counters its block contains, and a rollback still takes none of it back.Re-reproduced on this build:
counter 'c' after the FAILED EXEC = 2, with the Person count at 1.fix: address CodeRabbit review on PR #8309
fix(#8254,#8258,#8261): RAM writes follow the transaction that commit…
Merge pull request #8309 from ArcadeData/fix/issues-8261-8258-8254-8253
lvca commentedon Sep 25, 2026
Fixed in #8309, available in 26.10.1.
Redis in-memory commands inside a transaction now behave as follows:
SETfollows the transaction. It becomes visible to others only when the transaction commits and is discarded on rollback. This covers aMULTI/EXECblock, an HTTP request and a transaction opened by your application. A block that fails, for example on a duplicated key, leaves noSETbehind.INCR,INCRBY,INCRBYFLOAT,DECR,DECRBYandGETDELare applied atomically when they run, as in Redis, so two clients never receive the same counter value. When ArcadeDB automatically retries a block after a conflict, the retry reuses the value from the first attempt instead of incrementing again. If the block ultimately fails, the increment is not given back (like a database sequence), leaving a gap rather than risking a duplicate number.The Redis documentation has been updated accordingly.
❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.
fix(ArcadeData#8253,ArcadeData#8258,ArcadeData#8254,ArcadeData#8261):…