YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/tablet/tablet_bootstrap_if.h
Line
Count
Source
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
#ifndef YB_TABLET_TABLET_BOOTSTRAP_IF_H
33
#define YB_TABLET_TABLET_BOOTSTRAP_IF_H
34
35
#include <memory>
36
#include <shared_mutex>
37
#include <string>
38
#include <vector>
39
40
#include <boost/optional.hpp>
41
42
#include "yb/client/client_fwd.h"
43
44
#include "yb/consensus/log_fwd.h"
45
#include "yb/consensus/consensus_fwd.h"
46
47
#include "yb/gutil/ref_counted.h"
48
49
#include "yb/tablet/tablet_fwd.h"
50
#include "yb/tablet/tablet_options.h"
51
52
#include "yb/util/status_fwd.h"
53
#include "yb/util/opid.h"
54
#include "yb/util/shared_lock.h"
55
56
namespace yb {
57
58
class MetricRegistry;
59
class Partition;
60
class PartitionSchema;
61
class ThreadPool;
62
63
namespace consensus {
64
struct ConsensusBootstrapInfo;
65
} // namespace consensus
66
67
namespace server {
68
class Clock;
69
}
70
71
namespace tablet {
72
class Tablet;
73
class RaftGroupMetadata;
74
class TransactionCoordinatorContext;
75
class TransactionParticipantContext;
76
struct TabletOptions;
77
78
// A listener for logging the tablet related statuses as well as
79
// piping it into the web UI.
80
class TabletStatusListener {
81
 public:
82
  explicit TabletStatusListener(const RaftGroupMetadataPtr& meta);
83
84
  ~TabletStatusListener();
85
86
  void StatusMessage(const std::string& status);
87
88
  const std::string tablet_id() const;
89
90
  const std::string namespace_name() const;
91
92
  const std::string table_name() const;
93
94
  const std::string table_id() const;
95
96
  std::shared_ptr<Partition> partition() const;
97
98
  SchemaPtr schema() const;
99
100
8.14k
  std::string last_status() const {
101
8.14k
    SharedLock<std::shared_timed_mutex> l(lock_);
102
8.14k
    return last_status_;
103
8.14k
  }
104
105
 private:
106
  mutable std::shared_timed_mutex lock_;
107
108
  RaftGroupMetadataPtr meta_;
109
  std::string last_status_;
110
111
  DISALLOW_COPY_AND_ASSIGN(TabletStatusListener);
112
};
113
114
struct DocDbOpIds {
115
  OpId regular;
116
  OpId intents;
117
118
  std::string ToString() const;
119
};
120
121
// This is used for tests to interact with the tablet bootstrap procedure.
122
class TabletBootstrapTestHooksIf {
123
 public:
124
  virtual ~TabletBootstrapTestHooksIf() {}
125
126
  // This is called during TabletBootstrap initialization so that the test can pretend certain
127
  // OpIds have been flushed in to regular and intents RocksDBs.
128
  virtual boost::optional<DocDbOpIds> GetFlushedOpIdsOverride() const = 0;
129
130
  // TabletBootstrap calls this when an operation is replayed.
131
  // replay_decision is true for transaction update operations that have already been applied to the
132
  // regular RocksDB but not to the intents RocksDB.
133
  virtual void Replayed(
134
      OpId op_id,
135
      AlreadyAppliedToRegularDB already_applied_to_regular_db) = 0;
136
137
  // TabletBootstrap calls this when an operation is overwritten after a leader change.
138
  virtual void Overwritten(OpId op_id) = 0;
139
140
  virtual void RetryableRequest(OpId op_id) = 0;
141
142
  // Skip replaying transaction update requests, either on transaction coordinator or participant.
143
  // This is useful to avoid instatiating the entire transactional subsystem in a test tablet.
144
  virtual bool ShouldSkipTransactionUpdates() const = 0;
145
146
  // Will skip writing to the intents RocksDB if this returns true.
147
  virtual bool ShouldSkipWritingIntents() const = 0;
148
149
  // Tablet bootstrap will pretend that the intents RocksDB exists even if it does not if this
150
  // returns true.
151
  virtual bool HasIntentsDB() const = 0;
152
153
  // Tablet bootstrap calls this in the "bootstrap optimizer" code (--skip_wal_rewrite) every time
154
  // it discovers the first OpId of a log segment. OpId will be invalid if we could not read the
155
  // first OpId. This is called in the order from newer to older segments;
156
  virtual void FirstOpIdOfSegment(const std::string& path, OpId first_op_id) = 0;
157
};
158
159
struct BootstrapTabletData {
160
  TabletInitData tablet_init_data;
161
  TabletStatusListener* listener = nullptr;
162
  ThreadPool* append_pool = nullptr;
163
  ThreadPool* allocation_pool = nullptr;
164
  consensus::RetryableRequests* retryable_requests = nullptr;
165
166
  std::shared_ptr<TabletBootstrapTestHooksIf> test_hooks = nullptr;
167
};
168
169
// Bootstraps a tablet, initializing it with the provided metadata. If the tablet
170
// has blocks and log segments, this method rebuilds the soft state by replaying
171
// the Log.
172
//
173
// This is a synchronous method, but is typically called within a thread pool by
174
// TSTabletManager.
175
CHECKED_STATUS BootstrapTablet(
176
    const BootstrapTabletData& data,
177
    TabletPtr* rebuilt_tablet,
178
    log::LogPtr* rebuilt_log,
179
    consensus::ConsensusBootstrapInfo* consensus_info);
180
181
}  // namespace tablet
182
}  // namespace yb
183
184
#endif // YB_TABLET_TABLET_BOOTSTRAP_IF_H