diff --git a/fdbclient/Knobs.cpp b/fdbclient/Knobs.cpp index 1961f10bd2..ad3c996476 100644 --- a/fdbclient/Knobs.cpp +++ b/fdbclient/Knobs.cpp @@ -231,6 +231,7 @@ void ClientKnobs::initialize(bool randomize) { init( TAG_THROTTLE_SMOOTHING_WINDOW, 2.0 ); init( TAG_THROTTLE_RECHECK_INTERVAL, 5.0 ); if( randomize && BUGGIFY ) TAG_THROTTLE_RECHECK_INTERVAL = 0.0; init( TAG_THROTTLE_EXPIRATION_INTERVAL, 60.0 ); if( randomize && BUGGIFY ) TAG_THROTTLE_EXPIRATION_INTERVAL = 1.0; + // clang-format on } diff --git a/fdbclient/NativeAPI.actor.cpp b/fdbclient/NativeAPI.actor.cpp index ed539182af..538a46e17a 100644 --- a/fdbclient/NativeAPI.actor.cpp +++ b/fdbclient/NativeAPI.actor.cpp @@ -3257,10 +3257,12 @@ void Transaction::setupWatches() { } } -ACTOR Future estimateCommitCosts(Transaction* self, CommitTransactionRef* transaction) { +ACTOR Future estimateCommitCosts(Transaction* self, + CommitTransactionRef* transaction) { state MutationRef* it = transaction->mutations.begin(); state MutationRef* end = transaction->mutations.end(); state TransactionCommitCostEstimation trCommitCosts; + state KeyRange keyRange; for (; it != end; ++it) { if (it->type == MutationRef::Type::SetValue) { trCommitCosts.bytesWrite += it->expectedSize(); @@ -3269,16 +3271,21 @@ ACTOR Future estimateCommitCosts(Transaction* s trCommitCosts.bytesAtomicWrite += it->expectedSize(); trCommitCosts.numAtomicWrite++; } else if (it->type == MutationRef::Type::ClearRange) { - trCommitCosts.numClear ++; - if(self->options.expensiveClearCostEstimation) { + trCommitCosts.numClear++; + keyRange = KeyRange(KeyRangeRef(it->param1, it->param2)); + if (self->options.expensiveClearCostEstimation) { try { - StorageMetrics m = wait(self->getStorageMetrics(KeyRangeRef(it->param1, it->param2), -1)); - trCommitCosts.bytesClearEst += m.bytes; + StorageMetrics m = wait(self->getStorageMetrics(keyRange, INT_MAX)); + trCommitCosts.bytesClearEst.present() ? (trCommitCosts.bytesClearEst.get() += m.bytes) + : (trCommitCosts.bytesClearEst = m.bytes); continue; - } catch (...) {} // do a local estimation + } catch (...) { + } // do a local estimation } - // TODO how much data a clear would delete: 1. shard-map - + std::vector>> locations = wait(getKeyRangeLocations( + self->getDatabase(), keyRange, INT_MAX, false, &StorageServerInterface::getShardState, self->info)); + trCommitCosts.numClearShards.present() ? (trCommitCosts.numClearShards.get() += locations.size()) + : (trCommitCosts.numClearShards = locations.size()); } } return trCommitCosts; @@ -3305,11 +3312,8 @@ ACTOR static Future tryCommit( Database cx, Reference req.transaction.read_snapshot = v; } else { - Version v; - TransactionCommitCostEstimation costEst; - wait(store(v, readVersion) && store(costEst, estimateCommitCosts(tr, &req.transaction))); - req.transaction.read_snapshot = v; - req.commitCostEstimation = costEst; // estimateCommitCosts(tr, &req.transaction, false); + req.commitCostEstimation = TransactionCommitCostEstimation(); + wait(store(req.transaction.read_snapshot, readVersion) && store(req.commitCostEstimation.get(), estimateCommitCosts(tr, &req.transaction))); } startTime = now(); @@ -3732,15 +3736,17 @@ void Transaction::setOption( FDBTransactionOptions::Option option, Optional(value.get(), Unversioned())); break; - case FDBTransactionOptions::REPORT_CONFLICTING_KEYS: - validateOptionValue(value, false); - options.reportConflictingKeys = true; - break; + case FDBTransactionOptions::REPORT_CONFLICTING_KEYS: + validateOptionValue(value, false); + options.reportConflictingKeys = true; + break; + case FDBTransactionOptions::EXPENSIVE_CLEAR_COST_ESTIMATION_ENABLE: validateOptionValue(value, false); options.expensiveClearCostEstimation = true; break; - default: + + default: break; } } diff --git a/fdbserver/Ratekeeper.actor.cpp b/fdbserver/Ratekeeper.actor.cpp index 748d838695..80d2be3f9b 100644 --- a/fdbserver/Ratekeeper.actor.cpp +++ b/fdbserver/Ratekeeper.actor.cpp @@ -1291,7 +1291,8 @@ ACTOR Future ratekeeper(RatekeeperInterface rkInterf, Reference 0) { diff --git a/fdbserver/RatekeeperInterface.h b/fdbserver/RatekeeperInterface.h index f3b83f0a87..84da5d413c 100644 --- a/fdbserver/RatekeeperInterface.h +++ b/fdbserver/RatekeeperInterface.h @@ -80,21 +80,25 @@ struct TransactionCommitCostEstimation { int64_t numAtomicWrite = 0; int64_t numClear = 0; unsigned long bytesWrite = 0; - unsigned long bytesClearEst = 0; unsigned long bytesAtomicWrite = 0; + Optional numClearShards; + Optional bytesClearEst; template void serialize(Ar& ar) { - serializer(ar, bytesWrite, bytesClearEst, bytesAtomicWrite, numWrite, numAtomicWrite, numClear); + serializer(ar, bytesWrite, bytesClearEst, bytesAtomicWrite, numWrite, numAtomicWrite, numClear, numClearShards); } - TransactionCommitCostEstimation& operator += (const TransactionCommitCostEstimation& other) { + TransactionCommitCostEstimation& operator+=(const TransactionCommitCostEstimation& other) { numWrite += other.numWrite; numAtomicWrite += other.numAtomicWrite; numClear += other.numClear; bytesWrite += other.bytesWrite; - bytesClearEst += other.bytesClearEst; bytesAtomicWrite += other.numAtomicWrite; + if (other.bytesClearEst.present() || bytesClearEst.present()) + bytesClearEst = bytesClearEst.orDefault(0) + other.bytesClearEst.orDefault(0); + if (other.numClearShards.present() || numClearShards.present()) + numClearShards = numClearShards.orDefault(0) + other.numClearShards.orDefault(0); return *this; } };