/Users/deen/code/yugabyte-db/ent/src/yb/master/ts_descriptor.cc
Line | Count | Source |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | |
13 | | #include "yb/master/ts_descriptor.h" |
14 | | |
15 | | #include "yb/master/catalog_entity_info.pb.h" |
16 | | |
17 | | using std::set; |
18 | | |
19 | | namespace yb { |
20 | | namespace master { |
21 | | namespace enterprise { |
22 | | |
23 | 274k | bool TSDescriptor::IsReadOnlyTS(const ReplicationInfoPB& replication_info) const { |
24 | 274k | const PlacementInfoPB& placement_info = replication_info.live_replicas(); |
25 | 274k | if (placement_info.has_placement_uuid()) { |
26 | 3.25k | return placement_info.placement_uuid() != placement_uuid(); |
27 | 3.25k | } |
28 | 271k | return !placement_uuid().empty(); |
29 | 271k | } |
30 | | |
31 | 274k | bool TSDescriptor::IsAcceptingLeaderLoad(const ReplicationInfoPB& replication_info) const { |
32 | 274k | if (IsReadOnlyTS(replication_info)) { |
33 | | // Read-only ts are not voting and therefore cannot be leaders. |
34 | 1.42k | return false; |
35 | 1.42k | } |
36 | | |
37 | 273k | if (replication_info.affinitized_leaders_size() == 0) { |
38 | | // If there are no affinitized leaders, all ts can be leaders. |
39 | 272k | return true; |
40 | 272k | } |
41 | | |
42 | 850 | for (const CloudInfoPB& cloud_info : replication_info.affinitized_leaders()) { |
43 | 850 | if (MatchesCloudInfo(cloud_info)) { |
44 | 258 | return true; |
45 | 258 | } |
46 | 850 | } |
47 | 436 | return false; |
48 | 694 | } |
49 | | |
50 | | |
51 | | } // namespace enterprise |
52 | | } // namespace master |
53 | | } // namespace yb |