From 87956126f4f7fb16b4eddbca6bb5c7ae130ac476 Mon Sep 17 00:00:00 2001 From: Trevor Clinkenbeard Date: Mon, 22 Jun 2026 14:28:13 -0700 Subject: [PATCH 1/2] Convert ReadYourWrites.actor.cpp to standard coroutines --- fdbclient/ReadYourWrites.actor.cpp | 88 +++++++++--------------------- 1 file changed, 27 insertions(+), 61 deletions(-) diff --git a/fdbclient/ReadYourWrites.actor.cpp b/fdbclient/ReadYourWrites.actor.cpp index ca94e4e0204..9b3bb810bd8 100644 --- a/fdbclient/ReadYourWrites.actor.cpp +++ b/fdbclient/ReadYourWrites.actor.cpp @@ -27,7 +27,6 @@ #include "fdbclient/MonitorLeader.h" #include "flow/CoroUtils.h" #include "flow/Util.h" -#include "flow/actorcompiler.h" // This must be the last #include. class RYWImpl { public: @@ -351,48 +350,31 @@ class RYWImpl { } } - ACTOR template + template static Future readWithConflictRangeThrough(ReadYourWritesTransaction* ryw, Req req, Snapshot snapshot) { - choose { - when(typename Req::Result result = wait(readThrough(ryw, req, snapshot))) { - return result; - } - when(wait(ryw->resetPromise.getFuture())) { - throw internal_error(); - } - } + co_return co_await waitOrError(readThrough(ryw, req, snapshot), ryw->resetPromise.getFuture()); } - ACTOR template + + template static Future readWithConflictRangeSnapshot(ReadYourWritesTransaction* ryw, Req req) { - state SnapshotCache::iterator it(&ryw->cache, &ryw->writes); - choose { - when(typename Req::Result result = wait(read(ryw, req, &it))) { - return result; - } - when(wait(ryw->resetPromise.getFuture())) { - throw internal_error(); - } - } + SnapshotCache::iterator it(&ryw->cache, &ryw->writes); + co_return co_await waitOrError(read(ryw, req, &it), ryw->resetPromise.getFuture()); } - ACTOR template + + template static Future readWithConflictRangeRYW(ReadYourWritesTransaction* ryw, Req req, Snapshot snapshot) { - state RYWIterator it(&ryw->cache, &ryw->writes); - choose { - when(typename Req::Result result = wait(read(ryw, req, &it))) { - // Some overloads of addConflictRange() require it to point to the "right" key and others don't. The - // corresponding overloads of read() have to provide that guarantee! - if (!snapshot) - addConflictRange(ryw, req, it.extractWriteMapIterator(), result); - return result; - } - when(wait(ryw->resetPromise.getFuture())) { - throw internal_error(); - } - } + RYWIterator it(&ryw->cache, &ryw->writes); + auto result = co_await waitOrError(read(ryw, req, &it), ryw->resetPromise.getFuture()); + + // Some overloads of addConflictRange() require it to point to the "right" key and others don't. The + // corresponding overloads of read() have to provide that guarantee! + if (!snapshot) + addConflictRange(ryw, req, it.extractWriteMapIterator(), result); + co_return result; } template static inline Future readWithConflictRange(ReadYourWritesTransaction* ryw, @@ -1194,23 +1176,18 @@ class RYWImpl { } // For Snapshot::True and NOT readYourWritesDisabled. - ACTOR template + template static Future readWithConflictRangeRYW(ReadYourWritesTransaction* ryw, GetMappedRangeReq req, Snapshot snapshot) { - choose { - when(MappedRangeResult result = wait(readThrough(ryw, req, Snapshot::True))) { - // Insert read conflicts (so that it supported Snapshot::True) and check it is not modified (so it masks - // sure not break RYW semantic while not implementing RYW) for both the primary getRange and all - // underlying getValue/getRanges. - WriteMap::iterator writes(&ryw->writes); - addConflictRangeAndMustUnmodified(ryw, req, writes, result); - return result; - } - when(wait(ryw->resetPromise.getFuture())) { - throw internal_error(); - } - } + auto result = co_await waitOrError(readThrough(ryw, req, Snapshot::True), ryw->resetPromise.getFuture()); + + // Insert read conflicts (so that it supported Snapshot::True) and check it is not modified (so it masks + // sure not break RYW semantic while not implementing RYW) for both the primary getRange and all + // underlying getValue/getRanges. + WriteMap::iterator writes(&ryw->writes); + addConflictRangeAndMustUnmodified(ryw, req, writes, result); + co_return result; } template @@ -1408,8 +1385,6 @@ class RYWImpl { if (!ryw->tr.apiVersionAtLeast(410)) { ryw->reset(); } - - co_return; } catch (Error& e) { if (!ryw->tr.apiVersionAtLeast(410)) { ryw->commitStarted = false; @@ -1517,7 +1492,6 @@ class RYWImpl { ryw->debugLogRetries(e); ryw->resetRyow(); - co_return; } catch (Error& e) { if (!ryw->resetPromise.isSet()) { if (ryw->tr.apiVersionAtLeast(610)) { @@ -1532,16 +1506,8 @@ class RYWImpl { } } - ACTOR static Future getReadVersion(ReadYourWritesTransaction* ryw) { - choose { - when(Version v = wait(ryw->tr.getReadVersion())) { - return v; - } - - when(wait(ryw->resetPromise.getFuture())) { - throw internal_error(); - } - } + static Future getReadVersion(ReadYourWritesTransaction* ryw) { + co_return co_await waitOrError(ryw->tr.getReadVersion(), ryw->resetPromise.getFuture()); } }; From 042c89374f03b446686bdc62c821d8f4cf8f6c0c Mon Sep 17 00:00:00 2001 From: Trevor Clinkenbeard Date: Mon, 22 Jun 2026 14:30:49 -0700 Subject: [PATCH 2/2] Rename ReadYourWrites.actor.cpp --- design/AI-generated/foundationdb_subsystem_map.md | 2 +- design/AI-generated/subsystem_03_client_library.md | 2 +- fdbclient/{ReadYourWrites.actor.cpp => ReadYourWrites.cpp} | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename fdbclient/{ReadYourWrites.actor.cpp => ReadYourWrites.cpp} (99%) diff --git a/design/AI-generated/foundationdb_subsystem_map.md b/design/AI-generated/foundationdb_subsystem_map.md index e714626692e..07c2a227a7d 100644 --- a/design/AI-generated/foundationdb_subsystem_map.md +++ b/design/AI-generated/foundationdb_subsystem_map.md @@ -81,7 +81,7 @@ Plus supporting code: [`fdbserver/worker/`](https://github.com/apple/foundationd - **Retry loop**: `Transaction::onError()` handles `not_committed`, `transaction_too_old`, etc. by resetting and retrying with backoff. The canonical usage pattern is `loop { try { ... tr.commit(); break; } catch(Error& e) { wait(tr.onError(e)); } }`. - **Watches**: `tr.watch(key)` registers interest; the storage server notifies when the key changes. -**Principal files:** [`NativeAPI.actor.cpp`](https://github.com/apple/foundationdb/blob/main/fdbclient/NativeAPI.actor.cpp), [`ReadYourWrites.actor.cpp`](https://github.com/apple/foundationdb/blob/main/fdbclient/ReadYourWrites.actor.cpp), [`DatabaseContext.cpp`](https://github.com/apple/foundationdb/blob/main/fdbclient/DatabaseContext.cpp), [`MultiVersionTransaction.cpp`](https://github.com/apple/foundationdb/blob/main/fdbclient/MultiVersionTransaction.cpp), [`CommitTransaction.h`](https://github.com/apple/foundationdb/blob/main/fdbclient/include/fdbclient/CommitTransaction.h), [`SystemData.h`](https://github.com/apple/foundationdb/blob/main/fdbclient/include/fdbclient/SystemData.h), [`MonitorLeader.h`](https://github.com/apple/foundationdb/blob/main/fdbclient/include/fdbclient/MonitorLeader.h) +**Principal files:** [`NativeAPI.actor.cpp`](https://github.com/apple/foundationdb/blob/main/fdbclient/NativeAPI.actor.cpp), [`ReadYourWrites.cpp`](https://github.com/apple/foundationdb/blob/main/fdbclient/ReadYourWrites.cpp), [`DatabaseContext.cpp`](https://github.com/apple/foundationdb/blob/main/fdbclient/DatabaseContext.cpp), [`MultiVersionTransaction.cpp`](https://github.com/apple/foundationdb/blob/main/fdbclient/MultiVersionTransaction.cpp), [`CommitTransaction.h`](https://github.com/apple/foundationdb/blob/main/fdbclient/include/fdbclient/CommitTransaction.h), [`SystemData.h`](https://github.com/apple/foundationdb/blob/main/fdbclient/include/fdbclient/SystemData.h), [`MonitorLeader.h`](https://github.com/apple/foundationdb/blob/main/fdbclient/include/fdbclient/MonitorLeader.h) --- diff --git a/design/AI-generated/subsystem_03_client_library.md b/design/AI-generated/subsystem_03_client_library.md index e3bb2071b82..54bc9fc5202 100644 --- a/design/AI-generated/subsystem_03_client_library.md +++ b/design/AI-generated/subsystem_03_client_library.md @@ -279,7 +279,7 @@ Management API exposed as key-value operations: |------|---------| | [`fdbclient/NativeAPI.actor.cpp`](https://github.com/apple/foundationdb/blob/main/fdbclient/NativeAPI.actor.cpp) | Core transaction implementation, tryCommit, getValue, getRange | | `fdbclient/include/fdbclient/NativeAPI.actor.h` | Transaction class, TransactionState | -| [`fdbclient/ReadYourWrites.actor.cpp`](https://github.com/apple/foundationdb/blob/main/fdbclient/ReadYourWrites.actor.cpp) | RYW layer, write map, snapshot cache merging | +| [`fdbclient/ReadYourWrites.cpp`](https://github.com/apple/foundationdb/blob/main/fdbclient/ReadYourWrites.cpp) | RYW layer, write map, snapshot cache merging | | `fdbclient/include/fdbclient/DatabaseContext.h` | DatabaseContext: location cache, proxy tracking, watches | | [`fdbclient/include/fdbclient/CommitTransaction.h`](https://github.com/apple/foundationdb/blob/main/fdbclient/include/fdbclient/CommitTransaction.h) | MutationRef, CommitTransactionRef | | [`fdbclient/MultiVersionTransaction.cpp`](https://github.com/apple/foundationdb/blob/main/fdbclient/MultiVersionTransaction.cpp) | Multi-version client, DLTransaction | diff --git a/fdbclient/ReadYourWrites.actor.cpp b/fdbclient/ReadYourWrites.cpp similarity index 99% rename from fdbclient/ReadYourWrites.actor.cpp rename to fdbclient/ReadYourWrites.cpp index 9b3bb810bd8..945e93cc59d 100644 --- a/fdbclient/ReadYourWrites.actor.cpp +++ b/fdbclient/ReadYourWrites.cpp @@ -1,5 +1,5 @@ /* - * ReadYourWrites.actor.cpp + * ReadYourWrites.cpp * * This source file is part of the FoundationDB open source project *