/Users/deen/code/yugabyte-db/src/yb/tserver/remote_bootstrap-test-base.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 | | #ifndef YB_TSERVER_REMOTE_BOOTSTRAP_TEST_BASE_H_ |
33 | | #define YB_TSERVER_REMOTE_BOOTSTRAP_TEST_BASE_H_ |
34 | | |
35 | | #include <string> |
36 | | |
37 | | #include "yb/consensus/log.h" |
38 | | #include "yb/consensus/log_anchor_registry.h" |
39 | | #include "yb/consensus/opid_util.h" |
40 | | |
41 | | #include "yb/gutil/strings/fastmem.h" |
42 | | #include "yb/tablet/metadata.pb.h" |
43 | | #include "yb/tablet/tablet.h" |
44 | | #include "yb/tablet/tablet_metadata.h" |
45 | | #include "yb/tablet/tablet_peer.h" |
46 | | |
47 | | #include "yb/tserver/remote_bootstrap.pb.h" |
48 | | #include "yb/tserver/tablet_server-test-base.h" |
49 | | |
50 | | #include "yb/util/crc.h" |
51 | | #include "yb/util/stopwatch.h" |
52 | | #include "yb/util/test_util.h" |
53 | | |
54 | | namespace yb { |
55 | | namespace tserver { |
56 | | |
57 | | using consensus::MinimumOpId; |
58 | | |
59 | | // Number of times to roll the log. |
60 | | static const int kNumLogRolls = 2; |
61 | | |
62 | | class RemoteBootstrapTest : public TabletServerTestBase { |
63 | | public: |
64 | | explicit RemoteBootstrapTest(TableType table_type = DEFAULT_TABLE_TYPE) |
65 | 11 | : TabletServerTestBase(table_type) {} |
66 | | |
67 | 11 | virtual void SetUp() override { |
68 | 11 | TabletServerTestBase::SetUp(); |
69 | 11 | StartTabletServer(); |
70 | | // Prevent logs from being deleted out from under us until / unless we want |
71 | | // to test that we are anchoring correctly. Since GenerateTestData() does a |
72 | | // Flush(), Log GC is allowed to eat the logs before we get around to |
73 | | // starting a remote bootstrap session. |
74 | 11 | tablet_peer_->log_anchor_registry()->Register( |
75 | 11 | MinimumOpId().index(), CURRENT_TEST_NAME(), &anchor_); |
76 | 11 | ASSERT_NO_FATALS(GenerateTestData()); |
77 | 11 | } |
78 | | |
79 | 11 | virtual void TearDown() override { |
80 | 11 | ASSERT_OK(tablet_peer_->log_anchor_registry()->Unregister(&anchor_)); |
81 | 11 | TabletServerTestBase::TearDown(); |
82 | 11 | } |
83 | | |
84 | | protected: |
85 | | // Check that the contents and CRC32C of a DataChunkPB are equal to a local buffer. |
86 | 1 | static void AssertDataEqual(const uint8_t* local, int64_t size, const DataChunkPB& remote) { |
87 | 1 | ASSERT_EQ(size, remote.data().size()); |
88 | 1 | ASSERT_TRUE(strings::memeq(local, remote.data().data(), size)); |
89 | 1 | uint32_t crc32 = crc::Crc32c(local, size); |
90 | 1 | ASSERT_EQ(crc32, remote.crc32()); |
91 | 1 | } |
92 | | |
93 | | // Generate the test data for the tablet and do the flushing we assume will be |
94 | | // done in the unit tests for remote bootstrap. |
95 | 11 | void GenerateTestData() { |
96 | 11 | const int kIncr = 50; |
97 | 11 | LOG_TIMING(INFO, "Loading test data") { |
98 | 33 | for (int row_id = 0; row_id < kNumLogRolls * kIncr; row_id += kIncr) { |
99 | 22 | InsertTestRowsRemote(0, row_id, kIncr); |
100 | 22 | ASSERT_OK(tablet_peer_->tablet()->Flush(tablet::FlushMode::kSync)); |
101 | 22 | ASSERT_OK(tablet_peer_->log()->AllocateSegmentAndRollOver()); |
102 | 22 | } |
103 | 11 | } |
104 | 11 | } |
105 | | |
106 | | // Return the permanent_uuid of the local service. |
107 | 8 | const std::string GetLocalUUID() const { |
108 | 8 | return tablet_peer_->permanent_uuid(); |
109 | 8 | } |
110 | | |
111 | 0 | std::string GetTableId() const { |
112 | 0 | return tablet_peer_->tablet()->metadata()->table_id(); |
113 | 0 | } |
114 | | |
115 | 10 | const std::string& GetTabletId() const { |
116 | 10 | return tablet_peer_->tablet()->tablet_id(); |
117 | 10 | } |
118 | | |
119 | | log::LogAnchor anchor_; |
120 | | }; |
121 | | |
122 | | } // namespace tserver |
123 | | } // namespace yb |
124 | | |
125 | | #endif // YB_TSERVER_REMOTE_BOOTSTRAP_TEST_BASE_H_ |