Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion design/AI-generated/foundationdb_subsystem_map.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

---

Expand Down
2 changes: 1 addition & 1 deletion design/AI-generated/subsystem_03_client_library.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
90 changes: 28 additions & 62 deletions fdbclient/ReadYourWrites.actor.cpp → fdbclient/ReadYourWrites.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* ReadYourWrites.actor.cpp
* ReadYourWrites.cpp
*
* This source file is part of the FoundationDB open source project
*
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -351,48 +350,31 @@ class RYWImpl {
}
}

ACTOR template <class Req>
template <class Req>
static Future<typename Req::Result> 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 <class Req>

template <class Req>
static Future<typename Req::Result> 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 <class Req>

template <class Req>
static Future<typename Req::Result> 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 <class Req>
static inline Future<typename Req::Result> readWithConflictRange(ReadYourWritesTransaction* ryw,
Expand Down Expand Up @@ -1194,23 +1176,18 @@ class RYWImpl {
}

// For Snapshot::True and NOT readYourWritesDisabled.
ACTOR template <bool backwards>
template <bool backwards>
static Future<MappedRangeResult> readWithConflictRangeRYW(ReadYourWritesTransaction* ryw,
GetMappedRangeReq<backwards> 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<backwards>(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<backwards>(ryw, req, writes, result);
co_return result;
}

template <bool backwards>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand All @@ -1532,16 +1506,8 @@ class RYWImpl {
}
}

ACTOR static Future<Version> getReadVersion(ReadYourWritesTransaction* ryw) {
choose {
when(Version v = wait(ryw->tr.getReadVersion())) {
return v;
}

when(wait(ryw->resetPromise.getFuture())) {
throw internal_error();
}
}
static Future<Version> getReadVersion(ReadYourWritesTransaction* ryw) {
co_return co_await waitOrError(ryw->tr.getReadVersion(), ryw->resetPromise.getFuture());
}
};

Expand Down
Loading