YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/docdb/lock_batch.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
14
#include "yb/docdb/lock_batch.h"
15
16
#include "yb/docdb/shared_lock_manager.h"
17
18
#include "yb/util/status_format.h"
19
20
DEFINE_bool(dump_lock_keys, true,
21
            "Whether to add keys to error message when lock batch timed out");
22
23
namespace yb {
24
namespace docdb {
25
26
LockBatch::LockBatch(SharedLockManager* lock_manager, LockBatchEntries&& key_to_intent_type,
27
                     CoarseTimePoint deadline)
28
7.93M
    : data_(std::move(key_to_intent_type), lock_manager) {
29
7.93M
  if (!empty() && 
!lock_manager->Lock(&data_.key_to_type, deadline)7.92M
) {
30
212
    data_.shared_lock_manager = nullptr;
31
212
    std::string batch_str;
32
212
    if (FLAGS_dump_lock_keys) {
33
212
      batch_str = Format(", batch: $0", data_.key_to_type);
34
212
    }
35
212
    data_.key_to_type.clear();
36
212
    data_.status = STATUS_FORMAT(
37
212
        TryAgain, "Failed to obtain locks until deadline: $0$1", deadline, batch_str);
38
212
  }
39
7.93M
}
40
41
24.2M
LockBatch::~LockBatch() {
42
24.2M
  Reset();
43
24.2M
}
44
45
43.5M
void LockBatch::Reset() {
46
43.5M
  if (!empty()) {
47
7.93M
    VLOG
(1) << "Auto-unlocking a LockBatch with " << size() << " keys"244
;
48
7.93M
    DCHECK_NOTNULL(data_.shared_lock_manager)->Unlock(data_.key_to_type);
49
7.93M
    data_.key_to_type.clear();
50
7.93M
  }
51
43.5M
}
52
53
16.0M
void LockBatch::MoveFrom(LockBatch* other) {
54
16.0M
  Reset();
55
16.0M
  data_ = std::move(other->data_);
56
  // Explicitly clear other key_to_type to avoid extra unlock when it is destructed. We use
57
  // key_to_type emptiness to mark that it does not hold a lock.
58
16.0M
  other->data_.key_to_type.clear();
59
16.0M
}
60
61
232
std::string LockBatchEntry::ToString() const {
62
232
  return Format("{ key: $0 intent_types: $1 }", key.as_slice().ToDebugHexString(), intent_types);
63
232
}
64
65
}  // namespace docdb
66
}  // namespace yb