From 58dad5373b246db20435945a88a8265cc3ec6971 Mon Sep 17 00:00:00 2001 From: Meng Xu Date: Thu, 13 Feb 2020 11:06:20 -0800 Subject: [PATCH] FastRestore:Applier:Handle CompareAndClear atomicOp --- fdbserver/RestoreApplier.actor.cpp | 9 ++++----- fdbserver/RestoreApplier.actor.h | 11 +++++++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/fdbserver/RestoreApplier.actor.cpp b/fdbserver/RestoreApplier.actor.cpp index adb1f67800..1fa8787531 100644 --- a/fdbserver/RestoreApplier.actor.cpp +++ b/fdbserver/RestoreApplier.actor.cpp @@ -778,14 +778,15 @@ ACTOR static Future handleApplyToDBRequest(RestoreVersionBatchRequest req, return Void(); } -// Copy from WriteDuringRead.actor.cpp +// Copy from WriteDuringRead.actor.cpp with small modifications +// Not all AtomicOps are handled in this function: SetVersionstampedKey, SetVersionstampedValue, Value applyAtomicOp(Optional existingValue, Value value, MutationRef::Type type) { Arena arena; if (type == MutationRef::AddValue) return doLittleEndianAdd(existingValue, value, arena); else if (type == MutationRef::AppendIfFits) return doAppendIfFits(existingValue, value, arena); - else if (type == MutationRef::And) + else if (type == MutationRef::And || type == MutationRef::AndV2) return doAndV2(existingValue, value, arena); else if (type == MutationRef::Or) return doOr(existingValue, value, arena); @@ -793,14 +794,12 @@ Value applyAtomicOp(Optional existingValue, Value value, MutationRef: return doXor(existingValue, value, arena); else if (type == MutationRef::Max) return doMax(existingValue, value, arena); - else if (type == MutationRef::Min) + else if (type == MutationRef::Min || type == MutationRef::MinV2) return doMinV2(existingValue, value, arena); else if (type == MutationRef::ByteMin) return doByteMin(existingValue, value, arena); else if (type == MutationRef::ByteMax) return doByteMax(existingValue, value, arena); - else if (type == MutationRef::CompareAndClear) - return doCompareAndClear(existingValue, value, arena); else { TraceEvent(SevError, "ApplyAtomicOpUnhandledType").detail("TypeCode", (int) type).detail("TypeName", typeString[type]); ASSERT(false); diff --git a/fdbserver/RestoreApplier.actor.h b/fdbserver/RestoreApplier.actor.h index 32d67a171c..e83f3298d2 100644 --- a/fdbserver/RestoreApplier.actor.h +++ b/fdbserver/RestoreApplier.actor.h @@ -116,9 +116,17 @@ struct StagingKey { continue; } for (auto& mutation : lb->second) { - if (isAtomicOp((MutationRef::Type) mutation.type)) { + if (type == MutationRef::CompareAndClear) { // Special atomicOp + Optional retVal = doCompareAndClear(existingValue, value, arena); + if (!retVal.present()) { + val = key; + type = MutationRef::ClearRange; + } // else no-op + } else if (isAtomicOp((MutationRef::Type) mutation.type)) { val = applyAtomicOp(val, mutation.param2, (MutationRef::Type)mutation.type); + type = MutationRef::SetValue; // Precomputed result should be set to DB. } else if (mutation.type == MutationRef::SetValue || mutation.type == MutationRef::ClearRange) { + type = MutationRef::SetValue; // Precomputed result should be set to DB. TraceEvent(SevError, "FastRestoreApplierPrecomputeResultUnexpectedSet") .detail("Type", typeString[mutation.type]) .detail("Version", lb->first); @@ -129,7 +137,6 @@ struct StagingKey { } } version = lb->first; - type = MutationRef::SetValue; // Precomputed result should be set to DB. } }