Coverage Report

Created: 2026-09-28 07:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/rocksdb/utilities/transactions/lock/lock_manager.h
Line
Count
Source
1
// Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2
// This source code is licensed under both the GPLv2 (found in the
3
// COPYING file in the root directory) and Apache 2.0 License
4
// (found in the LICENSE.Apache file in the root directory).
5
6
#pragma once
7
8
#include "rocksdb/types.h"
9
#include "rocksdb/utilities/transaction.h"
10
#include "rocksdb/utilities/transaction_db.h"
11
#include "utilities/transactions/lock/lock_tracker.h"
12
#include "utilities/transactions/pessimistic_transaction.h"
13
14
namespace ROCKSDB_NAMESPACE {
15
16
class PessimisticTransactionDB;
17
18
class LockManager {
19
 public:
20
0
  virtual ~LockManager() {}
21
22
  // Whether supports locking a specific key.
23
  virtual bool IsPointLockSupported() const = 0;
24
25
  // Whether supports locking a range of keys.
26
  virtual bool IsRangeLockSupported() const = 0;
27
28
  // Locks acquired through this LockManager should be tracked by
29
  // the LockTrackers created through the returned factory.
30
  virtual const LockTrackerFactory& GetLockTrackerFactory() const = 0;
31
32
  // Enable locking for the specified column family.
33
  // Caller should guarantee that this column family is not already enabled.
34
  virtual void AddColumnFamily(const ColumnFamilyHandle* cf) = 0;
35
36
  // Disable locking for the specified column family.
37
  // Caller should guarantee that this column family is no longer used.
38
  virtual void RemoveColumnFamily(const ColumnFamilyHandle* cf) = 0;
39
40
  // Attempt to lock a key or a key range.  If OK status is returned, the caller
41
  // is responsible for calling UnLock() on this key.
42
  virtual Status TryLock(PessimisticTransaction* txn,
43
                         ColumnFamilyId column_family_id,
44
                         const std::string& key, Env* env, bool exclusive) = 0;
45
  // The range [start, end] are inclusive at both sides.
46
  virtual Status TryLock(PessimisticTransaction* txn,
47
                         ColumnFamilyId column_family_id, const Endpoint& start,
48
                         const Endpoint& end, Env* env, bool exclusive) = 0;
49
50
  // Unlock a key or a range locked by TryLock().  txn must be the same
51
  // Transaction that locked this key.
52
  virtual void UnLock(PessimisticTransaction* txn, const LockTracker& tracker,
53
                      Env* env) = 0;
54
  virtual void UnLock(PessimisticTransaction* txn,
55
                      ColumnFamilyId column_family_id, const std::string& key,
56
                      Env* env) = 0;
57
  virtual void UnLock(PessimisticTransaction* txn,
58
                      ColumnFamilyId column_family_id, const Endpoint& start,
59
                      const Endpoint& end, Env* env) = 0;
60
61
  using PointLockStatus = std::unordered_multimap<ColumnFamilyId, KeyLockInfo>;
62
  virtual PointLockStatus GetPointLockStatus() = 0;
63
64
  using RangeLockStatus =
65
      std::unordered_multimap<ColumnFamilyId, RangeLockInfo>;
66
  virtual RangeLockStatus GetRangeLockStatus() = 0;
67
68
  virtual std::vector<DeadlockPath> GetDeadlockInfoBuffer() = 0;
69
70
  virtual void Resize(uint32_t new_size) = 0;
71
};
72
73
// LockManager should always be constructed through this factory method,
74
// instead of constructing through concrete implementations' constructor.
75
// Caller owns the returned pointer.
76
std::shared_ptr<LockManager> NewLockManager(PessimisticTransactionDB* db,
77
                                            const TransactionDBOptions& opt);
78
79
}  // namespace ROCKSDB_NAMESPACE