YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/docdb/deadline_info.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/docdb/deadline_info.h"
15
16
#include <string>
17
18
#include <gflags/gflags.h>
19
20
#include "yb/util/flag_tags.h"
21
#include "yb/util/format.h"
22
23
using namespace std::literals;
24
25
DEFINE_test_flag(bool, tserver_timeout, false,
26
                 "Sleep past the deadline to test tserver query expiration");
27
28
namespace yb {
29
namespace docdb {
30
31
14.3M
DeadlineInfo::DeadlineInfo(CoarseTimePoint deadline) : deadline_(deadline) {}
32
33
// Every 1024 iterations, check whether the deadline passed and if so, change deadline_passed_
34
// before returning.
35
750M
bool DeadlineInfo::CheckAndSetDeadlinePassed() {
36
750M
  if (deadline_passed_) {
37
0
    return true;
38
0
  }
39
751M
  
if (750M
(750M
PREDICT_FALSE750M
(FLAGS_TEST_tserver_timeout) || (++counter_ & 1023) == 0)
40
750M
      && 
CoarseMonoClock::now() > deadline_591k
) {
41
0
    deadline_passed_ = true;
42
0
  }
43
750M
  return deadline_passed_;
44
750M
}
45
46
0
std::string DeadlineInfo::ToString() const {
47
0
  return Format("{ now: $0 deadline: $1 counter: $2 }",
48
0
                CoarseMonoClock::now(), deadline_, counter_);
49
0
}
50
51
7.62M
void SimulateTimeoutIfTesting(CoarseTimePoint* deadline) {
52
7.62M
  if (PREDICT_FALSE(FLAGS_TEST_tserver_timeout)) {
53
0
    *deadline = CoarseMonoClock::now() - 100ms;
54
0
  }
55
7.62M
}
56
57
} // namespace docdb
58
} // namespace yb