/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 | 460k | bool TSDescriptor::IsReadOnlyTS(const ReplicationInfoPB& replication_info) const { |
24 | 460k | const PlacementInfoPB& placement_info = replication_info.live_replicas(); |
25 | 460k | if (placement_info.has_placement_uuid()) { |
26 | 4.96k | return placement_info.placement_uuid() != placement_uuid(); |
27 | 4.96k | } |
28 | 455k | return !placement_uuid().empty(); |
29 | 460k | } |
30 | | |
31 | 460k | bool TSDescriptor::IsAcceptingLeaderLoad(const ReplicationInfoPB& replication_info) const { |
32 | 460k | if (IsReadOnlyTS(replication_info)) { |
33 | | // Read-only ts are not voting and therefore cannot be leaders. |
34 | 2.13k | return false; |
35 | 2.13k | } |
36 | | |
37 | 457k | if (replication_info.affinitized_leaders_size() == 0) { |
38 | | // If there are no affinitized leaders, all ts can be leaders. |
39 | 456k | return true; |
40 | 456k | } |
41 | | |
42 | 1.18k | for (const CloudInfoPB& cloud_info : replication_info.affinitized_leaders())998 { |
43 | 1.18k | if (MatchesCloudInfo(cloud_info)) { |
44 | 290 | return true; |
45 | 290 | } |
46 | 1.18k | } |
47 | 708 | return false; |
48 | 998 | } |
49 | | |
50 | | |
51 | | } // namespace enterprise |
52 | | } // namespace master |
53 | | } // namespace yb |