YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/master/flush_manager-test.cc
Line
Count
Source (jump to first uncovered line)
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
#include <string>
16
17
#include <gtest/gtest.h>
18
19
#include "yb/client/client.h"
20
#include "yb/client/table.h"
21
#include "yb/client/yb_table_name.h"
22
23
#include "yb/integration-tests/cql_test_base.h"
24
25
#include "yb/tablet/tablet.h"
26
#include "yb/tablet/tablet_bootstrap_if.h"
27
#include "yb/tablet/tablet_metadata.h"
28
#include "yb/tablet/tablet_peer.h"
29
30
#include "yb/util/status.h"
31
32
namespace yb {
33
namespace master {
34
35
const string kNamespace = "test";
36
37
class FlushManagerTest : public CqlTestBase<MiniCluster> {
38
 protected:
39
40
0
  Result<OpId> GetOpIdAtLeader(const string& table_id) {
41
0
    auto all_peers = ListTabletPeers(cluster_.get(), ListPeersFilter::kAll);
42
0
    for (const auto& peer : all_peers) {
43
0
      if (peer->tablet()->metadata()->table_id() == table_id) {
44
0
        return VERIFY_RESULT(peer->tablet()->MaxPersistentOpId()).regular;
45
0
      }
46
0
    }
47
0
    return STATUS(IllegalState, "No leader found for table.");
48
0
  }
49
50
0
  Result<OpId> GetMaxOpId(const string& table_id) {
51
0
    auto all_peers = ListTabletPeers(cluster_.get(), ListPeersFilter::kAll);
52
0
    OpId max_op_id(0, 0);
53
0
    for (const auto& peer : all_peers) {
54
0
      if (peer->tablet()->metadata()->table_id() == table_id) {
55
0
        max_op_id = std::max(max_op_id, VERIFY_RESULT(peer->tablet()->MaxPersistentOpId()).regular);
56
0
      }
57
0
    }
58
0
    return max_op_id;
59
0
  }
60
};
61
62
0
TEST_F(FlushManagerTest, VerifyFlush) {
63
0
  auto session = ASSERT_RESULT(EstablishSession(driver_.get()));
64
0
  ASSERT_OK(
65
0
      session.ExecuteQuery("CREATE TABLE IF NOT EXISTS t (key INT PRIMARY KEY, value INT) WITH "
66
0
                           "transactions = { 'enabled' : true } and tablets = 1"));
67
0
  ASSERT_OK(session.ExecuteQuery("CREATE INDEX IF NOT EXISTS idx ON T (value) WITH tablets = 1"));
68
69
0
  const client::YBTableName table_name(YQL_DATABASE_CQL, kNamespace, "t");
70
0
  const client::YBTableName index_name(YQL_DATABASE_CQL, kNamespace, "idx");
71
72
0
  auto table = ASSERT_RESULT(client_->OpenTable(table_name));
73
0
  auto index = ASSERT_RESULT(client_->OpenTable(index_name));
74
75
0
  ASSERT_OK(session.ExecuteQuery("INSERT INTO t(key, value) VALUES (1, 2)"));
76
77
0
  auto baseline_table_op_id = ASSERT_RESULT(GetOpIdAtLeader(table->id()));
78
0
  auto baseline_index_op_id = ASSERT_RESULT(GetOpIdAtLeader(index->id()));
79
0
  ASSERT_OK(client_->FlushTables({table->name()}, true, 30, false));
80
0
  EXPECT_GT(ASSERT_RESULT(GetMaxOpId(table->id())), baseline_table_op_id);
81
0
  EXPECT_GT(ASSERT_RESULT(GetMaxOpId(index->id())), baseline_index_op_id);
82
0
}
83
84
85
} // namespace master
86
} // namespace yb