fix resetStats() bug

This commit is contained in:
Xiaoxi Wang 2022-11-07 13:25:57 -08:00
parent 09f77a785f
commit c4d9a81d95
2 changed files with 12 additions and 6 deletions

View File

@ -123,10 +123,16 @@ Future<Void> updateStorageWiggleMetrics(TxnType tr, StorageWiggleMetrics metrics
return Void();
}
// set all fields except for smoothed durations to default values
// set all fields except for smoothed durations to default values. If the metrics is not given, load from system key
// space
ACTOR template <class TrType>
Future<Void> resetStorageWiggleMetrics(TrType tr, PrimaryRegion primary) {
state Optional<StorageWiggleMetrics> metrics = wait(loadStorageWiggleMetrics(tr, primary));
Future<Void> resetStorageWiggleMetrics(TrType tr,
PrimaryRegion primary,
Optional<StorageWiggleMetrics> metrics = Optional<StorageWiggleMetrics>()) {
if (!metrics.present()) {
wait(store(metrics, loadStorageWiggleMetrics(tr, primary)));
}
if (metrics.present()) {
auto oldStepDuration = metrics.get().smoothed_wiggle_duration;
auto oldRoundDuration = metrics.get().smoothed_round_duration;

View File

@ -183,9 +183,9 @@ Future<Void> StorageWiggler::resetStats() {
newMetrics.smoothed_round_duration = metrics.smoothed_round_duration;
newMetrics.smoothed_wiggle_duration = metrics.smoothed_wiggle_duration;
metrics = newMetrics;
return runRYWTransaction(teamCollection->dbContext(),
[this, &newMetrics](Reference<ReadYourWritesTransaction> tr) -> Future<Void> {
return updateStorageWiggleMetrics(tr, newMetrics, PrimaryRegion(teamCollection->isPrimary()));
return runRYWTransaction(
teamCollection->dbContext(), [this](Reference<ReadYourWritesTransaction> tr) -> Future<Void> {
return resetStorageWiggleMetrics(tr, PrimaryRegion(teamCollection->isPrimary()), metrics);
});
}