Skip to content

Commit

Permalink
[yugabyte#6571] Handle read replicas when checking counts in GetTable…
Browse files Browse the repository at this point in the history
…tLocations

Summary:
When read replicas are present, the warning in GetTabletLocations triggers because it
doesn't take read replicas into account. Add the read replica count so the false positive
disappears.

Additionally, GetExpectedNumberOfReplicas has a typo when fetching read replicas
so only the last read replica placement info is taken into account. Fixed here as well!

Test Plan:
Couldn't figure out how to test this locally, so I modified
`MasterFailoverTest.TestFailoverWithReadReplicas` to call GetTabletLocations, and manually checked
the result.

Reviewers: rahuldesirazu

Reviewed By: rahuldesirazu

Subscribers: ybase, bogdan

Differential Revision: https://phabricator.dev.yugabyte.com/D10565
  • Loading branch information
zhaoalex authored and Alex Ball committed Mar 9, 2021
1 parent 3e5cab7 commit d2a0d22
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/yb/master/catalog_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8708,15 +8708,18 @@ Status CatalogManager::GetReplicationFactorForTablet(const scoped_refptr<TabletI
*num_replicas = master_consensus.config().peers().size();
return Status::OK();
}
return GetReplicationFactor(num_replicas);
int num_live_replicas = 0, num_read_replicas = 0;
GetExpectedNumberOfReplicas(&num_live_replicas, &num_read_replicas);
*num_replicas = num_live_replicas + num_read_replicas;
return Status::OK();
}

void CatalogManager::GetExpectedNumberOfReplicas(int* num_live_replicas, int* num_read_replicas) {
auto l = cluster_config_->LockForRead();
const ReplicationInfoPB& replication_info = l->data().pb.replication_info();
*num_live_replicas = GetNumReplicasFromPlacementInfo(replication_info.live_replicas());
for (const auto& read_replica_placement_info : replication_info.read_replicas()) {
*num_read_replicas = read_replica_placement_info.num_replicas();
*num_read_replicas += read_replica_placement_info.num_replicas();
}
}

Expand Down

0 comments on commit d2a0d22

Please sign in to comment.