/Users/deen/code/yugabyte-db/src/yb/master/catalog_entity_info.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | // |
18 | | // The following only applies to changes made to this file as part of YugaByte development. |
19 | | // |
20 | | // Portions Copyright (c) YugaByte, Inc. |
21 | | // |
22 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
23 | | // in compliance with the License. You may obtain a copy of the License at |
24 | | // |
25 | | // http://www.apache.org/licenses/LICENSE-2.0 |
26 | | // |
27 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
28 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
29 | | // or implied. See the License for the specific language governing permissions and limitations |
30 | | // under the License. |
31 | | // |
32 | | |
33 | | #ifndef YB_MASTER_CATALOG_ENTITY_INFO_H |
34 | | #define YB_MASTER_CATALOG_ENTITY_INFO_H |
35 | | |
36 | | #include <shared_mutex> |
37 | | #include <mutex> |
38 | | #include <vector> |
39 | | |
40 | | #include "yb/common/entity_ids.h" |
41 | | #include "yb/common/index.h" |
42 | | |
43 | | #include "yb/master/master_client.fwd.h" |
44 | | #include "yb/master/master_fwd.h" |
45 | | #include "yb/master/catalog_entity_info.pb.h" |
46 | | #include "yb/master/tasks_tracker.h" |
47 | | |
48 | | #include "yb/server/monitored_task.h" |
49 | | |
50 | | #include "yb/tablet/metadata.pb.h" |
51 | | |
52 | | #include "yb/util/cow_object.h" |
53 | | #include "yb/util/format.h" |
54 | | #include "yb/util/monotime.h" |
55 | | #include "yb/util/status_fwd.h" |
56 | | |
57 | | namespace yb { |
58 | | namespace master { |
59 | | |
60 | | YB_STRONGLY_TYPED_BOOL(DeactivateOnly); |
61 | | |
62 | | // Drive usage information on a current replica of a tablet. |
63 | | // This allows us to look at individual resource usage per replica of a tablet. |
64 | | struct TabletReplicaDriveInfo { |
65 | | uint64 sst_files_size = 0; |
66 | | uint64 wal_files_size = 0; |
67 | | uint64 uncompressed_sst_file_size = 0; |
68 | | bool may_have_orphaned_post_split_data = true; |
69 | | }; |
70 | | |
71 | | // Information on a current replica of a tablet. |
72 | | // This is copyable so that no locking is needed. |
73 | | struct TabletReplica { |
74 | | TSDescriptor* ts_desc; |
75 | | tablet::RaftGroupStatePB state; |
76 | | PeerRole role; |
77 | | consensus::PeerMemberType member_type; |
78 | | MonoTime time_updated; |
79 | | |
80 | | // Replica is reporting that load balancer moves should be disabled. This could happen in the case |
81 | | // where a tablet has just been split and still refers to data from its parent which is no longer |
82 | | // relevant, for example. |
83 | | bool should_disable_lb_move = false; |
84 | | |
85 | | std::string fs_data_dir; |
86 | | |
87 | | TabletReplicaDriveInfo drive_info; |
88 | | |
89 | 379k | TabletReplica() : time_updated(MonoTime::Now()) {} |
90 | | |
91 | | void UpdateFrom(const TabletReplica& source); |
92 | | |
93 | | void UpdateDriveInfo(const TabletReplicaDriveInfo& info); |
94 | | |
95 | | bool IsStale() const; |
96 | | |
97 | | bool IsStarting() const; |
98 | | |
99 | | std::string ToString() const; |
100 | | }; |
101 | | |
102 | | // This class is a base wrapper around the protos that get serialized in the data column of the |
103 | | // sys_catalog. Subclasses of this will provide convenience getter/setter methods around the |
104 | | // protos and instances of these will be wrapped around CowObjects and locks for access and |
105 | | // modifications. |
106 | | template <class DataEntryPB, SysRowEntryType entry_type> |
107 | | struct Persistent { |
108 | | // Type declaration to be used in templated read/write methods. We are using typename |
109 | | // Class::data_type in templated methods for figuring out the type we need. |
110 | | typedef DataEntryPB data_type; |
111 | | |
112 | | // Subclasses of this need to provide a valid value of the entry type through |
113 | | // the template class argument. |
114 | 413k | static SysRowEntryType type() { return entry_type; } _ZN2yb6master10PersistentINS0_16SysTablesEntryPBELNS0_15SysRowEntryTypeE1EE4typeEv Line | Count | Source | 114 | 66.4k | static SysRowEntryType type() { return entry_type; } |
_ZN2yb6master10PersistentINS0_17SysTabletsEntryPBELNS0_15SysRowEntryTypeE2EE4typeEv Line | Count | Source | 114 | 245k | static SysRowEntryType type() { return entry_type; } |
_ZN2yb6master10PersistentINS0_23SysClusterConfigEntryPBELNS0_15SysRowEntryTypeE3EE4typeEv Line | Count | Source | 114 | 9.19k | static SysRowEntryType type() { return entry_type; } |
_ZN2yb6master10PersistentINS0_19SysNamespaceEntryPBELNS0_15SysRowEntryTypeE4EE4typeEv Line | Count | Source | 114 | 18.0k | static SysRowEntryType type() { return entry_type; } |
_ZN2yb6master10PersistentINS0_21SysRedisConfigEntryPBELNS0_15SysRowEntryTypeE8EE4typeEv Line | Count | Source | 114 | 7.13k | static SysRowEntryType type() { return entry_type; } |
_ZN2yb6master10PersistentINS0_16SysConfigEntryPBELNS0_15SysRowEntryTypeE9EE4typeEv Line | Count | Source | 114 | 21.8k | static SysRowEntryType type() { return entry_type; } |
_ZN2yb6master10PersistentINS0_14SysRoleEntryPBELNS0_15SysRowEntryTypeE6EE4typeEv Line | Count | Source | 114 | 13.6k | static SysRowEntryType type() { return entry_type; } |
_ZN2yb6master10PersistentINS0_16SysUDTypeEntryPBELNS0_15SysRowEntryTypeE5EE4typeEv Line | Count | Source | 114 | 7.21k | static SysRowEntryType type() { return entry_type; } |
_ZN2yb6master10PersistentINS0_19SysCDCStreamEntryPBELNS0_15SysRowEntryTypeE10EE4typeEv Line | Count | Source | 114 | 9.81k | static SysRowEntryType type() { return entry_type; } |
_ZN2yb6master10PersistentINS0_29SysUniverseReplicationEntryPBELNS0_15SysRowEntryTypeE11EE4typeEv Line | Count | Source | 114 | 7.12k | static SysRowEntryType type() { return entry_type; } |
_ZN2yb6master10PersistentINS0_18SysSnapshotEntryPBELNS0_15SysRowEntryTypeE7EE4typeEv Line | Count | Source | 114 | 7.11k | static SysRowEntryType type() { return entry_type; } |
|
115 | | |
116 | | // The proto that is persisted in the sys_catalog. |
117 | | DataEntryPB pb; |
118 | | }; |
119 | | |
120 | | // This class is a base wrapper around accessors for the persistent proto data, through CowObject. |
121 | | // The locks are taken on subclasses of this class, around the object returned from metadata(). |
122 | | template <class PersistentDataEntryPB> |
123 | | class MetadataCowWrapper { |
124 | | public: |
125 | | // Type declaration for use in the Lock classes. |
126 | | typedef PersistentDataEntryPB CowState; |
127 | | typedef CowWriteLock<CowState> WriteLock; |
128 | | typedef CowReadLock<CowState> ReadLock; |
129 | | |
130 | | // This method should return the id to be written into the sys_catalog id column. |
131 | | virtual const std::string& id() const = 0; |
132 | | |
133 | | // Pretty printing. |
134 | 740 | virtual std::string ToString() const { |
135 | 740 | return Format( |
136 | 740 | "Object type = $0 (id = $1)", PersistentDataEntryPB::type(), id()); |
137 | 740 | } Unexecuted instantiation: _ZNK2yb6master18MetadataCowWrapperINS0_27PersistentClusterConfigInfoEE8ToStringEv Unexecuted instantiation: _ZNK2yb6master18MetadataCowWrapperINS0_25PersistentRedisConfigInfoEE8ToStringEv Unexecuted instantiation: _ZNK2yb6master18MetadataCowWrapperINS0_23PersistentCDCStreamInfoEE8ToStringEv Unexecuted instantiation: _ZNK2yb6master18MetadataCowWrapperINS0_33PersistentUniverseReplicationInfoEE8ToStringEv Unexecuted instantiation: _ZNK2yb6master18MetadataCowWrapperINS0_22PersistentSnapshotInfoEE8ToStringEv Unexecuted instantiation: _ZNK2yb6master18MetadataCowWrapperINS0_23PersistentNamespaceInfoEE8ToStringEv _ZNK2yb6master18MetadataCowWrapperINS0_23PersistentSysConfigInfoEE8ToStringEv Line | Count | Source | 134 | 10 | virtual std::string ToString() const { | 135 | 10 | return Format( | 136 | 10 | "Object type = $0 (id = $1)", PersistentDataEntryPB::type(), id()); | 137 | 10 | } |
_ZNK2yb6master18MetadataCowWrapperINS0_18PersistentRoleInfoEE8ToStringEv Line | Count | Source | 134 | 730 | virtual std::string ToString() const { | 135 | 730 | return Format( | 136 | 730 | "Object type = $0 (id = $1)", PersistentDataEntryPB::type(), id()); | 137 | 730 | } |
Unexecuted instantiation: _ZNK2yb6master18MetadataCowWrapperINS0_20PersistentUDTypeInfoEE8ToStringEv Unexecuted instantiation: _ZNK2yb6master18MetadataCowWrapperINS0_20PersistentTabletInfoEE8ToStringEv Unexecuted instantiation: _ZNK2yb6master18MetadataCowWrapperINS0_19PersistentTableInfoEE8ToStringEv |
138 | | |
139 | | // Access the persistent metadata. Typically you should use |
140 | | // MetadataLock to gain access to this data. |
141 | 144M | const CowObject<PersistentDataEntryPB>& metadata() const { return metadata_; } _ZNK2yb6master18MetadataCowWrapperINS0_20PersistentTabletInfoEE8metadataEv Line | Count | Source | 141 | 31.6M | const CowObject<PersistentDataEntryPB>& metadata() const { return metadata_; } |
_ZNK2yb6master18MetadataCowWrapperINS0_19PersistentTableInfoEE8metadataEv Line | Count | Source | 141 | 109M | const CowObject<PersistentDataEntryPB>& metadata() const { return metadata_; } |
_ZNK2yb6master18MetadataCowWrapperINS0_27PersistentClusterConfigInfoEE8metadataEv Line | Count | Source | 141 | 1.54M | const CowObject<PersistentDataEntryPB>& metadata() const { return metadata_; } |
_ZNK2yb6master18MetadataCowWrapperINS0_23PersistentNamespaceInfoEE8metadataEv Line | Count | Source | 141 | 1.27M | const CowObject<PersistentDataEntryPB>& metadata() const { return metadata_; } |
_ZNK2yb6master18MetadataCowWrapperINS0_25PersistentRedisConfigInfoEE8metadataEv Line | Count | Source | 141 | 6 | const CowObject<PersistentDataEntryPB>& metadata() const { return metadata_; } |
_ZNK2yb6master18MetadataCowWrapperINS0_23PersistentSysConfigInfoEE8metadataEv Line | Count | Source | 141 | 683k | const CowObject<PersistentDataEntryPB>& metadata() const { return metadata_; } |
_ZNK2yb6master18MetadataCowWrapperINS0_18PersistentRoleInfoEE8metadataEv Line | Count | Source | 141 | 58.4k | const CowObject<PersistentDataEntryPB>& metadata() const { return metadata_; } |
_ZNK2yb6master18MetadataCowWrapperINS0_20PersistentUDTypeInfoEE8metadataEv Line | Count | Source | 141 | 2.89k | const CowObject<PersistentDataEntryPB>& metadata() const { return metadata_; } |
_ZNK2yb6master18MetadataCowWrapperINS0_23PersistentCDCStreamInfoEE8metadataEv Line | Count | Source | 141 | 780 | const CowObject<PersistentDataEntryPB>& metadata() const { return metadata_; } |
_ZNK2yb6master18MetadataCowWrapperINS0_33PersistentUniverseReplicationInfoEE8metadataEv Line | Count | Source | 141 | 4 | const CowObject<PersistentDataEntryPB>& metadata() const { return metadata_; } |
Unexecuted instantiation: _ZNK2yb6master18MetadataCowWrapperINS0_22PersistentSnapshotInfoEE8metadataEv |
142 | 1.56M | CowObject<PersistentDataEntryPB>* mutable_metadata() { return &metadata_; } _ZN2yb6master18MetadataCowWrapperINS0_20PersistentTabletInfoEE16mutable_metadataEv Line | Count | Source | 142 | 655k | CowObject<PersistentDataEntryPB>* mutable_metadata() { return &metadata_; } |
_ZN2yb6master18MetadataCowWrapperINS0_19PersistentTableInfoEE16mutable_metadataEv Line | Count | Source | 142 | 833k | CowObject<PersistentDataEntryPB>* mutable_metadata() { return &metadata_; } |
_ZN2yb6master18MetadataCowWrapperINS0_27PersistentClusterConfigInfoEE16mutable_metadataEv Line | Count | Source | 142 | 2.49k | CowObject<PersistentDataEntryPB>* mutable_metadata() { return &metadata_; } |
_ZN2yb6master18MetadataCowWrapperINS0_23PersistentNamespaceInfoEE16mutable_metadataEv Line | Count | Source | 142 | 20.4k | CowObject<PersistentDataEntryPB>* mutable_metadata() { return &metadata_; } |
_ZN2yb6master18MetadataCowWrapperINS0_20PersistentUDTypeInfoEE16mutable_metadataEv Line | Count | Source | 142 | 182 | CowObject<PersistentDataEntryPB>* mutable_metadata() { return &metadata_; } |
_ZN2yb6master18MetadataCowWrapperINS0_25PersistentRedisConfigInfoEE16mutable_metadataEv Line | Count | Source | 142 | 10 | CowObject<PersistentDataEntryPB>* mutable_metadata() { return &metadata_; } |
_ZN2yb6master18MetadataCowWrapperINS0_23PersistentSysConfigInfoEE16mutable_metadataEv Line | Count | Source | 142 | 16.0k | CowObject<PersistentDataEntryPB>* mutable_metadata() { return &metadata_; } |
_ZN2yb6master18MetadataCowWrapperINS0_18PersistentRoleInfoEE16mutable_metadataEv Line | Count | Source | 142 | 32.2k | CowObject<PersistentDataEntryPB>* mutable_metadata() { return &metadata_; } |
_ZN2yb6master18MetadataCowWrapperINS0_23PersistentCDCStreamInfoEE16mutable_metadataEv Line | Count | Source | 142 | 3.01k | CowObject<PersistentDataEntryPB>* mutable_metadata() { return &metadata_; } |
_ZN2yb6master18MetadataCowWrapperINS0_33PersistentUniverseReplicationInfoEE16mutable_metadataEv Line | Count | Source | 142 | 8 | CowObject<PersistentDataEntryPB>* mutable_metadata() { return &metadata_; } |
Unexecuted instantiation: _ZN2yb6master18MetadataCowWrapperINS0_22PersistentSnapshotInfoEE16mutable_metadataEv |
143 | | |
144 | 144M | ReadLock LockForRead() const { |
145 | 144M | return ReadLock(&metadata()); |
146 | 144M | } _ZNK2yb6master18MetadataCowWrapperINS0_20PersistentTabletInfoEE11LockForReadEv Line | Count | Source | 144 | 30.9M | ReadLock LockForRead() const { | 145 | 30.9M | return ReadLock(&metadata()); | 146 | 30.9M | } |
_ZNK2yb6master18MetadataCowWrapperINS0_19PersistentTableInfoEE11LockForReadEv Line | Count | Source | 144 | 109M | ReadLock LockForRead() const { | 145 | 109M | return ReadLock(&metadata()); | 146 | 109M | } |
_ZNK2yb6master18MetadataCowWrapperINS0_27PersistentClusterConfigInfoEE11LockForReadEv Line | Count | Source | 144 | 1.54M | ReadLock LockForRead() const { | 145 | 1.54M | return ReadLock(&metadata()); | 146 | 1.54M | } |
_ZNK2yb6master18MetadataCowWrapperINS0_23PersistentNamespaceInfoEE11LockForReadEv Line | Count | Source | 144 | 1.27M | ReadLock LockForRead() const { | 145 | 1.27M | return ReadLock(&metadata()); | 146 | 1.27M | } |
_ZNK2yb6master18MetadataCowWrapperINS0_25PersistentRedisConfigInfoEE11LockForReadEv Line | Count | Source | 144 | 6 | ReadLock LockForRead() const { | 145 | 6 | return ReadLock(&metadata()); | 146 | 6 | } |
_ZNK2yb6master18MetadataCowWrapperINS0_23PersistentSysConfigInfoEE11LockForReadEv Line | Count | Source | 144 | 681k | ReadLock LockForRead() const { | 145 | 681k | return ReadLock(&metadata()); | 146 | 681k | } |
_ZNK2yb6master18MetadataCowWrapperINS0_18PersistentRoleInfoEE11LockForReadEv Line | Count | Source | 144 | 58.4k | ReadLock LockForRead() const { | 145 | 58.4k | return ReadLock(&metadata()); | 146 | 58.4k | } |
_ZNK2yb6master18MetadataCowWrapperINS0_20PersistentUDTypeInfoEE11LockForReadEv Line | Count | Source | 144 | 2.89k | ReadLock LockForRead() const { | 145 | 2.89k | return ReadLock(&metadata()); | 146 | 2.89k | } |
_ZNK2yb6master18MetadataCowWrapperINS0_23PersistentCDCStreamInfoEE11LockForReadEv Line | Count | Source | 144 | 780 | ReadLock LockForRead() const { | 145 | 780 | return ReadLock(&metadata()); | 146 | 780 | } |
_ZNK2yb6master18MetadataCowWrapperINS0_33PersistentUniverseReplicationInfoEE11LockForReadEv Line | Count | Source | 144 | 4 | ReadLock LockForRead() const { | 145 | 4 | return ReadLock(&metadata()); | 146 | 4 | } |
Unexecuted instantiation: _ZNK2yb6master18MetadataCowWrapperINS0_22PersistentSnapshotInfoEE11LockForReadEv |
147 | | |
148 | 1.02M | WriteLock LockForWrite() { |
149 | 1.02M | return WriteLock(mutable_metadata()); |
150 | 1.02M | } _ZN2yb6master18MetadataCowWrapperINS0_20PersistentTabletInfoEE12LockForWriteEv Line | Count | Source | 148 | 288k | WriteLock LockForWrite() { | 149 | 288k | return WriteLock(mutable_metadata()); | 150 | 288k | } |
_ZN2yb6master18MetadataCowWrapperINS0_19PersistentTableInfoEE12LockForWriteEv Line | Count | Source | 148 | 699k | WriteLock LockForWrite() { | 149 | 699k | return WriteLock(mutable_metadata()); | 150 | 699k | } |
_ZN2yb6master18MetadataCowWrapperINS0_27PersistentClusterConfigInfoEE12LockForWriteEv Line | Count | Source | 148 | 2.49k | WriteLock LockForWrite() { | 149 | 2.49k | return WriteLock(mutable_metadata()); | 150 | 2.49k | } |
_ZN2yb6master18MetadataCowWrapperINS0_23PersistentNamespaceInfoEE12LockForWriteEv Line | Count | Source | 148 | 11.9k | WriteLock LockForWrite() { | 149 | 11.9k | return WriteLock(mutable_metadata()); | 150 | 11.9k | } |
_ZN2yb6master18MetadataCowWrapperINS0_20PersistentUDTypeInfoEE12LockForWriteEv Line | Count | Source | 148 | 47 | WriteLock LockForWrite() { | 149 | 47 | return WriteLock(mutable_metadata()); | 150 | 47 | } |
_ZN2yb6master18MetadataCowWrapperINS0_25PersistentRedisConfigInfoEE12LockForWriteEv Line | Count | Source | 148 | 7 | WriteLock LockForWrite() { | 149 | 7 | return WriteLock(mutable_metadata()); | 150 | 7 | } |
_ZN2yb6master18MetadataCowWrapperINS0_23PersistentSysConfigInfoEE12LockForWriteEv Line | Count | Source | 148 | 16.0k | WriteLock LockForWrite() { | 149 | 16.0k | return WriteLock(mutable_metadata()); | 150 | 16.0k | } |
_ZN2yb6master18MetadataCowWrapperINS0_18PersistentRoleInfoEE12LockForWriteEv Line | Count | Source | 148 | 3.54k | WriteLock LockForWrite() { | 149 | 3.54k | return WriteLock(mutable_metadata()); | 150 | 3.54k | } |
_ZN2yb6master18MetadataCowWrapperINS0_23PersistentCDCStreamInfoEE12LockForWriteEv Line | Count | Source | 148 | 2.54k | WriteLock LockForWrite() { | 149 | 2.54k | return WriteLock(mutable_metadata()); | 150 | 2.54k | } |
_ZN2yb6master18MetadataCowWrapperINS0_33PersistentUniverseReplicationInfoEE12LockForWriteEv Line | Count | Source | 148 | 2 | WriteLock LockForWrite() { | 149 | 2 | return WriteLock(mutable_metadata()); | 150 | 2 | } |
Unexecuted instantiation: _ZN2yb6master18MetadataCowWrapperINS0_22PersistentSnapshotInfoEE12LockForWriteEv |
151 | | |
152 | 398k | const auto& old_pb() const { |
153 | 398k | return metadata_.state().pb; |
154 | 398k | } _ZNK2yb6master18MetadataCowWrapperINS0_19PersistentTableInfoEE6old_pbEv Line | Count | Source | 152 | 59.2k | const auto& old_pb() const { | 153 | 59.2k | return metadata_.state().pb; | 154 | 59.2k | } |
_ZNK2yb6master18MetadataCowWrapperINS0_20PersistentTabletInfoEE6old_pbEv Line | Count | Source | 152 | 302k | const auto& old_pb() const { | 153 | 302k | return metadata_.state().pb; | 154 | 302k | } |
_ZNK2yb6master18MetadataCowWrapperINS0_27PersistentClusterConfigInfoEE6old_pbEv Line | Count | Source | 152 | 2.06k | const auto& old_pb() const { | 153 | 2.06k | return metadata_.state().pb; | 154 | 2.06k | } |
_ZNK2yb6master18MetadataCowWrapperINS0_23PersistentNamespaceInfoEE6old_pbEv Line | Count | Source | 152 | 10.9k | const auto& old_pb() const { | 153 | 10.9k | return metadata_.state().pb; | 154 | 10.9k | } |
_ZNK2yb6master18MetadataCowWrapperINS0_25PersistentRedisConfigInfoEE6old_pbEv Line | Count | Source | 152 | 5 | const auto& old_pb() const { | 153 | 5 | return metadata_.state().pb; | 154 | 5 | } |
_ZNK2yb6master18MetadataCowWrapperINS0_23PersistentSysConfigInfoEE6old_pbEv Line | Count | Source | 152 | 14.7k | const auto& old_pb() const { | 153 | 14.7k | return metadata_.state().pb; | 154 | 14.7k | } |
_ZNK2yb6master18MetadataCowWrapperINS0_18PersistentRoleInfoEE6old_pbEv Line | Count | Source | 152 | 5.79k | const auto& old_pb() const { | 153 | 5.79k | return metadata_.state().pb; | 154 | 5.79k | } |
_ZNK2yb6master18MetadataCowWrapperINS0_20PersistentUDTypeInfoEE6old_pbEv Line | Count | Source | 152 | 92 | const auto& old_pb() const { | 153 | 92 | return metadata_.state().pb; | 154 | 92 | } |
_ZNK2yb6master18MetadataCowWrapperINS0_23PersistentCDCStreamInfoEE6old_pbEv Line | Count | Source | 152 | 2.69k | const auto& old_pb() const { | 153 | 2.69k | return metadata_.state().pb; | 154 | 2.69k | } |
_ZNK2yb6master18MetadataCowWrapperINS0_33PersistentUniverseReplicationInfoEE6old_pbEv Line | Count | Source | 152 | 4 | const auto& old_pb() const { | 153 | 4 | return metadata_.state().pb; | 154 | 4 | } |
Unexecuted instantiation: _ZNK2yb6master18MetadataCowWrapperINS0_22PersistentSnapshotInfoEE6old_pbEv |
155 | | |
156 | 396k | const auto& new_pb() const { |
157 | 396k | return metadata_.dirty().pb; |
158 | 396k | } _ZNK2yb6master18MetadataCowWrapperINS0_19PersistentTableInfoEE6new_pbEv Line | Count | Source | 156 | 59.2k | const auto& new_pb() const { | 157 | 59.2k | return metadata_.dirty().pb; | 158 | 59.2k | } |
_ZNK2yb6master18MetadataCowWrapperINS0_20PersistentTabletInfoEE6new_pbEv Line | Count | Source | 156 | 302k | const auto& new_pb() const { | 157 | 302k | return metadata_.dirty().pb; | 158 | 302k | } |
_ZNK2yb6master18MetadataCowWrapperINS0_27PersistentClusterConfigInfoEE6new_pbEv Line | Count | Source | 156 | 2.06k | const auto& new_pb() const { | 157 | 2.06k | return metadata_.dirty().pb; | 158 | 2.06k | } |
_ZNK2yb6master18MetadataCowWrapperINS0_23PersistentNamespaceInfoEE6new_pbEv Line | Count | Source | 156 | 9.40k | const auto& new_pb() const { | 157 | 9.40k | return metadata_.dirty().pb; | 158 | 9.40k | } |
_ZNK2yb6master18MetadataCowWrapperINS0_25PersistentRedisConfigInfoEE6new_pbEv Line | Count | Source | 156 | 3 | const auto& new_pb() const { | 157 | 3 | return metadata_.dirty().pb; | 158 | 3 | } |
_ZNK2yb6master18MetadataCowWrapperINS0_23PersistentSysConfigInfoEE6new_pbEv Line | Count | Source | 156 | 14.7k | const auto& new_pb() const { | 157 | 14.7k | return metadata_.dirty().pb; | 158 | 14.7k | } |
_ZNK2yb6master18MetadataCowWrapperINS0_18PersistentRoleInfoEE6new_pbEv Line | Count | Source | 156 | 5.06k | const auto& new_pb() const { | 157 | 5.06k | return metadata_.dirty().pb; | 158 | 5.06k | } |
_ZNK2yb6master18MetadataCowWrapperINS0_20PersistentUDTypeInfoEE6new_pbEv Line | Count | Source | 156 | 46 | const auto& new_pb() const { | 157 | 46 | return metadata_.dirty().pb; | 158 | 46 | } |
_ZNK2yb6master18MetadataCowWrapperINS0_23PersistentCDCStreamInfoEE6new_pbEv Line | Count | Source | 156 | 2.69k | const auto& new_pb() const { | 157 | 2.69k | return metadata_.dirty().pb; | 158 | 2.69k | } |
_ZNK2yb6master18MetadataCowWrapperINS0_33PersistentUniverseReplicationInfoEE6new_pbEv Line | Count | Source | 156 | 3 | const auto& new_pb() const { | 157 | 3 | return metadata_.dirty().pb; | 158 | 3 | } |
Unexecuted instantiation: _ZNK2yb6master18MetadataCowWrapperINS0_22PersistentSnapshotInfoEE6new_pbEv |
159 | | |
160 | 333k | static auto type() { |
161 | 333k | return CowState::type(); |
162 | 333k | } _ZN2yb6master18MetadataCowWrapperINS0_19PersistentTableInfoEE4typeEv Line | Count | Source | 160 | 59.2k | static auto type() { | 161 | 59.2k | return CowState::type(); | 162 | 59.2k | } |
_ZN2yb6master18MetadataCowWrapperINS0_20PersistentTabletInfoEE4typeEv Line | Count | Source | 160 | 238k | static auto type() { | 161 | 238k | return CowState::type(); | 162 | 238k | } |
_ZN2yb6master18MetadataCowWrapperINS0_27PersistentClusterConfigInfoEE4typeEv Line | Count | Source | 160 | 2.06k | static auto type() { | 161 | 2.06k | return CowState::type(); | 162 | 2.06k | } |
_ZN2yb6master18MetadataCowWrapperINS0_23PersistentNamespaceInfoEE4typeEv Line | Count | Source | 160 | 10.9k | static auto type() { | 161 | 10.9k | return CowState::type(); | 162 | 10.9k | } |
_ZN2yb6master18MetadataCowWrapperINS0_25PersistentRedisConfigInfoEE4typeEv Line | Count | Source | 160 | 5 | static auto type() { | 161 | 5 | return CowState::type(); | 162 | 5 | } |
_ZN2yb6master18MetadataCowWrapperINS0_23PersistentSysConfigInfoEE4typeEv Line | Count | Source | 160 | 14.7k | static auto type() { | 161 | 14.7k | return CowState::type(); | 162 | 14.7k | } |
_ZN2yb6master18MetadataCowWrapperINS0_18PersistentRoleInfoEE4typeEv Line | Count | Source | 160 | 5.79k | static auto type() { | 161 | 5.79k | return CowState::type(); | 162 | 5.79k | } |
_ZN2yb6master18MetadataCowWrapperINS0_20PersistentUDTypeInfoEE4typeEv Line | Count | Source | 160 | 92 | static auto type() { | 161 | 92 | return CowState::type(); | 162 | 92 | } |
_ZN2yb6master18MetadataCowWrapperINS0_23PersistentCDCStreamInfoEE4typeEv Line | Count | Source | 160 | 2.69k | static auto type() { | 161 | 2.69k | return CowState::type(); | 162 | 2.69k | } |
_ZN2yb6master18MetadataCowWrapperINS0_33PersistentUniverseReplicationInfoEE4typeEv Line | Count | Source | 160 | 4 | static auto type() { | 161 | 4 | return CowState::type(); | 162 | 4 | } |
Unexecuted instantiation: _ZN2yb6master18MetadataCowWrapperINS0_22PersistentSnapshotInfoEE4typeEv |
163 | | |
164 | | protected: |
165 | 8.09k | virtual ~MetadataCowWrapper() = default; _ZN2yb6master18MetadataCowWrapperINS0_27PersistentClusterConfigInfoEED2Ev Line | Count | Source | 165 | 440 | virtual ~MetadataCowWrapper() = default; |
_ZN2yb6master18MetadataCowWrapperINS0_25PersistentRedisConfigInfoEED2Ev Line | Count | Source | 165 | 7 | virtual ~MetadataCowWrapper() = default; |
_ZN2yb6master18MetadataCowWrapperINS0_23PersistentSysConfigInfoEED2Ev Line | Count | Source | 165 | 1.31k | virtual ~MetadataCowWrapper() = default; |
_ZN2yb6master18MetadataCowWrapperINS0_18PersistentRoleInfoEED2Ev Line | Count | Source | 165 | 805 | virtual ~MetadataCowWrapper() = default; |
_ZN2yb6master18MetadataCowWrapperINS0_33PersistentUniverseReplicationInfoEED2Ev Line | Count | Source | 165 | 2 | virtual ~MetadataCowWrapper() = default; |
_ZN2yb6master18MetadataCowWrapperINS0_20PersistentTabletInfoEED2Ev Line | Count | Source | 165 | 1.73k | virtual ~MetadataCowWrapper() = default; |
_ZN2yb6master18MetadataCowWrapperINS0_19PersistentTableInfoEED2Ev Line | Count | Source | 165 | 1.97k | virtual ~MetadataCowWrapper() = default; |
_ZN2yb6master18MetadataCowWrapperINS0_23PersistentNamespaceInfoEED2Ev Line | Count | Source | 165 | 1.76k | virtual ~MetadataCowWrapper() = default; |
_ZN2yb6master18MetadataCowWrapperINS0_20PersistentUDTypeInfoEED2Ev Line | Count | Source | 165 | 47 | virtual ~MetadataCowWrapper() = default; |
_ZN2yb6master18MetadataCowWrapperINS0_23PersistentCDCStreamInfoEED2Ev Line | Count | Source | 165 | 6 | virtual ~MetadataCowWrapper() = default; |
Unexecuted instantiation: _ZN2yb6master18MetadataCowWrapperINS0_22PersistentSnapshotInfoEED2Ev |
166 | | CowObject<PersistentDataEntryPB> metadata_; |
167 | | }; |
168 | | |
169 | | // The data related to a tablet which is persisted on disk. |
170 | | // This portion of TabletInfo is managed via CowObject. |
171 | | // It wraps the underlying protobuf to add useful accessors. |
172 | | struct PersistentTabletInfo : public Persistent<SysTabletsEntryPB, SysRowEntryType::TABLET> { |
173 | 5.32M | bool is_running() const { |
174 | 5.32M | return pb.state() == SysTabletsEntryPB::RUNNING; |
175 | 5.32M | } |
176 | | |
177 | 4.45M | bool is_deleted() const { |
178 | 4.45M | return pb.state() == SysTabletsEntryPB::REPLACED || |
179 | 4.45M | pb.state() == SysTabletsEntryPB::DELETED; |
180 | 4.45M | } |
181 | | |
182 | 933k | bool is_hidden() const { |
183 | 933k | return pb.hide_hybrid_time() != 0; |
184 | 933k | } |
185 | | |
186 | 38.9k | bool ListedAsHidden() const { |
187 | | // Tablet was hidden, but not yet deleted (to avoid resending delete for it). |
188 | 38.9k | return is_hidden() && !is_deleted(); |
189 | 38.9k | } |
190 | | |
191 | 0 | bool is_colocated() const { |
192 | 0 | return pb.colocated(); |
193 | 0 | } |
194 | | |
195 | | // Helper to set the state of the tablet with a custom message. |
196 | | // Requires that the caller has prepared this object for write. |
197 | | // The change will only be visible after Commit(). |
198 | | void set_state(SysTabletsEntryPB::State state, const std::string& msg); |
199 | | }; |
200 | | |
201 | | // The information about a single tablet which exists in the cluster, |
202 | | // including its state and locations. |
203 | | // |
204 | | // This object uses copy-on-write for the portions of data which are persisted |
205 | | // on disk. This allows the mutated data to be staged and written to disk |
206 | | // while readers continue to access the previous version. These portions |
207 | | // of data are in PersistentTabletInfo above, and typically accessed using |
208 | | // MetadataLock. For example: |
209 | | // |
210 | | // TabletInfo* tablet = ...; |
211 | | // MetadataLock l = tablet->LockForRead(); |
212 | | // if (l.data().is_running()) { ... } |
213 | | // |
214 | | // The non-persistent information about the tablet is protected by an internal |
215 | | // spin-lock. |
216 | | // |
217 | | // The object is owned/managed by the CatalogManager, and exposed for testing. |
218 | | class TabletInfo : public RefCountedThreadSafe<TabletInfo>, |
219 | | public MetadataCowWrapper<PersistentTabletInfo> { |
220 | | public: |
221 | | TabletInfo(const scoped_refptr<TableInfo>& table, TabletId tablet_id); |
222 | 14.6M | virtual const TabletId& id() const override { return tablet_id_; } |
223 | | |
224 | 1.59M | const TabletId& tablet_id() const { return tablet_id_; } |
225 | 11.2M | scoped_refptr<const TableInfo> table() const { return table_; } |
226 | 10.2M | const scoped_refptr<TableInfo>& table() { return table_; } |
227 | | |
228 | | // Accessors for the latest known tablet replica locations. |
229 | | // These locations include only the members of the latest-reported Raft |
230 | | // configuration whose tablet servers have ever heartbeated to this Master. |
231 | | void SetReplicaLocations(std::shared_ptr<TabletReplicaMap> replica_locations); |
232 | | std::shared_ptr<const TabletReplicaMap> GetReplicaLocations() const; |
233 | | Result<TSDescriptor*> GetLeader() const; |
234 | | Result<TabletReplicaDriveInfo> GetLeaderReplicaDriveInfo() const; |
235 | | |
236 | | // Replaces a replica in replica_locations_ map if it exists. Otherwise, it adds it to the map. |
237 | | void UpdateReplicaLocations(const TabletReplica& replica); |
238 | | |
239 | | // Updates a replica in replica_locations_ map if it exists. |
240 | | void UpdateReplicaDriveInfo(const std::string& ts_uuid, |
241 | | const TabletReplicaDriveInfo& drive_info); |
242 | | |
243 | | // Accessors for the last time the replica locations were updated. |
244 | | void set_last_update_time(const MonoTime& ts); |
245 | | MonoTime last_update_time() const; |
246 | | |
247 | | // Accessors for the last reported schema version. |
248 | | bool set_reported_schema_version(const TableId& table_id, uint32_t version); |
249 | | uint32_t reported_schema_version(const TableId& table_id); |
250 | | |
251 | | bool colocated() const; |
252 | | |
253 | | // No synchronization needed. |
254 | | std::string ToString() const override; |
255 | | |
256 | | // This is called when a leader stepdown request fails. Optionally, takes an amount of time since |
257 | | // the stepdown failure, in case it happened in the past (e.g. we talked to a tablet server and |
258 | | // it told us that it previously tried to step down in favor of this server and that server lost |
259 | | // the election). |
260 | | void RegisterLeaderStepDownFailure(const TabletServerId& intended_leader, |
261 | | MonoDelta time_since_stepdown_failure); |
262 | | |
263 | | // Retrieves a map of recent leader step-down failures. At the same time, forgets about step-down |
264 | | // failures that happened before a certain point in time. |
265 | | void GetLeaderStepDownFailureTimes(MonoTime forget_failures_before, |
266 | | LeaderStepDownFailureTimes* dest); |
267 | | |
268 | | CHECKED_STATUS CheckRunning() const; |
269 | | |
270 | 91.7k | bool InitiateElection() { |
271 | 91.7k | bool expected = false; |
272 | 91.7k | return initiated_election_.compare_exchange_strong(expected, true); |
273 | 91.7k | } |
274 | | |
275 | | private: |
276 | | friend class RefCountedThreadSafe<TabletInfo>; |
277 | | |
278 | | class LeaderChangeReporter; |
279 | | friend class LeaderChangeReporter; |
280 | | |
281 | | ~TabletInfo(); |
282 | | TSDescriptor* GetLeaderUnlocked() const REQUIRES_SHARED(lock_); |
283 | | CHECKED_STATUS GetLeaderNotFoundStatus() const REQUIRES_SHARED(lock_); |
284 | | |
285 | | const TabletId tablet_id_; |
286 | | const scoped_refptr<TableInfo> table_; |
287 | | |
288 | | // Lock protecting the below mutable fields. |
289 | | // This doesn't protect metadata_ (the on-disk portion). |
290 | | mutable simple_spinlock lock_; |
291 | | |
292 | | // The last time the replica locations were updated. |
293 | | // Also set when the Master first attempts to create the tablet. |
294 | | MonoTime last_update_time_ GUARDED_BY(lock_); |
295 | | |
296 | | // The locations in the latest Raft config where this tablet has been |
297 | | // reported. The map is keyed by tablet server UUID. |
298 | | std::shared_ptr<TabletReplicaMap> replica_locations_ GUARDED_BY(lock_); |
299 | | |
300 | | // Reported schema version (in-memory only). |
301 | | std::unordered_map<TableId, uint32_t> reported_schema_version_ GUARDED_BY(lock_) = {}; |
302 | | |
303 | | LeaderStepDownFailureTimes leader_stepdown_failure_times_ GUARDED_BY(lock_); |
304 | | |
305 | | std::atomic<bool> initiated_election_{false}; |
306 | | |
307 | | DISALLOW_COPY_AND_ASSIGN(TabletInfo); |
308 | | }; |
309 | | |
310 | | // The data related to a table which is persisted on disk. |
311 | | // This portion of TableInfo is managed via CowObject. |
312 | | // It wraps the underlying protobuf to add useful accessors. |
313 | | struct PersistentTableInfo : public Persistent<SysTablesEntryPB, SysRowEntryType::TABLE> { |
314 | 4.68M | bool started_deleting() const { |
315 | 4.68M | return pb.state() == SysTablesEntryPB::DELETING || |
316 | 4.67M | pb.state() == SysTablesEntryPB::DELETED; |
317 | 4.68M | } |
318 | | |
319 | 14.8M | bool is_deleted() const { |
320 | 14.8M | return pb.state() == SysTablesEntryPB::DELETED; |
321 | 14.8M | } |
322 | | |
323 | 11.3M | bool is_deleting() const { |
324 | 11.3M | return pb.state() == SysTablesEntryPB::DELETING; |
325 | 11.3M | } |
326 | | |
327 | 13.1M | bool is_running() const { |
328 | 13.1M | return pb.state() == SysTablesEntryPB::RUNNING || |
329 | 62.5k | pb.state() == SysTablesEntryPB::ALTERING; |
330 | 13.1M | } |
331 | | |
332 | 1.64M | bool visible_to_client() const { |
333 | 1.64M | return is_running() && !is_hidden(); |
334 | 1.64M | } |
335 | | |
336 | 3.64M | bool is_hiding() const { |
337 | 3.64M | return pb.hide_state() == SysTablesEntryPB::HIDING; |
338 | 3.64M | } |
339 | | |
340 | 2.09M | bool is_hidden() const { |
341 | 2.09M | return pb.hide_state() == SysTablesEntryPB::HIDDEN; |
342 | 2.09M | } |
343 | | |
344 | 471k | bool started_hiding() const { |
345 | 471k | return is_hiding() || is_hidden(); |
346 | 471k | } |
347 | | |
348 | | // Return the table's name. |
349 | 41.5k | const TableName& name() const { |
350 | 41.5k | return pb.name(); |
351 | 41.5k | } |
352 | | |
353 | | // Return the table's type. |
354 | 451k | TableType table_type() const { |
355 | 451k | return pb.table_type(); |
356 | 451k | } |
357 | | |
358 | | // Return the table's namespace id. |
359 | 1.16M | const NamespaceId& namespace_id() const { return pb.namespace_id(); } |
360 | | // Return the table's namespace name. |
361 | 50.1k | const NamespaceName& namespace_name() const { return pb.namespace_name(); } |
362 | | |
363 | 530k | const SchemaPB& schema() const { |
364 | 530k | return pb.schema(); |
365 | 530k | } |
366 | | |
367 | | const std::string& indexed_table_id() const; |
368 | | |
369 | | bool is_index() const; |
370 | | |
371 | 202k | SchemaPB* mutable_schema() { |
372 | 202k | return pb.mutable_schema(); |
373 | 202k | } |
374 | | |
375 | | // Helper to set the state of the tablet with a custom message. |
376 | | void set_state(SysTablesEntryPB::State state, const std::string& msg); |
377 | | }; |
378 | | |
379 | | // The information about a table, including its state and tablets. |
380 | | // |
381 | | // This object uses copy-on-write techniques similarly to TabletInfo. |
382 | | // Please see the TabletInfo class doc above for more information. |
383 | | // |
384 | | // The non-persistent information about the table is protected by an internal |
385 | | // spin-lock. |
386 | | class TableInfo : public RefCountedThreadSafe<TableInfo>, |
387 | | public MetadataCowWrapper<PersistentTableInfo> { |
388 | | public: |
389 | | explicit TableInfo(TableId table_id, scoped_refptr<TasksTracker> tasks_tracker = nullptr); |
390 | | |
391 | | const TableName name() const; |
392 | | |
393 | | bool is_running() const; |
394 | | bool is_deleted() const; |
395 | | |
396 | | std::string ToString() const override; |
397 | | std::string ToStringWithState() const; |
398 | | |
399 | | const NamespaceId namespace_id() const; |
400 | | const NamespaceName namespace_name() const; |
401 | | |
402 | | const CHECKED_STATUS GetSchema(Schema* schema) const; |
403 | | |
404 | | bool colocated() const; |
405 | | |
406 | | // Return the table's ID. Does not require synchronization. |
407 | 28.9M | virtual const std::string& id() const override { return table_id_; } |
408 | | |
409 | | // Return the indexed table id if the table is an index table. Otherwise, return an empty string. |
410 | | std::string indexed_table_id() const; |
411 | | |
412 | 23 | bool is_index() const { |
413 | 23 | return !indexed_table_id().empty(); |
414 | 23 | } |
415 | | |
416 | | // For index table |
417 | | bool is_local_index() const; |
418 | | bool is_unique_index() const; |
419 | | |
420 | 241k | void set_is_system() { is_system_ = true; } |
421 | 30.1M | bool is_system() const { return is_system_; } |
422 | | |
423 | | // Return the table type of the table. |
424 | | TableType GetTableType() const; |
425 | | |
426 | | // Checks if the table is the internal redis table. |
427 | 0 | bool IsRedisTable() const { |
428 | 0 | return GetTableType() == REDIS_TABLE_TYPE; |
429 | 0 | } |
430 | | |
431 | | // Add a tablet to this table. |
432 | | void AddTablet(const TabletInfoPtr& tablet); |
433 | | |
434 | | // Replace existing tablet with a new one. |
435 | | void ReplaceTablet(const TabletInfoPtr& old_tablet, const TabletInfoPtr& new_tablet); |
436 | | |
437 | | // Add multiple tablets to this table. |
438 | | void AddTablets(const TabletInfos& tablets); |
439 | | |
440 | | // Removes the tablet from 'partitions_' and 'tablets_' structures. |
441 | | // Return true if the tablet was removed from 'partitions_'. |
442 | | // If deactivate_only is set to true then it only |
443 | | // deactivates the tablet (i.e. removes it only from partitions_ and not from tablets_). |
444 | | // See the declaration of partitions_ structure to understand what constitutes inactive tablets. |
445 | | bool RemoveTablet(const TabletId& tablet_id, |
446 | | DeactivateOnly deactivate_only = DeactivateOnly::kFalse); |
447 | | |
448 | | // Remove multiple tablets from this table. |
449 | | // Return true if all given tablets were removed from 'partitions_'. |
450 | | bool RemoveTablets(const TabletInfos& tablets, |
451 | | DeactivateOnly deactivate_only = DeactivateOnly::kFalse); |
452 | | |
453 | | // This only returns tablets which are in RUNNING state. |
454 | | void GetTabletsInRange(const GetTableLocationsRequestPB* req, TabletInfos *ret) const; |
455 | | void GetTabletsInRange( |
456 | | const std::string& partition_key_start, const std::string& partition_key_end, |
457 | | TabletInfos* ret, |
458 | | int32_t max_returned_locations = std::numeric_limits<int32_t>::max()) const EXCLUDES(lock_); |
459 | | // Iterates through tablets_ and not partitions_, so there may be duplicates of key ranges. |
460 | | void GetInactiveTabletsInRange( |
461 | | const std::string& partition_key_start, const std::string& partition_key_end, |
462 | | TabletInfos* ret, |
463 | | int32_t max_returned_locations = std::numeric_limits<int32_t>::max()) const EXCLUDES(lock_); |
464 | | |
465 | | std::size_t NumPartitions() const; |
466 | | // Return whether given partition start keys match partitions_. |
467 | | bool HasPartitions(const std::vector<PartitionKey> other) const; |
468 | | |
469 | | // Get all tablets of the table. |
470 | | // If include_inactive is true then it also returns inactive tablets along with the active ones. |
471 | | // See the declaration of partitions_ structure to understand what constitutes inactive tablets. |
472 | | TabletInfos GetTablets(IncludeInactive include_inactive = IncludeInactive::kFalse) const; |
473 | | |
474 | | // Get the tablet of the table. The table must be colocated. |
475 | | TabletInfoPtr GetColocatedTablet() const; |
476 | | |
477 | | // Get info of the specified index. |
478 | | IndexInfo GetIndexInfo(const TableId& index_id) const; |
479 | | |
480 | | // Returns true if all tablets of the table are deleted. |
481 | | bool AreAllTabletsDeleted() const; |
482 | | |
483 | | // Returns true if all tablets of the table are deleted or hidden. |
484 | | bool AreAllTabletsHidden() const; |
485 | | |
486 | | // Clears partitons_ and tablets_. |
487 | | // If deactivate_only is set to true then clear only the partitions_. |
488 | | void ClearTabletMaps(DeactivateOnly deactivate_only = DeactivateOnly::kFalse); |
489 | | |
490 | | // Returns true if the table creation is in-progress. |
491 | | bool IsCreateInProgress() const; |
492 | | |
493 | | // Returns true if the table is backfilling an index. |
494 | 11.3M | bool IsBackfilling() const { |
495 | 11.3M | std::shared_lock<decltype(lock_)> l(lock_); |
496 | 11.3M | return is_backfilling_; |
497 | 11.3M | } |
498 | | |
499 | | CHECKED_STATUS SetIsBackfilling(); |
500 | | |
501 | 408 | void ClearIsBackfilling() { |
502 | 408 | std::lock_guard<decltype(lock_)> l(lock_); |
503 | 408 | is_backfilling_ = false; |
504 | 408 | } |
505 | | |
506 | | // Returns true if an "Alter" operation is in-progress. |
507 | | bool IsAlterInProgress(uint32_t version) const; |
508 | | |
509 | | // Set the Status related to errors on CreateTable. |
510 | | void SetCreateTableErrorStatus(const Status& status); |
511 | | |
512 | | // Get the Status of the last error from the current CreateTable. |
513 | | CHECKED_STATUS GetCreateTableErrorStatus() const; |
514 | | |
515 | | std::size_t NumLBTasks() const; |
516 | | std::size_t NumTasks() const; |
517 | | bool HasTasks() const; |
518 | | bool HasTasks(server::MonitoredTask::Type type) const; |
519 | | void AddTask(std::shared_ptr<server::MonitoredTask> task); |
520 | | |
521 | | // Returns true if no running tasks left. |
522 | | bool RemoveTask(const std::shared_ptr<server::MonitoredTask>& task); |
523 | | |
524 | | void AbortTasks(); |
525 | | void AbortTasksAndClose(); |
526 | | void WaitTasksCompletion(); |
527 | | |
528 | | // Allow for showing outstanding tasks in the master UI. |
529 | | std::unordered_set<std::shared_ptr<server::MonitoredTask>> GetTasks(); |
530 | | |
531 | | // Returns whether this is a type of table that will use tablespaces |
532 | | // for placement. |
533 | | bool UsesTablespacesForPlacement() const; |
534 | | |
535 | | bool IsColocatedParentTable() const; |
536 | | bool IsTablegroupParentTable() const; |
537 | | bool IsColocatedUserTable() const; |
538 | | |
539 | | // Provides the ID of the tablespace that will be used to determine |
540 | | // where the tablets for this table should be placed when the table |
541 | | // is first being created. |
542 | | TablespaceId TablespaceIdForTableCreation() const; |
543 | | |
544 | | // Set the tablespace to use during table creation. This will determine |
545 | | // where the tablets of the newly created table should reside. |
546 | | void SetTablespaceIdForTableCreation(const TablespaceId& tablespace_id); |
547 | | |
548 | | private: |
549 | | friend class RefCountedThreadSafe<TableInfo>; |
550 | | ~TableInfo(); |
551 | | |
552 | | void AddTabletUnlocked(const TabletInfoPtr& tablet) REQUIRES(lock_); |
553 | | bool RemoveTabletUnlocked( |
554 | | const TableId& tablet_id, |
555 | | DeactivateOnly deactivate_only = DeactivateOnly::kFalse) REQUIRES(lock_); |
556 | | |
557 | | void AbortTasksAndCloseIfRequested(bool close); |
558 | | |
559 | 0 | std::string LogPrefix() const { |
560 | 0 | return ToString() + ": "; |
561 | 0 | } |
562 | | |
563 | | const TableId table_id_; |
564 | | |
565 | | scoped_refptr<TasksTracker> tasks_tracker_; |
566 | | |
567 | | // Sorted index of tablet start partition-keys to TabletInfo. |
568 | | // The TabletInfo objects are owned by the CatalogManager. |
569 | | // At any point in time it contains only the active tablets. |
570 | | std::map<PartitionKey, TabletInfo*> partitions_ GUARDED_BY(lock_); |
571 | | // At any point in time it contains both active and inactive tablets. |
572 | | // Currently there are two cases for a tablet to be categorized as inactive: |
573 | | // 1) Not yet deleted split parent tablets for which we've already |
574 | | // registered child split tablets. |
575 | | // 2) Tablets that are marked as HIDDEN for PITR. |
576 | | std::unordered_map<TabletId, TabletInfo*> tablets_ GUARDED_BY(lock_); |
577 | | |
578 | | // Protects partitions_, tablets_ and pending_tasks_. |
579 | | mutable rw_spinlock lock_; |
580 | | |
581 | | // If closing, requests to AddTask will be promptly aborted. |
582 | | bool closing_ = false; |
583 | | |
584 | | // In memory state set during backfill to prevent multiple backfill jobs. |
585 | | bool is_backfilling_ = false; |
586 | | |
587 | | std::atomic<bool> is_system_{false}; |
588 | | |
589 | | // List of pending tasks (e.g. create/alter tablet requests). |
590 | | std::unordered_set<std::shared_ptr<server::MonitoredTask>> pending_tasks_ GUARDED_BY(lock_); |
591 | | |
592 | | // The last error Status of the currently running CreateTable. Will be OK, if freshly constructed |
593 | | // object, or if the CreateTable was successful. |
594 | | Status create_table_error_; |
595 | | |
596 | | // This field denotes the tablespace id that the user specified while |
597 | | // creating the table. This will be used only to place tablets at the time |
598 | | // of table creation. At all other times, this information needs to be fetched |
599 | | // from PG catalog tables because the user may have used Alter Table to change |
600 | | // the table's tablespace. |
601 | | TablespaceId tablespace_id_for_table_creation_; |
602 | | |
603 | | DISALLOW_COPY_AND_ASSIGN(TableInfo); |
604 | | }; |
605 | | |
606 | | class DeletedTableInfo; |
607 | | typedef std::pair<TabletServerId, TabletId> TabletKey; |
608 | | typedef std::unordered_map< |
609 | | TabletKey, scoped_refptr<DeletedTableInfo>, boost::hash<TabletKey>> DeletedTabletMap; |
610 | | |
611 | | class DeletedTableInfo : public RefCountedThreadSafe<DeletedTableInfo> { |
612 | | public: |
613 | | explicit DeletedTableInfo(const TableInfo* table); |
614 | | |
615 | 0 | const TableId& id() const { return table_id_; } |
616 | | |
617 | | std::size_t NumTablets() const; |
618 | | bool HasTablets() const; |
619 | | |
620 | | void DeleteTablet(const TabletKey& key); |
621 | | |
622 | | void AddTabletsToMap(DeletedTabletMap* tablet_map); |
623 | | |
624 | | private: |
625 | | const TableId table_id_; |
626 | | |
627 | | // Protects tablet_set_. |
628 | | mutable simple_spinlock lock_; |
629 | | |
630 | | typedef std::unordered_set<TabletKey, boost::hash<TabletKey>> TabletSet; |
631 | | TabletSet tablet_set_ GUARDED_BY(lock_); |
632 | | }; |
633 | | |
634 | | // The data related to a namespace which is persisted on disk. |
635 | | // This portion of NamespaceInfo is managed via CowObject. |
636 | | // It wraps the underlying protobuf to add useful accessors. |
637 | | struct PersistentNamespaceInfo : public Persistent< |
638 | | SysNamespaceEntryPB, SysRowEntryType::NAMESPACE> { |
639 | | // Get the namespace name. |
640 | 28.1k | const NamespaceName& name() const { |
641 | 28.1k | return pb.name(); |
642 | 28.1k | } |
643 | | |
644 | 0 | YQLDatabase database_type() const { |
645 | 0 | return pb.database_type(); |
646 | 0 | } |
647 | | |
648 | 0 | bool colocated() const { |
649 | 0 | return pb.colocated(); |
650 | 0 | } |
651 | | }; |
652 | | |
653 | | // The information about a namespace. |
654 | | // |
655 | | // This object uses copy-on-write techniques similarly to TabletInfo. |
656 | | // Please see the TabletInfo class doc above for more information. |
657 | | class NamespaceInfo : public RefCountedThreadSafe<NamespaceInfo>, |
658 | | public MetadataCowWrapper<PersistentNamespaceInfo> { |
659 | | public: |
660 | | explicit NamespaceInfo(NamespaceId ns_id); |
661 | | |
662 | 234k | virtual const NamespaceId& id() const override { return namespace_id_; } |
663 | | |
664 | | const NamespaceName& name() const; |
665 | | |
666 | | YQLDatabase database_type() const; |
667 | | |
668 | | bool colocated() const; |
669 | | |
670 | | ::yb::master::SysNamespaceEntryPB_State state() const; |
671 | | |
672 | | std::string ToString() const override; |
673 | | |
674 | | private: |
675 | | friend class RefCountedThreadSafe<NamespaceInfo>; |
676 | 1.76k | ~NamespaceInfo() = default; |
677 | | |
678 | | // The ID field is used in the sys_catalog table. |
679 | | const NamespaceId namespace_id_; |
680 | | |
681 | | DISALLOW_COPY_AND_ASSIGN(NamespaceInfo); |
682 | | }; |
683 | | |
684 | | // The information about a tablegroup. |
685 | | class TablegroupInfo : public RefCountedThreadSafe<TablegroupInfo>{ |
686 | | public: |
687 | | explicit TablegroupInfo(TablegroupId tablegroup_id, |
688 | | NamespaceId namespace_id); |
689 | | |
690 | 3 | const std::string& id() const { return tablegroup_id_; } |
691 | 3 | const std::string& namespace_id() const { return namespace_id_; } |
692 | | |
693 | | // Operations to track table_set_ information (what tables belong to the tablegroup) |
694 | | void AddChildTable(const TableId& table_id); |
695 | | void DeleteChildTable(const TableId& table_id); |
696 | | bool HasChildTables() const; |
697 | | std::size_t NumChildTables() const; |
698 | | std::unordered_set<TableId> ChildTables() const; |
699 | | |
700 | | private: |
701 | | friend class RefCountedThreadSafe<TablegroupInfo>; |
702 | 3 | ~TablegroupInfo() = default; |
703 | | |
704 | | // The tablegroup ID is used in the catalog manager maps to look up the proper |
705 | | // tablet to add user tables to. |
706 | | const TablegroupId tablegroup_id_; |
707 | | const NamespaceId namespace_id_; |
708 | | |
709 | | // Protects table_set_. |
710 | | mutable simple_spinlock lock_; |
711 | | std::unordered_set<TableId> table_set_ GUARDED_BY(lock_); |
712 | | |
713 | | DISALLOW_COPY_AND_ASSIGN(TablegroupInfo); |
714 | | }; |
715 | | |
716 | | // The data related to a User-Defined Type which is persisted on disk. |
717 | | // This portion of UDTypeInfo is managed via CowObject. |
718 | | // It wraps the underlying protobuf to add useful accessors. |
719 | | struct PersistentUDTypeInfo : public Persistent<SysUDTypeEntryPB, SysRowEntryType::UDTYPE> { |
720 | | // Return the type's name. |
721 | 4 | const UDTypeName& name() const { |
722 | 4 | return pb.name(); |
723 | 4 | } |
724 | | |
725 | | // Return the table's namespace id. |
726 | 48 | const NamespaceId& namespace_id() const { |
727 | 48 | return pb.namespace_id(); |
728 | 48 | } |
729 | | |
730 | 140 | int field_names_size() const { |
731 | 140 | return pb.field_names_size(); |
732 | 140 | } |
733 | | |
734 | 96 | const string& field_names(int index) const { |
735 | 96 | return pb.field_names(index); |
736 | 96 | } |
737 | | |
738 | 343 | int field_types_size() const { |
739 | 343 | return pb.field_types_size(); |
740 | 343 | } |
741 | | |
742 | 225 | const QLTypePB& field_types(int index) const { |
743 | 225 | return pb.field_types(index); |
744 | 225 | } |
745 | | }; |
746 | | |
747 | | class UDTypeInfo : public RefCountedThreadSafe<UDTypeInfo>, |
748 | | public MetadataCowWrapper<PersistentUDTypeInfo> { |
749 | | public: |
750 | | explicit UDTypeInfo(UDTypeId udtype_id); |
751 | | |
752 | | // Return the user defined type's ID. Does not require synchronization. |
753 | 417 | virtual const std::string& id() const override { return udtype_id_; } |
754 | | |
755 | | const UDTypeName& name() const; |
756 | | |
757 | | const NamespaceId& namespace_id() const; |
758 | | |
759 | | int field_names_size() const; |
760 | | |
761 | | const string& field_names(int index) const; |
762 | | |
763 | | int field_types_size() const; |
764 | | |
765 | | const QLTypePB& field_types(int index) const; |
766 | | |
767 | | std::string ToString() const override; |
768 | | |
769 | | private: |
770 | | friend class RefCountedThreadSafe<UDTypeInfo>; |
771 | 47 | ~UDTypeInfo() = default; |
772 | | |
773 | | // The ID field is used in the sys_catalog table. |
774 | | const UDTypeId udtype_id_; |
775 | | |
776 | | DISALLOW_COPY_AND_ASSIGN(UDTypeInfo); |
777 | | }; |
778 | | |
779 | | // This wraps around the proto containing cluster level config information. It will be used for |
780 | | // CowObject managed access. |
781 | | struct PersistentClusterConfigInfo : public Persistent<SysClusterConfigEntryPB, |
782 | | SysRowEntryType::CLUSTER_CONFIG> { |
783 | | }; |
784 | | |
785 | | // This is the in memory representation of the cluster config information serialized proto data, |
786 | | // using metadata() for CowObject access. |
787 | | class ClusterConfigInfo : public RefCountedThreadSafe<ClusterConfigInfo>, |
788 | | public MetadataCowWrapper<PersistentClusterConfigInfo> { |
789 | | public: |
790 | 2.37k | ClusterConfigInfo() {} |
791 | | |
792 | 2.06k | virtual const std::string& id() const override { return fake_id_; } |
793 | | |
794 | | private: |
795 | | friend class RefCountedThreadSafe<ClusterConfigInfo>; |
796 | 440 | ~ClusterConfigInfo() = default; |
797 | | |
798 | | // We do not use the ID field in the sys_catalog table. |
799 | | const std::string fake_id_; |
800 | | |
801 | | DISALLOW_COPY_AND_ASSIGN(ClusterConfigInfo); |
802 | | }; |
803 | | |
804 | | struct PersistentRedisConfigInfo |
805 | | : public Persistent<SysRedisConfigEntryPB, SysRowEntryType::REDIS_CONFIG> {}; |
806 | | |
807 | | class RedisConfigInfo : public RefCountedThreadSafe<RedisConfigInfo>, |
808 | | public MetadataCowWrapper<PersistentRedisConfigInfo> { |
809 | | public: |
810 | 7 | explicit RedisConfigInfo(const std::string key) : config_key_(key) {} |
811 | | |
812 | 5 | virtual const std::string& id() const override { return config_key_; } |
813 | | |
814 | | private: |
815 | | friend class RefCountedThreadSafe<RedisConfigInfo>; |
816 | 7 | ~RedisConfigInfo() = default; |
817 | | |
818 | | const std::string config_key_; |
819 | | |
820 | | DISALLOW_COPY_AND_ASSIGN(RedisConfigInfo); |
821 | | }; |
822 | | |
823 | | struct PersistentRoleInfo : public Persistent<SysRoleEntryPB, SysRowEntryType::ROLE> {}; |
824 | | |
825 | | class RoleInfo : public RefCountedThreadSafe<RoleInfo>, |
826 | | public MetadataCowWrapper<PersistentRoleInfo> { |
827 | | public: |
828 | 2.76k | explicit RoleInfo(const std::string& role) : role_(role) {} |
829 | 8.43k | const std::string& id() const override { return role_; } |
830 | | |
831 | | private: |
832 | | friend class RefCountedThreadSafe<RoleInfo>; |
833 | 805 | ~RoleInfo() = default; |
834 | | |
835 | | const std::string role_; |
836 | | |
837 | | DISALLOW_COPY_AND_ASSIGN(RoleInfo); |
838 | | }; |
839 | | |
840 | | struct PersistentSysConfigInfo |
841 | | : public Persistent<SysConfigEntryPB, SysRowEntryType::SYS_CONFIG> {}; |
842 | | |
843 | | class SysConfigInfo : public RefCountedThreadSafe<SysConfigInfo>, |
844 | | public MetadataCowWrapper<PersistentSysConfigInfo> { |
845 | | public: |
846 | 7.12k | explicit SysConfigInfo(const std::string& config_type) : config_type_(config_type) {} |
847 | 14.7k | const std::string& id() const override { return config_type_; /* config type is the entry id */ } |
848 | | |
849 | | private: |
850 | | friend class RefCountedThreadSafe<SysConfigInfo>; |
851 | 1.31k | ~SysConfigInfo() = default; |
852 | | |
853 | | const std::string config_type_; |
854 | | |
855 | | DISALLOW_COPY_AND_ASSIGN(SysConfigInfo); |
856 | | }; |
857 | | |
858 | | class DdlLogEntry { |
859 | | public: |
860 | | // time - when DDL operation was started. |
861 | | // table_id - modified table id. |
862 | | // table - what table was modified during DDL. |
863 | | // action - string description of DDL. |
864 | | DdlLogEntry( |
865 | | HybridTime time, const TableId& table_id, const SysTablesEntryPB& table, |
866 | | const std::string& action); |
867 | | |
868 | 3.04k | static SysRowEntryType type() { |
869 | 3.04k | return SysRowEntryType::DDL_LOG_ENTRY; |
870 | 3.04k | } |
871 | | |
872 | | std::string id() const; |
873 | | |
874 | | // Used by sys catalog writer. It requires 2 protobuf to check whether entry was actually changed. |
875 | | const DdlLogEntryPB& new_pb() const; |
876 | | const DdlLogEntryPB& old_pb() const; |
877 | | |
878 | | protected: |
879 | | DdlLogEntryPB pb_; |
880 | | }; |
881 | | |
882 | | // Helper class to commit Info mutations at the end of a scope. |
883 | | template <class Info> |
884 | | class ScopedInfoCommitter { |
885 | | public: |
886 | | typedef scoped_refptr<Info> InfoPtr; |
887 | | typedef std::vector<InfoPtr> Infos; |
888 | 25.3k | explicit ScopedInfoCommitter(const Infos* infos) : infos_(DCHECK_NOTNULL(infos)), done_(false) {} |
889 | 25.3k | ~ScopedInfoCommitter() { |
890 | 25.3k | if (!done_) { |
891 | 25.3k | Commit(); |
892 | 25.3k | } |
893 | 25.3k | } |
894 | | // This method is not thread safe. Must be called by the same thread |
895 | | // that would destroy this instance. |
896 | 4 | void Abort() { |
897 | 4 | if (PREDICT_TRUE(!done_)) { |
898 | 16 | for (const InfoPtr& info : *infos_) { |
899 | 16 | info->mutable_metadata()->AbortMutation(); |
900 | 16 | } |
901 | 4 | } |
902 | 4 | done_ = true; |
903 | 4 | } |
904 | 25.3k | void Commit() { |
905 | 25.3k | if (PREDICT_TRUE(!done_)) { |
906 | 55.6k | for (const InfoPtr& info : *infos_) { |
907 | 55.6k | info->mutable_metadata()->CommitMutation(); |
908 | 55.6k | } |
909 | 25.3k | } |
910 | 25.3k | done_ = true; |
911 | 25.3k | } |
912 | | private: |
913 | | const Infos* infos_; |
914 | | bool done_; |
915 | | }; |
916 | | |
917 | | // Convenience typedefs. |
918 | | // Table(t)InfoMap ordered for deterministic locking. |
919 | | typedef std::pair<NamespaceId, TableName> TableNameKey; |
920 | | typedef std::unordered_map< |
921 | | TableNameKey, scoped_refptr<TableInfo>, boost::hash<TableNameKey>> TableInfoByNameMap; |
922 | | |
923 | | typedef std::unordered_map<UDTypeId, scoped_refptr<UDTypeInfo>> UDTypeInfoMap; |
924 | | typedef std::pair<NamespaceId, UDTypeName> UDTypeNameKey; |
925 | | typedef std::unordered_map< |
926 | | UDTypeNameKey, scoped_refptr<UDTypeInfo>, boost::hash<UDTypeNameKey>> UDTypeInfoByNameMap; |
927 | | |
928 | | template <class Info> |
929 | 0 | void FillInfoEntry(const Info& info, SysRowEntry* entry) { |
930 | 0 | entry->set_id(info.id()); |
931 | 0 | entry->set_type(info.metadata().state().type()); |
932 | 0 | entry->set_data(info.metadata().state().pb.SerializeAsString()); |
933 | 0 | } Unexecuted instantiation: _ZN2yb6master13FillInfoEntryINS0_13NamespaceInfoEEEvRKT_PNS0_11SysRowEntryE Unexecuted instantiation: _ZN2yb6master13FillInfoEntryINS0_9TableInfoEEEvRKT_PNS0_11SysRowEntryE Unexecuted instantiation: _ZN2yb6master13FillInfoEntryINS0_10TabletInfoEEEvRKT_PNS0_11SysRowEntryE |
934 | | |
935 | | template <class Info> |
936 | 0 | auto AddInfoEntry(Info* info, google::protobuf::RepeatedPtrField<SysRowEntry>* out) { |
937 | 0 | auto lock = info->LockForRead(); |
938 | 0 | FillInfoEntry(*info, out->Add()); |
939 | 0 | return lock; |
940 | 0 | } Unexecuted instantiation: _ZN2yb6master12AddInfoEntryINS0_13NamespaceInfoEEEDaPT_PN6google8protobuf16RepeatedPtrFieldINS0_11SysRowEntryEEE Unexecuted instantiation: _ZN2yb6master12AddInfoEntryINS0_9TableInfoEEEDaPT_PN6google8protobuf16RepeatedPtrFieldINS0_11SysRowEntryEEE Unexecuted instantiation: _ZN2yb6master12AddInfoEntryINS0_10TabletInfoEEEDaPT_PN6google8protobuf16RepeatedPtrFieldINS0_11SysRowEntryEEE |
941 | | |
942 | | struct SplitTabletIds { |
943 | | const TabletId& source; |
944 | | const std::pair<const TabletId&, const TabletId&> children; |
945 | | |
946 | 0 | std::string ToString() const { |
947 | 0 | return YB_STRUCT_TO_STRING(source, children); |
948 | 0 | } Unexecuted instantiation: _ZNK2yb6master14SplitTabletIds8ToStringEv Unexecuted instantiation: _ZNK2yb6master14SplitTabletIds8ToStringEv |
949 | | }; |
950 | | |
951 | | } // namespace master |
952 | | } // namespace yb |
953 | | |
954 | | #endif // YB_MASTER_CATALOG_ENTITY_INFO_H |