YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/ent/src/yb/master/catalog_entity_info.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
13
#ifndef ENT_SRC_YB_MASTER_CATALOG_ENTITY_INFO_H
14
#define ENT_SRC_YB_MASTER_CATALOG_ENTITY_INFO_H
15
16
#include "../../../../src/yb/master/catalog_entity_info.h"
17
18
#include "yb/common/snapshot.h"
19
20
namespace yb {
21
namespace master {
22
23
struct TableDescription {
24
  scoped_refptr<NamespaceInfo> namespace_info;
25
  scoped_refptr<TableInfo> table_info;
26
  TabletInfos tablet_infos;
27
};
28
29
// This wraps around the proto containing CDC stream information. It will be used for
30
// CowObject managed access.
31
struct PersistentCDCStreamInfo : public Persistent<
32
    SysCDCStreamEntryPB, SysRowEntryType::CDC_STREAM> {
33
21
  const google::protobuf::RepeatedPtrField<std::string>& table_id() const {
34
21
    return pb.table_id();
35
21
  }
36
37
0
  const NamespaceId& namespace_id() const {
38
0
    return pb.namespace_id();
39
0
  }
40
41
0
  bool started_deleting() const {
42
0
    return pb.state() == SysCDCStreamEntryPB::DELETING ||
43
0
        pb.state() == SysCDCStreamEntryPB::DELETED;
44
0
  }
45
46
3.12k
  bool is_deleting() const {
47
3.12k
    return pb.state() == SysCDCStreamEntryPB::DELETING;
48
3.12k
  }
49
50
5
  bool is_deleted() const {
51
5
    return pb.state() == SysCDCStreamEntryPB::DELETED;
52
5
  }
53
54
10
  const google::protobuf::RepeatedPtrField<CDCStreamOptionsPB> options() const {
55
10
    return pb.options();
56
10
  }
57
};
58
59
class CDCStreamInfo : public RefCountedThreadSafe<CDCStreamInfo>,
60
                      public MetadataCowWrapper<PersistentCDCStreamInfo> {
61
 public:
62
159
  explicit CDCStreamInfo(CDCStreamId stream_id) : stream_id_(std::move(stream_id)) {}
63
64
3.17k
  const CDCStreamId& id() const override { return stream_id_; }
65
66
  const google::protobuf::RepeatedPtrField<std::string>& table_id() const;
67
68
  const NamespaceId& namespace_id() const;
69
70
  std::string ToString() const override;
71
72
 private:
73
  friend class RefCountedThreadSafe<CDCStreamInfo>;
74
6
  ~CDCStreamInfo() = default;
75
76
  const CDCStreamId stream_id_;
77
78
  DISALLOW_COPY_AND_ASSIGN(CDCStreamInfo);
79
};
80
81
// This wraps around the proto containing universe replication information. It will be used for
82
// CowObject managed access.
83
struct PersistentUniverseReplicationInfo :
84
    public Persistent<SysUniverseReplicationEntryPB, SysRowEntryType::UNIVERSE_REPLICATION> {
85
86
0
  bool is_deleted_or_failed() const {
87
0
    return pb.state() == SysUniverseReplicationEntryPB::DELETED
88
0
      || pb.state() == SysUniverseReplicationEntryPB::DELETED_ERROR
89
0
      || pb.state() == SysUniverseReplicationEntryPB::FAILED;
90
0
  }
91
92
0
  bool is_active() const {
93
0
    return pb.state() == SysUniverseReplicationEntryPB::ACTIVE;
94
0
  }
95
};
96
97
class UniverseReplicationInfo : public RefCountedThreadSafe<UniverseReplicationInfo>,
98
                                public MetadataCowWrapper<PersistentUniverseReplicationInfo> {
99
 public:
100
  explicit UniverseReplicationInfo(std::string producer_id)
101
4
      : producer_id_(std::move(producer_id)) {}
102
103
8
  const std::string& id() const override { return producer_id_; }
104
105
  std::string ToString() const override;
106
107
  Result<std::shared_ptr<CDCRpcTasks>> GetOrCreateCDCRpcTasks(
108
      google::protobuf::RepeatedPtrField<HostPortPB> producer_masters);
109
110
  // Set the Status related to errors on SetupUniverseReplication.
111
  void SetSetupUniverseReplicationErrorStatus(const Status& status);
112
113
  // Get the Status of the last error from the current SetupUniverseReplication.
114
  CHECKED_STATUS GetSetupUniverseReplicationErrorStatus() const;
115
116
 private:
117
  friend class RefCountedThreadSafe<UniverseReplicationInfo>;
118
2
  ~UniverseReplicationInfo() = default;
119
120
  const std::string producer_id_;
121
122
  std::shared_ptr<CDCRpcTasks> cdc_rpc_tasks_;
123
  std::string master_addrs_;
124
125
  // The last error Status of the currently running SetupUniverseReplication. Will be OK, if freshly
126
  // constructed object, or if the SetupUniverseReplication was successful.
127
  Status setup_universe_replication_error_ = Status::OK();
128
129
  // Protects cdc_rpc_tasks_.
130
  mutable rw_spinlock lock_;
131
132
  DISALLOW_COPY_AND_ASSIGN(UniverseReplicationInfo);
133
};
134
135
// The data related to a snapshot which is persisted on disk.
136
// This portion of SnapshotInfo is managed via CowObject.
137
// It wraps the underlying protobuf to add useful accessors.
138
struct PersistentSnapshotInfo : public Persistent<SysSnapshotEntryPB, SysRowEntryType::SNAPSHOT> {
139
0
  SysSnapshotEntryPB::State state() const {
140
0
    return pb.state();
141
0
  }
142
143
0
  const std::string& state_name() const {
144
0
    return SysSnapshotEntryPB::State_Name(state());
145
0
  }
146
147
0
  bool is_creating() const {
148
0
    return state() == SysSnapshotEntryPB::CREATING;
149
0
  }
150
151
0
  bool started_deleting() const {
152
0
    return state() == SysSnapshotEntryPB::DELETING ||
153
0
           state() == SysSnapshotEntryPB::DELETED;
154
0
  }
155
156
0
  bool is_failed() const {
157
0
    return state() == SysSnapshotEntryPB::FAILED;
158
0
  }
159
160
0
  bool is_cancelled() const {
161
0
    return state() == SysSnapshotEntryPB::CANCELLED;
162
0
  }
163
164
0
  bool is_complete() const {
165
0
    return state() == SysSnapshotEntryPB::COMPLETE;
166
0
  }
167
168
0
  bool is_restoring() const {
169
0
    return state() == SysSnapshotEntryPB::RESTORING;
170
0
  }
171
172
0
  bool is_deleting() const {
173
0
    return state() == SysSnapshotEntryPB::DELETING;
174
0
  }
175
};
176
177
// The information about a snapshot.
178
//
179
// This object uses copy-on-write techniques similarly to TabletInfo.
180
// Please see the TabletInfo class doc above for more information.
181
class SnapshotInfo : public RefCountedThreadSafe<SnapshotInfo>,
182
                     public MetadataCowWrapper<PersistentSnapshotInfo> {
183
 public:
184
  explicit SnapshotInfo(SnapshotId id);
185
186
0
  virtual const std::string& id() const override { return snapshot_id_; };
187
188
  SysSnapshotEntryPB::State state() const;
189
190
  const std::string& state_name() const;
191
192
  std::string ToString() const override;
193
194
  // Returns true if the snapshot creation is in-progress.
195
  bool IsCreateInProgress() const;
196
197
  // Returns true if the snapshot restoring is in-progress.
198
  bool IsRestoreInProgress() const;
199
200
  // Returns true if the snapshot deleting is in-progress.
201
  bool IsDeleteInProgress() const;
202
203
  void AddEntries(
204
      const TableDescription& table_description, std::unordered_set<NamespaceId>* added_namespaces);
205
206
  static void AddEntries(
207
      const TableDescription& table_description,
208
      google::protobuf::RepeatedPtrField<SysRowEntry>* out,
209
      google::protobuf::RepeatedPtrField<SysSnapshotEntryPB::TabletSnapshotPB>* tablet_infos,
210
      std::unordered_set<NamespaceId>* added_namespaces);
211
212
 private:
213
  friend class RefCountedThreadSafe<SnapshotInfo>;
214
0
  ~SnapshotInfo() = default;
215
216
  // The ID field is used in the sys_catalog table.
217
  const SnapshotId snapshot_id_;
218
219
  DISALLOW_COPY_AND_ASSIGN(SnapshotInfo);
220
};
221
222
} // namespace master
223
} // namespace yb
224
225
#endif // ENT_SRC_YB_MASTER_CATALOG_ENTITY_INFO_H