Fix tenant map update race when applying mutations (#10557)

This commit is contained in:
Hui Liu 2023-06-27 10:31:58 -07:00 committed by GitHub
parent 321b77d809
commit 788f3420c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 4 deletions

View File

@ -715,7 +715,8 @@ ACTOR Future<Void> sendCommitTransactionRequest(CommitTransactionRequest req,
int* mutationSize,
PromiseStream<Future<Void>> addActor,
FlowLock* commitLock,
PublicRequestStream<CommitTransactionRequest> commit) {
PublicRequestStream<CommitTransactionRequest> commit,
bool tenantMapChanging) {
Key applyBegin = uid.withPrefix(applyMutationsBeginRange.begin);
Key versionKey = BinaryWriter::toValue(newBeginVersion, Unversioned());
Key rangeEnd = getApplyKey(newBeginVersion, uid);
@ -737,7 +738,14 @@ ACTOR Future<Void> sendCommitTransactionRequest(CommitTransactionRequest req,
*totalBytes += *mutationSize;
wait(commitLock->take(TaskPriority::DefaultYield, *mutationSize));
addActor.send(commitLock->releaseWhen(success(commit.getReply(req)), *mutationSize));
Future<Void> commitAndUnlock = commitLock->releaseWhen(success(commit.getReply(req)), *mutationSize);
if (tenantMapChanging) {
// If tenant map is changing, we need to wait until it's committed before processing next mutations.
// Next muations need the updated tenant map for filtering.
wait(commitAndUnlock);
} else {
addActor.send(commitAndUnlock);
}
return Void();
}
@ -814,7 +822,8 @@ ACTOR Future<int> kvMutationLogToTransactions(Database cx,
&mutationSize,
addActor,
commitLock,
commit));
commit,
false));
req = CommitTransactionRequest();
mutationSize = 0;
}
@ -857,7 +866,8 @@ ACTOR Future<int> kvMutationLogToTransactions(Database cx,
&mutationSize,
addActor,
commitLock,
commit));
commit,
tenantMapChanging));
if (endOfStream) {
return totalBytes;
}