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