YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/integration-tests/mini_cluster_utils.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 "yb/integration-tests/mini_cluster_utils.h"
15
16
#include "yb/integration-tests/mini_cluster.h"
17
18
#include "yb/tablet/tablet.h"
19
#include "yb/tablet/tablet_peer.h"
20
#include "yb/tablet/transaction_participant.h"
21
22
#include "yb/tserver/mini_tablet_server.h"
23
#include "yb/tserver/tablet_server.h"
24
#include "yb/tserver/ts_tablet_manager.h"
25
26
#include "yb/util/test_util.h"
27
#include "yb/util/tsan_util.h"
28
29
using namespace std::literals;
30
31
namespace yb {
32
33
0
size_t CountRunningTransactions(MiniCluster* cluster) {
34
0
  size_t result = 0;
35
0
  auto peers = ListTabletPeers(cluster, ListPeersFilter::kAll);
36
0
  for (const auto &peer : peers) {
37
0
    auto participant = peer->tablet()->transaction_participant();
38
0
    result += participant ? participant->TEST_GetNumRunningTransactions() : 0;
39
0
  }
40
0
  return result;
41
0
}
42
43
void AssertRunningTransactionsCountLessOrEqualTo(MiniCluster* cluster,
44
0
                                                 size_t max_remaining_txns_per_tablet) {
45
0
  MonoTime deadline = MonoTime::Now() + 15s * kTimeMultiplier;
46
0
  bool has_bad = false;
47
0
  for (size_t i = 0; i != cluster->num_tablet_servers(); ++i) {
48
0
    auto server = cluster->mini_tablet_server(i)->server();
49
0
    std::vector<std::shared_ptr<tablet::TabletPeer>> tablets;
50
0
    auto status = Wait([server, &tablets] {
51
0
          tablets = server->tablet_manager()->GetTabletPeers();
52
0
          for (const auto& peer : tablets) {
53
0
            if (peer->tablet() == nullptr) {
54
0
              return false;
55
0
            }
56
0
          }
57
0
          return true;
58
0
        }, deadline, "Wait until all peers have tablets");
59
0
    if (!status.ok()) {
60
0
      has_bad = true;
61
0
      for (const auto& peer : tablets) {
62
0
        if (peer->tablet() == nullptr) {
63
0
          LOG(ERROR) << Format(
64
0
              "T $1 P $0: Tablet object is not created",
65
0
              server->permanent_uuid(), peer->tablet_id());
66
0
        }
67
0
      }
68
0
      continue;
69
0
    }
70
0
    for (const auto& peer : tablets) {
71
0
      auto participant = peer->tablet()->transaction_participant();
72
0
      if (participant) {
73
0
        auto status = Wait([participant, max_remaining_txns_per_tablet] {
74
0
              return participant->TEST_GetNumRunningTransactions() <= max_remaining_txns_per_tablet;
75
0
            },
76
0
            deadline,
77
0
            "Wait until no transactions are running");
78
0
        if (!status.ok()) {
79
0
          LOG(ERROR) << Format(
80
0
              "T $1 P $0: Transactions: $2",
81
0
              server->permanent_uuid(), peer->tablet_id(),
82
0
              participant->TEST_GetNumRunningTransactions());
83
0
          has_bad = true;
84
0
        }
85
0
      }
86
0
    }
87
0
  }
88
0
  ASSERT_FALSE(has_bad);
89
0
}
90
91
0
void AssertNoRunningTransactions(MiniCluster* cluster) {
92
0
  AssertRunningTransactionsCountLessOrEqualTo(cluster, 0);
93
0
}
94
95
} // namespace yb