FastRestoreApplier:Fix conflict range inverted due to invalid memory access

Rerpot error on loader and applier if not error_code_operation_cancelled error ever happens
This commit is contained in:
Meng Xu 2020-09-09 14:40:18 -07:00
parent f10e9ea679
commit 2febbe74ce
2 changed files with 10 additions and 8 deletions

View File

@ -89,9 +89,10 @@ ACTOR Future<Void> restoreApplierCore(RestoreApplierInterface applierInterf, int
break;
}
}
TraceEvent("RestoreApplierCore", self->id()).detail("Request", requestTypeStr); // For debug only
//TraceEvent("RestoreApplierCore", self->id()).detail("Request", requestTypeStr); // For debug only
} catch (Error& e) {
TraceEvent(SevWarn, "FastRestoreApplierError", self->id())
bool isError = e.code() != error_code_operation_cancelled;
TraceEvent(isError ? SevError : SevWarnAlways, "FastRestoreApplierError", self->id())
.detail("RequestType", requestTypeStr)
.error(e, true);
actors.clear(false);
@ -466,7 +467,7 @@ ACTOR static Future<Void> precomputeMutationsResult(Reference<ApplierBatchData>
ACTOR static Future<Void> applyStagingKeysBatch(std::map<Key, StagingKey>::iterator begin,
std::map<Key, StagingKey>::iterator end, Database cx,
FlowLock* applyStagingKeysBatchLock, UID applierID,
ApplierBatchData::Counters* cc) {
ApplierBatchData::Counters* cc, KeyRangeRef range) {
if (SERVER_KNOBS->FASTRESTORE_NOT_WRITE_DB) {
TraceEvent("FastRestoreApplierPhaseApplyStagingKeysBatchSkipped", applierID).detail("Begin", begin->first);
ASSERT(!g_network->isSimulated());
@ -483,7 +484,7 @@ ACTOR static Future<Void> applyStagingKeysBatch(std::map<Key, StagingKey>::itera
try {
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
tr->addWriteConflictRange(KeyRangeRef(begin->first, endKey)); // Reduce resolver load
tr->addWriteConflictRange(range); // Reduce resolver load
std::map<Key, StagingKey>::iterator iter = begin;
while (iter != end) {
if (iter->second.type == MutationRef::SetValue) {
@ -548,7 +549,7 @@ ACTOR static Future<Void> applyStagingKeys(Reference<ApplierBatchData> batchData
txnSize += cur->second.expectedMutationSize();
if (txnSize > SERVER_KNOBS->FASTRESTORE_TXN_BATCH_MAX_BYTES) {
fBatches.push_back(applyStagingKeysBatch(begin, cur, cx, &batchData->applyStagingKeysBatchLock, applierID,
&batchData->counters));
&batchData->counters, KeyRangeRef(begin->first, cur->first)));
batchData->counters.appliedBytes += txnSize;
batchData->appliedBytes += txnSize;
begin = cur;
@ -558,8 +559,9 @@ ACTOR static Future<Void> applyStagingKeys(Reference<ApplierBatchData> batchData
cur++;
}
if (begin != batchData->stagingKeys.end()) {
KeyRangeRef range(begin->first, keyAfter(batchData->stagingKeys.rbegin()->first));
fBatches.push_back(applyStagingKeysBatch(begin, cur, cx, &batchData->applyStagingKeysBatchLock, applierID,
&batchData->counters));
&batchData->counters, range));
batchData->counters.appliedBytes += txnSize;
batchData->appliedBytes += txnSize;
txnBatches++;

View File

@ -282,8 +282,8 @@ ACTOR Future<Void> restoreLoaderCore(RestoreLoaderInterface loaderInterf, int no
when(wait(error)) { TraceEvent("FastRestoreLoaderActorCollectionError", self->id()); }
}
} catch (Error& e) {
TraceEvent(e.code() == error_code_broken_promise ? SevError : SevWarnAlways, "FastRestoreLoaderError",
self->id())
bool isError = e.code() != error_code_operation_cancelled; // == error_code_broken_promise
TraceEvent(isError ? SevError : SevWarnAlways, "FastRestoreLoaderError", self->id())
.detail("RequestType", requestTypeStr)
.error(e, true);
actors.clear(false);