]>
Commit | Line | Data |
---|---|---|
20effc67 TL |
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 | |
1e59de90 | 7 | #ifndef ROCKSDB_LITE |
20effc67 TL |
8 | |
9 | #include <memory> | |
10 | #include <string> | |
11 | #include <unordered_map> | |
12 | ||
13 | #include "utilities/transactions/lock/lock_tracker.h" | |
14 | ||
15 | namespace ROCKSDB_NAMESPACE { | |
16 | ||
17 | struct TrackedKeyInfo { | |
18 | // Earliest sequence number that is relevant to this transaction for this key | |
19 | SequenceNumber seq; | |
20 | ||
21 | uint32_t num_writes; | |
22 | uint32_t num_reads; | |
23 | ||
24 | bool exclusive; | |
25 | ||
26 | explicit TrackedKeyInfo(SequenceNumber seq_no) | |
27 | : seq(seq_no), num_writes(0), num_reads(0), exclusive(false) {} | |
28 | ||
29 | void Merge(const TrackedKeyInfo& info) { | |
30 | assert(seq <= info.seq); | |
31 | num_reads += info.num_reads; | |
32 | num_writes += info.num_writes; | |
33 | exclusive = exclusive || info.exclusive; | |
34 | } | |
35 | }; | |
36 | ||
37 | using TrackedKeyInfos = std::unordered_map<std::string, TrackedKeyInfo>; | |
38 | ||
39 | using TrackedKeys = std::unordered_map<ColumnFamilyId, TrackedKeyInfos>; | |
40 | ||
41 | // Tracks point locks on single keys. | |
42 | class PointLockTracker : public LockTracker { | |
43 | public: | |
44 | PointLockTracker() = default; | |
45 | ||
46 | PointLockTracker(const PointLockTracker&) = delete; | |
47 | PointLockTracker& operator=(const PointLockTracker&) = delete; | |
48 | ||
49 | bool IsPointLockSupported() const override { return true; } | |
50 | ||
51 | bool IsRangeLockSupported() const override { return false; } | |
52 | ||
53 | void Track(const PointLockRequest& lock_request) override; | |
54 | ||
55 | UntrackStatus Untrack(const PointLockRequest& lock_request) override; | |
56 | ||
57 | void Track(const RangeLockRequest& /*lock_request*/) override {} | |
58 | ||
59 | UntrackStatus Untrack(const RangeLockRequest& /*lock_request*/) override { | |
60 | return UntrackStatus::NOT_TRACKED; | |
61 | } | |
62 | ||
63 | void Merge(const LockTracker& tracker) override; | |
64 | ||
65 | void Subtract(const LockTracker& tracker) override; | |
66 | ||
67 | void Clear() override; | |
68 | ||
69 | virtual LockTracker* GetTrackedLocksSinceSavePoint( | |
70 | const LockTracker& save_point_tracker) const override; | |
71 | ||
72 | PointLockStatus GetPointLockStatus(ColumnFamilyId column_family_id, | |
73 | const std::string& key) const override; | |
74 | ||
75 | uint64_t GetNumPointLocks() const override; | |
76 | ||
77 | ColumnFamilyIterator* GetColumnFamilyIterator() const override; | |
78 | ||
79 | KeyIterator* GetKeyIterator(ColumnFamilyId column_family_id) const override; | |
80 | ||
81 | private: | |
82 | TrackedKeys tracked_keys_; | |
83 | }; | |
84 | ||
85 | class PointLockTrackerFactory : public LockTrackerFactory { | |
86 | public: | |
87 | static const PointLockTrackerFactory& Get() { | |
88 | static const PointLockTrackerFactory instance; | |
89 | return instance; | |
90 | } | |
91 | ||
92 | LockTracker* Create() const override { return new PointLockTracker(); } | |
93 | ||
94 | private: | |
95 | PointLockTrackerFactory() {} | |
96 | }; | |
97 | ||
98 | } // namespace ROCKSDB_NAMESPACE | |
1e59de90 | 99 | #endif // ROCKSDB_LITE |