Skip to content

Commit

Permalink
[#22376] xCluster: Acquire locks in correct order when handling AutoF…
Browse files Browse the repository at this point in the history
…lagsConfigChange

Summary:
`HandleLocalAutoFlagsConfigChange` and `RefreshAutoFlagConfigVersion` take the ClusterConfig write lock before ReplicationInfo write lock. Whereas `AddCDCStreamToUniverseAndInitConsumer` take the locks in the other order causing a deadlock of setup replication.

Fixed the lock order in `HandleLocalAutoFlagsConfigChange` and `RefreshAutoFlagConfigVersion`.
Jira: DB-11277

Test Plan: Jenkins

Reviewers: slingam, jhe, xCluster, asrivastava

Reviewed By: asrivastava

Subscribers: ybase

Differential Revision: https://phorge.dev.yugabyte.com/D35072
  • Loading branch information
hari90 committed May 15, 2024
1 parent 401ab5f commit d9deed4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/yb/master/xcluster/xcluster_replication_group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ Status RefreshAutoFlagConfigVersion(
<< replication_info.ReplicationGroupId()
<< " with requested source config version: " << requested_auto_flag_version;

// Lock ClusterConfig before ReplicationInfo.
// Lock ReplicationInfo before ClusterConfig.
auto replication_info_write_lock = replication_info.LockForWrite();

auto cluster_config_lock = cluster_config.LockForWrite();
auto& cluster_config_pb = cluster_config_lock.mutable_data()->pb;

Expand All @@ -197,7 +199,6 @@ Status RefreshAutoFlagConfigVersion(
return Status::OK();
}

auto replication_info_write_lock = replication_info.LockForWrite();
auto& replication_info_pb = replication_info_write_lock.mutable_data()->pb;

const auto local_auto_flags_config = get_local_auto_flags_config_func();
Expand Down Expand Up @@ -230,11 +231,11 @@ Status HandleLocalAutoFlagsConfigChange(
}
}

// Lock ClusterConfig before ReplicationInfo.
// Lock ReplicationInfo before ClusterConfig.
auto replication_info_write_lock = replication_info.LockForWrite();
auto cluster_config_lock = cluster_config.LockForWrite();
auto& cluster_config_pb = cluster_config_lock.mutable_data()->pb;

auto replication_info_write_lock = replication_info.LockForWrite();
auto& cluster_config_pb = cluster_config_lock.mutable_data()->pb;
auto& replication_info_pb = replication_info_write_lock.mutable_data()->pb;

RETURN_NOT_OK(ValidateAutoFlagsInternal(
Expand Down

0 comments on commit d9deed4

Please sign in to comment.