Remove cx->clearWatchMetadata() when connection file changed
In NativeAPI.actor.cpp, ::watch ACTOR will call cx->clearWatchMetadata() when the connectionFileChanged event is triggered. After that, it will create a new watch metadata for itself. If there are multiple watches, each of them that receives the cnnectionFileChanged will clear *all* watch data and create *one* watch for itself. This does not makes sense. A watch should only clear the metadata, and then create one, for itself. cx->clearWatchMetadata() is only used there, thus removed.
This commit is contained in:
parent
8773564390
commit
a355289d63
|
@ -70,12 +70,10 @@ int32_t DatabaseContext::decreaseWatchRefCount(const int64_t tenantID, KeyRef ke
|
|||
return count;
|
||||
}
|
||||
|
||||
void DatabaseContext::deleteWatchMetadata(int64_t tenantId, KeyRef key) {
|
||||
void DatabaseContext::deleteWatchMetadata(int64_t tenantId, KeyRef key, bool removeReferenceCount) {
|
||||
const WatchMapKey mapKey(tenantId, key);
|
||||
watchMap.erase(mapKey);
|
||||
}
|
||||
|
||||
void DatabaseContext::clearWatchMetadata() {
|
||||
watchMap.clear();
|
||||
watchCounterMap.clear();
|
||||
if (removeReferenceCount) {
|
||||
watchCounterMap.erase(mapKey);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5420,6 +5420,10 @@ ACTOR Future<Void> restartWatch(Database cx,
|
|||
TaskPriority taskID,
|
||||
Optional<UID> debugID,
|
||||
UseProvisionalProxies useProvisionalProxies) {
|
||||
// Remove the reference count as the old watches should be all dropped when switching connectionFile.
|
||||
// The tenantId should be the old one.
|
||||
cx->deleteWatchMetadata(tenantInfo.tenantId, key, /* removeReferenceCount */ true);
|
||||
|
||||
// The ID of the tenant may be different on the cluster that we switched to, so obtain the new ID
|
||||
if (tenantInfo.name.present()) {
|
||||
state KeyRangeLocationInfo locationInfo = wait(getKeyLocation(cx,
|
||||
|
@ -5474,7 +5478,6 @@ ACTOR Future<Void> watch(Reference<Watch> watch,
|
|||
|
||||
when(wait(cx->connectionFileChanged())) {
|
||||
CODE_PROBE(true, "Recreated a watch after switch");
|
||||
cx->clearWatchMetadata();
|
||||
watch->watchFuture = restartWatch(cx,
|
||||
tenantInfo,
|
||||
watch->key,
|
||||
|
|
|
@ -343,7 +343,8 @@ public:
|
|||
void setWatchMetadata(Reference<WatchMetadata> metadata);
|
||||
|
||||
// Removes the watch metadata
|
||||
void deleteWatchMetadata(int64_t tenant, KeyRef key);
|
||||
// If removeReferenceCount is set to be true, the corresponding WatchRefCount record is removed, too.
|
||||
void deleteWatchMetadata(int64_t tenant, KeyRef key, bool removeReferenceCount = false);
|
||||
|
||||
// Increases reference count to the given watch. Returns the number of references to the watch.
|
||||
int32_t increaseWatchRefCount(const int64_t tenant, KeyRef key, const Version& version);
|
||||
|
@ -352,8 +353,6 @@ public:
|
|||
// removed. Returns the number of references to the watch.
|
||||
int32_t decreaseWatchRefCount(const int64_t tenant, KeyRef key, const Version& version);
|
||||
|
||||
void clearWatchMetadata();
|
||||
|
||||
void setOption(FDBDatabaseOptions::Option option, Optional<StringRef> value);
|
||||
|
||||
Error deferredError;
|
||||
|
|
Loading…
Reference in New Issue