@@ -1970,11 +1970,11 @@ vector<facade::Listener*> ServerFamily::GetNonPriviligedListeners() const {
1970
1970
}
1971
1971
1972
1972
optional<Replica::Summary> ServerFamily::GetReplicaSummary () const {
1973
- util::fb2::LockGuard lk (replicaof_mu_);
1974
- if (replica_ == nullptr ) {
1973
+ if (tl_replica == nullptr ) {
1975
1974
return nullopt ;
1976
1975
} else {
1977
- return replica_->GetSummary ();
1976
+ auto replica = tl_replica;
1977
+ return replica->GetSummary ();
1978
1978
}
1979
1979
}
1980
1980
@@ -3095,15 +3095,12 @@ string ServerFamily::FormatInfoMetrics(const Metrics& m, std::string_view sectio
3095
3095
3096
3096
auto add_repl_info = [&] {
3097
3097
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
+
3107
3104
if (is_master) {
3108
3105
vector<ReplicaRoleInfo> replicas_info = dfly_cmd_->GetReplicasRoleInfo ();
3109
3106
append (" role" , " master" );
@@ -3137,13 +3134,9 @@ string ServerFamily::FormatInfoMetrics(const Metrics& m, std::string_view sectio
3137
3134
append (" psync_attempts" , rinfo.psync_attempts );
3138
3135
append (" psync_successes" , rinfo.psync_successes );
3139
3136
};
3140
- // Deep copy because tl_replica might be overwritten inbetween
3141
- auto replica = tl_replica;
3142
3137
3143
3138
replication_info_cb (replica->GetSummary ());
3144
3139
3145
- // Deep copy because tl_cluster_replicas might be overwritten inbetween
3146
- auto cluster_replicas = tl_cluster_replicas;
3147
3140
// Special case, when multiple masters replicate to a single replica.
3148
3141
for (const auto & replica : cluster_replicas) {
3149
3142
replication_info_cb (replica->GetSummary ());
@@ -3721,12 +3714,11 @@ void ServerFamily::ReplConf(CmdArgList args, const CommandContext& cmd_cntx) {
3721
3714
3722
3715
void ServerFamily::Role (CmdArgList args, const CommandContext& cmd_cntx) {
3723
3716
auto * rb = static_cast <RedisReplyBuilder*>(cmd_cntx.rb );
3724
- util::fb2::LockGuard lk (replicaof_mu_);
3725
3717
// Thread local var is_master is updated under mutex replicaof_mu_ together with replica_,
3726
3718
// ensuring eventual consistency of is_master. When determining if the server is a replica and
3727
3719
// accessing the replica_ object, we must lock replicaof_mu_. Using is_master alone is
3728
3720
// insufficient in this scenario.
3729
- if (!replica_ ) {
3721
+ if (!tl_replica ) {
3730
3722
rb->StartArray (2 );
3731
3723
rb->SendBulkString (" master" );
3732
3724
auto vec = dfly_cmd_->GetReplicasRoleInfo ();
@@ -3739,6 +3731,10 @@ void ServerFamily::Role(CmdArgList args, const CommandContext& cmd_cntx) {
3739
3731
}
3740
3732
3741
3733
} else {
3734
+ // Deep copy because tl_replica might be overwritten inbetween
3735
+ auto replica = tl_replica;
3736
+ auto cluster_replicas = tl_cluster_replicas;
3737
+
3742
3738
rb->StartArray (4 + cluster_replicas_.size () * 3 );
3743
3739
rb->SendBulkString (GetFlag (FLAGS_info_replication_valkey_compatible) ? " slave" : " replica" );
3744
3740
@@ -3756,9 +3752,9 @@ void ServerFamily::Role(CmdArgList args, const CommandContext& cmd_cntx) {
3756
3752
rb->SendBulkString (" connecting" );
3757
3753
}
3758
3754
};
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 ());
3762
3758
}
3763
3759
}
3764
3760
}
0 commit comments