YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/ent/src/yb/tserver/remote_bootstrap_rocksdb_session-test_ent.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
#include "yb/tserver/remote_bootstrap_session-test.h"
14
15
#include "yb/consensus/log.h"
16
17
#include "yb/tablet/tablet.h"
18
#include "yb/tablet/tablet_metadata.h"
19
#include "yb/tablet/tablet_peer.h"
20
#include "yb/tablet/tablet_snapshots.h"
21
#include "yb/tablet/operations/snapshot_operation.h"
22
23
namespace yb {
24
namespace tserver {
25
26
using std::string;
27
28
using yb::tablet::Tablet;
29
30
static const string kSnapshotId = "0123456789ABCDEF0123456789ABCDEF";
31
32
class RemoteBootstrapRocksDBTest : public RemoteBootstrapSessionTest {
33
 public:
34
4
  RemoteBootstrapRocksDBTest() : RemoteBootstrapSessionTest(YQL_TABLE_TYPE) {}
35
36
1
  void InitSession() override {
37
1
    CreateSnapshot();
38
1
    RemoteBootstrapSessionTest::InitSession();
39
1
  }
40
41
1
  void CreateSnapshot() {
42
1
    LOG(INFO) << "Creating Snapshot " << kSnapshotId << " ...";
43
1
    TabletSnapshotOpRequestPB request;
44
1
    request.set_snapshot_id(kSnapshotId);
45
1
    tablet::SnapshotOperation operation(tablet().get(), &request);
46
1
    operation.set_hybrid_time(tablet()->clock()->Now());
47
1
    operation.set_op_id(tablet_peer_->log()->GetLatestEntryOpId());
48
1
    ASSERT_OK(tablet()->snapshots().Create(&operation));
49
50
    // Create extra file to check that it will not break snapshot files collecting
51
    // inside RemoteBootstrapSession::InitSession().
52
1
    const string rocksdb_dir = tablet()->metadata()->rocksdb_dir();
53
1
    const string top_snapshots_dir = tablet()->metadata()->snapshots_dir();
54
1
    const string snapshot_dir = JoinPathSegments(top_snapshots_dir, kSnapshotId);
55
1
    ASSERT_TRUE(env_->FileExists(snapshot_dir));
56
57
1
    const string extra_file = snapshot_dir + ".sha256";
58
1
    ASSERT_FALSE(env_->FileExists(extra_file));
59
1
    {
60
1
      std::unique_ptr<WritableFile> writer;
61
1
      ASSERT_OK(env_->NewWritableFile(extra_file, &writer));
62
1
      ASSERT_OK(writer->Append(Slice("012345")));
63
1
      ASSERT_OK(writer->Flush(WritableFile::FLUSH_SYNC));
64
1
      ASSERT_OK(writer->Close());
65
1
    }
66
1
    ASSERT_TRUE(env_->FileExists(extra_file));
67
1
  }
68
};
69
70
1
TEST_F(RemoteBootstrapRocksDBTest, CheckSuperBlockHasSnapshotFields) {
71
1
  auto superblock = session_->tablet_superblock();
72
1
  LOG(INFO) << superblock.ShortDebugString();
73
1
  ASSERT_TRUE(superblock.obsolete_table_type() == YQL_TABLE_TYPE);
74
75
1
  const auto& kv_store = superblock.kv_store();
76
1
  ASSERT_TRUE(kv_store.has_rocksdb_dir());
77
78
1
  const string& rocksdb_dir = kv_store.rocksdb_dir();
79
1
  ASSERT_TRUE(env_->FileExists(rocksdb_dir));
80
81
1
  const string top_snapshots_dir = tablet::TabletSnapshots::SnapshotsDirName(rocksdb_dir);
82
1
  ASSERT_TRUE(env_->FileExists(top_snapshots_dir));
83
84
1
  const string snapshot_dir = JoinPathSegments(top_snapshots_dir, kSnapshotId);
85
1
  ASSERT_TRUE(env_->FileExists(snapshot_dir));
86
87
1
  vector<string> snapshot_files;
88
1
  ASSERT_OK(env_->GetChildren(snapshot_dir, &snapshot_files));
89
90
  // Ignore "." and ".." entries in snapshot_dir.
91
2
  ASSERT_EQ(kv_store.snapshot_files().size(), snapshot_files.size() - 2)
92
2
      << "KV store snapshot files: " << AsString(kv_store.snapshot_files())
93
2
      << ", filesystem: " << AsString(snapshot_files);
94
95
5
  for (int i = 0; i < kv_store.snapshot_files().size(); ++i) {
96
4
    const auto& snapshot_file = kv_store.snapshot_files(i);
97
4
    const string& snapshot_id = snapshot_file.snapshot_id();
98
4
    const string& snapshot_file_name = snapshot_file.file().name();
99
4
    const uint64_t snapshot_file_size_bytes = snapshot_file.file().size_bytes();
100
101
4
    ASSERT_EQ(snapshot_id, kSnapshotId);
102
103
4
    const string file_path = JoinPathSegments(snapshot_dir, snapshot_file_name);
104
4
    ASSERT_TRUE(env_->FileExists(file_path));
105
106
4
    uint64 file_size_bytes = ASSERT_RESULT(env_->GetFileSize(file_path));
107
4
    ASSERT_EQ(snapshot_file_size_bytes, file_size_bytes);
108
4
  }
109
1
}
110
111
}  // namespace tserver
112
}  // namespace yb