@@ -1970,11 +1970,11 @@ vector<facade::Listener*> ServerFamily::GetNonPriviligedListeners() const {
19701970}
19711971
19721972optional<Replica::Summary> ServerFamily::GetReplicaSummary () const {
1973- util::fb2::LockGuard lk (replicaof_mu_);
1974- if (replica_ == nullptr ) {
1973+ if (tl_replica == nullptr ) {
19751974 return nullopt ;
19761975 } else {
1977- return replica_->GetSummary ();
1976+ auto replica = tl_replica;
1977+ return replica->GetSummary ();
19781978 }
19791979}
19801980
@@ -3095,15 +3095,12 @@ string ServerFamily::FormatInfoMetrics(const Metrics& m, std::string_view sectio
30953095
30963096 auto add_repl_info = [&] {
30973097 bool is_master = true ;
3098- // Thread local var is_master is updated under mutex replicaof_mu_ together with replica_,
3099- // ensuring eventual consistency of is_master. When determining if the server is a replica and
3100- // accessing the replica_ object, we must lock replicaof_mu_. Using is_master alone is
3101- // insufficient in this scenario.
3102- // Please note that we we do not use Metrics object here.
3103- {
3104- fb2::LockGuard lk (replicaof_mu_);
3105- is_master = !replica_;
3106- }
3098+
3099+ // Deep copy because tl_replica might be overwritten inbetween
3100+ auto replica = tl_replica;
3101+ auto cluster_replicas = tl_cluster_replicas;
3102+ is_master = !replica;
3103+
31073104 if (is_master) {
31083105 vector<ReplicaRoleInfo> replicas_info = dfly_cmd_->GetReplicasRoleInfo ();
31093106 append (" role" , " master" );
@@ -3137,13 +3134,9 @@ string ServerFamily::FormatInfoMetrics(const Metrics& m, std::string_view sectio
31373134 append (" psync_attempts" , rinfo.psync_attempts );
31383135 append (" psync_successes" , rinfo.psync_successes );
31393136 };
3140- // Deep copy because tl_replica might be overwritten inbetween
3141- auto replica = tl_replica;
31423137
31433138 replication_info_cb (replica->GetSummary ());
31443139
3145- // Deep copy because tl_cluster_replicas might be overwritten inbetween
3146- auto cluster_replicas = tl_cluster_replicas;
31473140 // Special case, when multiple masters replicate to a single replica.
31483141 for (const auto & replica : cluster_replicas) {
31493142 replication_info_cb (replica->GetSummary ());
@@ -3721,12 +3714,11 @@ void ServerFamily::ReplConf(CmdArgList args, const CommandContext& cmd_cntx) {
37213714
37223715void ServerFamily::Role (CmdArgList args, const CommandContext& cmd_cntx) {
37233716 auto * rb = static_cast <RedisReplyBuilder*>(cmd_cntx.rb );
3724- util::fb2::LockGuard lk (replicaof_mu_);
37253717 // Thread local var is_master is updated under mutex replicaof_mu_ together with replica_,
37263718 // ensuring eventual consistency of is_master. When determining if the server is a replica and
37273719 // accessing the replica_ object, we must lock replicaof_mu_. Using is_master alone is
37283720 // insufficient in this scenario.
3729- if (!replica_ ) {
3721+ if (!tl_replica ) {
37303722 rb->StartArray (2 );
37313723 rb->SendBulkString (" master" );
37323724 auto vec = dfly_cmd_->GetReplicasRoleInfo ();
@@ -3739,6 +3731,10 @@ void ServerFamily::Role(CmdArgList args, const CommandContext& cmd_cntx) {
37393731 }
37403732
37413733 } else {
3734+ // Deep copy because tl_replica might be overwritten inbetween
3735+ auto replica = tl_replica;
3736+ auto cluster_replicas = tl_cluster_replicas;
3737+
37423738 rb->StartArray (4 + cluster_replicas_.size () * 3 );
37433739 rb->SendBulkString (GetFlag (FLAGS_info_replication_valkey_compatible) ? " slave" : " replica" );
37443740
@@ -3756,9 +3752,9 @@ void ServerFamily::Role(CmdArgList args, const CommandContext& cmd_cntx) {
37563752 rb->SendBulkString (" connecting" );
37573753 }
37583754 };
3759- send_replica_info (replica_ ->GetSummary ());
3760- for (const auto & replica : cluster_replicas_ ) {
3761- send_replica_info (replica ->GetSummary ());
3755+ send_replica_info (replica ->GetSummary ());
3756+ for (const auto & repl : cluster_replicas ) {
3757+ send_replica_info (repl ->GetSummary ());
37623758 }
37633759 }
37643760}
0 commit comments