/Users/deen/code/yugabyte-db/src/yb/tserver/remote_bootstrap_rocksdb_client-test.cc
Line | Count | Source |
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 | | |
14 | | #include <algorithm> |
15 | | |
16 | | #include "yb/tablet/tablet_snapshots.h" |
17 | | |
18 | | #include "yb/tserver/remote_bootstrap_client-test.h" |
19 | | |
20 | | using std::shared_ptr; |
21 | | |
22 | | namespace yb { |
23 | | namespace tserver { |
24 | | |
25 | | using consensus::GetRaftConfigLeader; |
26 | | using consensus::RaftPeerPB; |
27 | | using tablet::RaftGroupMetadata; |
28 | | using tablet::TabletStatusListener; |
29 | | |
30 | | class RemoteBootstrapRocksDBClientTest : public RemoteBootstrapClientTest { |
31 | | public: |
32 | 4 | RemoteBootstrapRocksDBClientTest() : RemoteBootstrapClientTest(YQL_TABLE_TYPE) {} |
33 | | }; |
34 | | |
35 | | // Basic begin / end remote bootstrap session. |
36 | 1 | TEST_F(RemoteBootstrapRocksDBClientTest, TestBeginEndSession) { |
37 | 1 | TabletStatusListener listener(meta_); |
38 | 1 | ASSERT_OK(client_->FetchAll(&listener)); |
39 | 1 | ASSERT_OK(client_->Finish()); |
40 | 1 | } |
41 | | |
42 | | // Basic RocksDB files download unit test. |
43 | 1 | TEST_F(RemoteBootstrapRocksDBClientTest, TestDownloadRocksDBFiles) { |
44 | 1 | TabletStatusListener listener(meta_); |
45 | 1 | ASSERT_OK(client_->FetchAll(&listener)); |
46 | 1 | auto tablet_peer_checkpoint_dir = |
47 | 1 | tablet_peer_->tablet()->snapshots().TEST_LastRocksDBCheckpointDir(); |
48 | | |
49 | 1 | vector<std::string> rocksdb_files; |
50 | 1 | LOG(INFO) << "RocksDB dir: " << meta_->rocksdb_dir(); |
51 | 1 | ASSERT_OK(fs_manager_->ListDir(meta_->rocksdb_dir(), &rocksdb_files)); |
52 | | |
53 | 1 | vector<std::string> tablet_peer_checkpoint_files; |
54 | 1 | ASSERT_OK(tablet_peer_->tablet_metadata()->fs_manager()->ListDir(tablet_peer_checkpoint_dir, |
55 | 1 | &tablet_peer_checkpoint_files)); |
56 | | |
57 | 1 | std::sort(rocksdb_files.begin(), rocksdb_files.end()); |
58 | 1 | std::sort(tablet_peer_checkpoint_files.begin(), tablet_peer_checkpoint_files.end()); |
59 | | |
60 | 2 | ASSERT_EQ(rocksdb_files.size(), tablet_peer_checkpoint_files.size()) |
61 | 2 | << AsString(rocksdb_files) << " vs " << AsString(tablet_peer_checkpoint_files); |
62 | | |
63 | | // Verify that the client has the same files that the leader has. |
64 | 9 | for (size_t i = 0; i < rocksdb_files.size(); ++i) { |
65 | 8 | auto local_rocksdb_file = rocksdb_files[i]; |
66 | 8 | auto tablet_peer_rocksdb_file = tablet_peer_checkpoint_files[i]; |
67 | 8 | ASSERT_EQ(local_rocksdb_file, tablet_peer_rocksdb_file); |
68 | | |
69 | 8 | if (local_rocksdb_file == "." || local_rocksdb_file == "..") { |
70 | 2 | continue; |
71 | 2 | } |
72 | | |
73 | 6 | auto local_rocksdb_file_path = JoinPathSegments(meta_->rocksdb_dir(), local_rocksdb_file); |
74 | 6 | auto tablet_peer_rocksdb_file_path = JoinPathSegments(tablet_peer_checkpoint_dir, |
75 | 6 | tablet_peer_rocksdb_file); |
76 | | |
77 | 6 | LOG(INFO) << "Comparing file " << local_rocksdb_file_path |
78 | 6 | << " and file " << tablet_peer_rocksdb_file_path; |
79 | 6 | ASSERT_OK(CompareFileContents(local_rocksdb_file_path, tablet_peer_rocksdb_file_path)); |
80 | 6 | } |
81 | 1 | } |
82 | | |
83 | | } // namespace tserver |
84 | | } // namespace yb |