/Users/deen/code/yugabyte-db/src/yb/tablet/tablet_bootstrap_if.cc
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 | | |
33 | | #include "yb/tablet/tablet_bootstrap_if.h" |
34 | | |
35 | | #include <atomic> |
36 | | #include <future> |
37 | | #include <map> |
38 | | #include <memory> |
39 | | #include <mutex> |
40 | | #include <string> |
41 | | #include <vector> |
42 | | |
43 | | #include "yb/consensus/consensus_fwd.h" |
44 | | #include "yb/consensus/log.h" |
45 | | |
46 | | #include "yb/gutil/callback.h" |
47 | | #include "yb/gutil/ref_counted.h" |
48 | | #include "yb/gutil/thread_annotations.h" |
49 | | |
50 | | #include "yb/tablet/tablet_fwd.h" |
51 | | #include "yb/tablet/tablet_bootstrap.h" |
52 | | #include "yb/tablet/tablet_metadata.h" |
53 | | #include "yb/tablet/tablet_options.h" |
54 | | |
55 | | #include "yb/util/debug/trace_event.h" |
56 | | |
57 | | namespace yb { |
58 | | namespace tablet { |
59 | | |
60 | | using std::shared_ptr; |
61 | | |
62 | | using consensus::ConsensusBootstrapInfo; |
63 | | |
64 | | TabletStatusListener::TabletStatusListener(const RaftGroupMetadataPtr& meta) |
65 | 88.6k | : meta_(meta) { |
66 | 88.6k | } |
67 | | |
68 | 242k | const string TabletStatusListener::tablet_id() const { |
69 | 242k | return meta_->raft_group_id(); |
70 | 242k | } |
71 | | |
72 | 7.35k | const string TabletStatusListener::namespace_name() const { |
73 | 7.35k | return meta_->namespace_name(); |
74 | 7.35k | } |
75 | | |
76 | 7.35k | const string TabletStatusListener::table_name() const { |
77 | 7.35k | return meta_->table_name(); |
78 | 7.35k | } |
79 | | |
80 | 7.35k | const string TabletStatusListener::table_id() const { |
81 | 7.35k | return meta_->table_id(); |
82 | 7.35k | } |
83 | | |
84 | 7.36k | std::shared_ptr<Partition> TabletStatusListener::partition() const { |
85 | 7.36k | return meta_->partition(); |
86 | 7.36k | } |
87 | | |
88 | 3.14k | SchemaPtr TabletStatusListener::schema() const { |
89 | 3.14k | return meta_->schema(); |
90 | 3.14k | } |
91 | | |
92 | 47.4k | TabletStatusListener::~TabletStatusListener() { |
93 | 47.4k | } |
94 | | |
95 | 235k | void TabletStatusListener::StatusMessage(const string& status) { |
96 | 235k | LOG(INFO) << "T " << tablet_id() << " P " << meta_->fs_manager()->uuid() << ": " |
97 | 235k | << status; |
98 | 235k | std::lock_guard<std::shared_timed_mutex> l(lock_); |
99 | 235k | last_status_ = status; |
100 | 235k | } |
101 | | |
102 | | Status BootstrapTablet( |
103 | | const BootstrapTabletData& data, |
104 | | TabletPtr* rebuilt_tablet, |
105 | | scoped_refptr<log::Log>* rebuilt_log, |
106 | 89.1k | ConsensusBootstrapInfo* consensus_info) { |
107 | 89.1k | const auto& meta = *data.tablet_init_data.metadata; |
108 | 89.1k | TRACE_EVENT1("tablet", "BootstrapTablet", "tablet_id", meta.raft_group_id()); |
109 | 89.1k | RETURN_NOT_OK(BootstrapTabletImpl(data, rebuilt_tablet, rebuilt_log, consensus_info)); |
110 | | |
111 | | // Set WAL retention time from the metadata. |
112 | 89.1k | (*rebuilt_log)->set_wal_retention_secs(meta.wal_retention_secs()); |
113 | 89.1k | (*rebuilt_log)->set_cdc_min_replicated_index(meta.cdc_min_replicated_index()); |
114 | | |
115 | | // This is necessary since OpenNewLog() initially disables sync. |
116 | 89.1k | RETURN_NOT_OK((*rebuilt_log)->ReEnableSyncIfRequired()); |
117 | 89.1k | return Status::OK(); |
118 | 89.1k | } |
119 | | |
120 | 2.12k | string DocDbOpIds::ToString() const { |
121 | 2.12k | return Format("{ regular: $0 intents: $1 }", regular, intents); |
122 | 2.12k | } |
123 | | |
124 | | } // namespace tablet |
125 | | } // namespace yb |