YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/tablet/tablet-harness.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_TABLET_TABLET_HARNESS_H
33
#define YB_TABLET_TABLET_HARNESS_H
34
35
#include <memory>
36
#include <string>
37
#include <utility>
38
#include <vector>
39
40
#include "yb/common/schema.h"
41
42
#include "yb/fs/fs_manager.h"
43
44
#include "yb/server/clock.h"
45
46
#include "yb/tablet/tablet_fwd.h"
47
48
#include "yb/util/env.h"
49
#include "yb/util/metrics.h"
50
#include "yb/util/status_log.h"
51
52
using std::string;
53
using std::vector;
54
55
namespace yb {
56
namespace tablet {
57
58
// Creates a default partition schema and partition for a table.
59
//
60
// The provided schema must include column IDs.
61
//
62
// The partition schema will have no hash components, and a single range component over the primary
63
// key columns. The partition will cover the entire partition-key space.
64
std::pair<PartitionSchema, Partition> CreateDefaultPartition(const Schema& schema);
65
66
class TabletHarness {
67
 public:
68
  struct Options {
69
    explicit Options(string root_dir)
70
        : env(Env::Default()),
71
          tablet_id("test_tablet_id"),
72
          root_dir(std::move(root_dir)),
73
          table_type(TableType::DEFAULT_TABLE_TYPE),
74
74
          enable_metrics(true) {}
75
76
    Env* env;
77
    string tablet_id;
78
    string root_dir;
79
    TableType table_type;
80
    bool enable_metrics;
81
  };
82
83
  TabletHarness(const Schema& schema, Options options)
84
74
      : options_(std::move(options)), schema_(schema) {}
85
86
74
  virtual ~TabletHarness() = default;
87
88
  CHECKED_STATUS Create(bool first_time);
89
90
  CHECKED_STATUS Open();
91
92
  Result<TabletPtr> OpenTablet(const TabletId& tablet_id);
93
94
  TabletInitData MakeTabletInitData(const RaftGroupMetadataPtr& metadata);
95
96
8
  server::Clock* clock() const {
97
8
    return clock_.get();
98
8
  }
99
100
2.86k
  const TabletPtr& tablet() {
101
2.86k
    return tablet_;
102
2.86k
  }
103
104
20
  FsManager* fs_manager() {
105
20
    return fs_manager_.get();
106
20
  }
107
108
6
  MetricRegistry* metrics_registry() {
109
6
    return metrics_registry_.get();
110
6
  }
111
112
0
  const Options& options() const { return options_; }
113
114
 private:
115
  Options options_;
116
117
  std::unique_ptr<MetricRegistry> metrics_registry_;
118
119
  scoped_refptr<server::Clock> clock_;
120
  Schema schema_;
121
  std::unique_ptr<FsManager> fs_manager_;
122
  TabletPtr tablet_;
123
};
124
125
} // namespace tablet
126
} // namespace yb
127
#endif // YB_TABLET_TABLET_HARNESS_H