How is write visibility ensure in FDB client?

a txn should be able to see the effects of its own updates, however, I cant find any code related to that in NativeAPI.actor.cpp, this set function does nothing but record the mutations and write conflict ranges. So where is this feature implemented in FDB exactly?

void Transaction::set(const KeyRef& key, const ValueRef& value, bool addConflictRange) {
	++cx->transactionSetMutations;
	if (key.size() >
	    (key.startsWith(systemKeys.begin) ? CLIENT_KNOBS->SYSTEM_KEY_SIZE_LIMIT : CLIENT_KNOBS->KEY_SIZE_LIMIT))
		throw key_too_large();
	if (value.size() > CLIENT_KNOBS->VALUE_SIZE_LIMIT)
		throw value_too_large();

	auto& req = tr;
	auto& t = req.transaction;
	auto r = singleKeyRange(key, req.arena);
	auto v = ValueRef(req.arena, value);
	t.mutations.push_back(req.arena, MutationRef(MutationRef::SetValue, r.begin, v));

	if (addConflictRange) {
		t.write_conflict_ranges.push_back(req.arena, r);
	}
}

The Transaction class doesn’t provide this functionality (and if used you won’t see your own writes). This is why we don’t expose it in the bindings. The transaction class exposed (and therefore used by applications) is ReadYourWritesTransaction. You can find the implementation in ReadYourWrites.actor.cpp and the corresponding header file (it wraps a Transaction object and adds a cache on top of it).

1 Like