diff --git a/fdbclient/include/fdbclient/KeyBackedTypes.h b/fdbclient/include/fdbclient/KeyBackedTypes.h index cf8181a71f..dab88afe07 100644 --- a/fdbclient/include/fdbclient/KeyBackedTypes.h +++ b/fdbclient/include/fdbclient/KeyBackedTypes.h @@ -435,6 +435,30 @@ public: tr->clear(subspace); } + template + void addReadConflictKey(Transaction tr, KeyType const& key) { + Key k = subspace.begin.withSuffix(KeyCodec::pack(key)); + tr->addReadConflictRange(singleKeyRange(k)); + } + + template + void addReadConflictRange(Transaction tr, KeyType const& begin, KeyType const& end) { + tr->addReadConflictRange(subspace.begin.withSuffix(KeyCodec::pack(begin)), + subspace.begin.withSuffix(KeyCodec::pack(end))); + } + + template + void addWriteConflictKey(Transaction tr, KeyType const& key) { + Key k = subspace.begin.withSuffix(KeyCodec::pack(key)); + tr->addWriteConflictRange(singleKeyRange(k)); + } + + template + void addWriteConflictRange(Transaction tr, KeyType const& begin, KeyType const& end) { + tr->addWriteConflictRange(subspace.begin.withSuffix(KeyCodec::pack(begin)), + subspace.begin.withSuffix(KeyCodec::pack(end))); + } + KeyRange subspace; }; diff --git a/fdbclient/include/fdbclient/MetaclusterManagement.actor.h b/fdbclient/include/fdbclient/MetaclusterManagement.actor.h index 69f1fbcc6f..a35cf89b28 100644 --- a/fdbclient/include/fdbclient/MetaclusterManagement.actor.h +++ b/fdbclient/include/fdbclient/MetaclusterManagement.actor.h @@ -1409,6 +1409,7 @@ struct RestoreClusterImpl { } else if (transactionId.get() != self->restoreId) { throw conflicting_restore(); } else { + MetaclusterMetadata::activeRestoreIds().addReadConflictKey(tr, self->clusterName); MetaclusterMetadata::activeRestoreIds().erase(tr, self->clusterName); } @@ -1504,6 +1505,7 @@ struct RestoreClusterImpl { TraceEvent("RestoredClusterAlreadyExists").detail("ClusterName", self->clusterName); throw cluster_already_exists(); } else if (!self->restoreDryRun) { + MetaclusterMetadata::activeRestoreIds().addReadConflictKey(tr, self->clusterName); MetaclusterMetadata::activeRestoreIds().set(tr, self->clusterName, self->restoreId); ManagementClusterMetadata::dataClusters().set(tr, self->clusterName, clusterEntry); @@ -1558,6 +1560,7 @@ struct RestoreClusterImpl { if (!self->restoreDryRun) { MetaclusterMetadata::metaclusterRegistration().set(tr, dataClusterEntry); + MetaclusterMetadata::activeRestoreIds().addReadConflictKey(tr, self->clusterName); MetaclusterMetadata::activeRestoreIds().set(tr, self->clusterName, self->restoreId); wait(buggifiedCommit(tr, BUGGIFY_WITH_PROB(0.1))); } @@ -1572,6 +1575,7 @@ struct RestoreClusterImpl { } void markClusterRestoring(Reference tr) { + MetaclusterMetadata::activeRestoreIds().addReadConflictKey(tr, clusterName); MetaclusterMetadata::activeRestoreIds().set(tr, clusterName, restoreId); if (ctx.dataClusterMetadata.get().entry.clusterState != DataClusterState::RESTORING) { DataClusterEntry updatedEntry = ctx.dataClusterMetadata.get().entry;