Abstract out LockManager interface (#7532)
Summary: In order to be able to introduce more locking protocols, we need to abstract out the locking subsystem in TransactionDB into a set of interfaces. PR https://github.com/facebook/rocksdb/pull/7013 introduces interface `LockTracker`. This PR is a follow up to take the first step to abstract out a `LockManager` interface. Further modifications to the interface may be needed when introducing the first implementation of range lock. But the idea here is to put the range lock implementation based on range tree under the `utilities/transactions/lock/range/range_tree`. Pull Request resolved: https://github.com/facebook/rocksdb/pull/7532 Test Plan: point_lock_manager_test Reviewed By: ajkr Differential Revision: D24238731 Pulled By: cheng-chang fbshipit-source-id: 2a9458cd8b3fb008d9529dbc4d3b28c24631f463main
parent
ed90e2a450
commit
0ea7db768e
@ -0,0 +1,23 @@ |
|||||||
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
||||||
|
// This source code is licensed under both the GPLv2 (found in the
|
||||||
|
// COPYING file in the root directory) and Apache 2.0 License
|
||||||
|
// (found in the LICENSE.Apache file in the root directory).
|
||||||
|
|
||||||
|
#ifndef ROCKSDB_LITE |
||||||
|
|
||||||
|
#include "utilities/transactions/lock/lock_manager.h" |
||||||
|
|
||||||
|
#include "utilities/transactions/lock/point/point_lock_manager.h" |
||||||
|
|
||||||
|
namespace ROCKSDB_NAMESPACE { |
||||||
|
|
||||||
|
LockManager* NewLockManager(PessimisticTransactionDB* db, |
||||||
|
const TransactionDBOptions& opt) { |
||||||
|
assert(db); |
||||||
|
// TODO: determine the lock manager implementation based on configuration.
|
||||||
|
return new PointLockManager(db, opt); |
||||||
|
} |
||||||
|
|
||||||
|
} // namespace ROCKSDB_NAMESPACE
|
||||||
|
|
||||||
|
#endif // ROCKSDB_LITE
|
@ -0,0 +1,82 @@ |
|||||||
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
||||||
|
// This source code is licensed under both the GPLv2 (found in the
|
||||||
|
// COPYING file in the root directory) and Apache 2.0 License
|
||||||
|
// (found in the LICENSE.Apache file in the root directory).
|
||||||
|
|
||||||
|
#pragma once |
||||||
|
#ifndef ROCKSDB_LITE |
||||||
|
|
||||||
|
#include "rocksdb/types.h" |
||||||
|
#include "rocksdb/utilities/transaction.h" |
||||||
|
#include "rocksdb/utilities/transaction_db.h" |
||||||
|
#include "utilities/transactions/lock/lock_tracker.h" |
||||||
|
#include "utilities/transactions/pessimistic_transaction.h" |
||||||
|
|
||||||
|
namespace ROCKSDB_NAMESPACE { |
||||||
|
|
||||||
|
class PessimisticTransactionDB; |
||||||
|
|
||||||
|
class LockManager { |
||||||
|
public: |
||||||
|
virtual ~LockManager() {} |
||||||
|
|
||||||
|
// Whether supports locking a specific key.
|
||||||
|
virtual bool IsPointLockSupported() const = 0; |
||||||
|
|
||||||
|
// Whether supports locking a range of keys.
|
||||||
|
virtual bool IsRangeLockSupported() const = 0; |
||||||
|
|
||||||
|
// Locks acquired through this LockManager should be tracked by
|
||||||
|
// the LockTrackers created through the returned factory.
|
||||||
|
virtual const LockTrackerFactory& GetLockTrackerFactory() const = 0; |
||||||
|
|
||||||
|
// Enable locking for the specified column family.
|
||||||
|
// Caller should guarantee that this column family is not already enabled.
|
||||||
|
virtual void AddColumnFamily(const ColumnFamilyHandle* cf) = 0; |
||||||
|
|
||||||
|
// Disable locking for the specified column family.
|
||||||
|
// Caller should guarantee that this column family is no longer used.
|
||||||
|
virtual void RemoveColumnFamily(const ColumnFamilyHandle* cf) = 0; |
||||||
|
|
||||||
|
// Attempt to lock a key or a key range. If OK status is returned, the caller
|
||||||
|
// is responsible for calling UnLock() on this key.
|
||||||
|
virtual Status TryLock(PessimisticTransaction* txn, |
||||||
|
ColumnFamilyId column_family_id, |
||||||
|
const std::string& key, Env* env, bool exclusive) = 0; |
||||||
|
// The range [start, end] are inclusive at both sides.
|
||||||
|
virtual Status TryLock(PessimisticTransaction* txn, |
||||||
|
ColumnFamilyId column_family_id, const Endpoint& start, |
||||||
|
const Endpoint& end, Env* env, bool exclusive) = 0; |
||||||
|
|
||||||
|
// Unlock a key or a range locked by TryLock(). txn must be the same
|
||||||
|
// Transaction that locked this key.
|
||||||
|
virtual void UnLock(PessimisticTransaction* txn, const LockTracker& tracker, |
||||||
|
Env* env) = 0; |
||||||
|
virtual void UnLock(PessimisticTransaction* txn, |
||||||
|
ColumnFamilyId column_family_id, const std::string& key, |
||||||
|
Env* env) = 0; |
||||||
|
virtual void UnLock(PessimisticTransaction* txn, |
||||||
|
ColumnFamilyId column_family_id, const Endpoint& start, |
||||||
|
const Endpoint& end, Env* env) = 0; |
||||||
|
|
||||||
|
using PointLockStatus = std::unordered_multimap<ColumnFamilyId, KeyLockInfo>; |
||||||
|
virtual PointLockStatus GetPointLockStatus() = 0; |
||||||
|
|
||||||
|
using RangeLockStatus = |
||||||
|
std::unordered_multimap<ColumnFamilyId, RangeLockInfo>; |
||||||
|
virtual RangeLockStatus GetRangeLockStatus() = 0; |
||||||
|
|
||||||
|
virtual std::vector<DeadlockPath> GetDeadlockInfoBuffer() = 0; |
||||||
|
|
||||||
|
virtual void Resize(uint32_t new_size) = 0; |
||||||
|
}; |
||||||
|
|
||||||
|
// LockManager should always be constructed through this factory method,
|
||||||
|
// instead of constructing through concrete implementations' constructor.
|
||||||
|
// Caller owns the returned pointer.
|
||||||
|
LockManager* NewLockManager(PessimisticTransactionDB* db, |
||||||
|
const TransactionDBOptions& opt); |
||||||
|
|
||||||
|
} // namespace ROCKSDB_NAMESPACE
|
||||||
|
|
||||||
|
#endif // ROCKSDB_LITE
|
@ -1,17 +0,0 @@ |
|||||||
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
||||||
// This source code is licensed under both the GPLv2 (found in the
|
|
||||||
// COPYING file in the root directory) and Apache 2.0 License
|
|
||||||
// (found in the LICENSE.Apache file in the root directory).
|
|
||||||
|
|
||||||
#include "utilities/transactions/lock/lock_tracker.h" |
|
||||||
|
|
||||||
#include "utilities/transactions/lock/point_lock_tracker.h" |
|
||||||
|
|
||||||
namespace ROCKSDB_NAMESPACE { |
|
||||||
|
|
||||||
LockTracker* NewLockTracker() { |
|
||||||
// TODO: determine the lock tracker implementation based on configuration.
|
|
||||||
return new PointLockTracker(); |
|
||||||
} |
|
||||||
|
|
||||||
} // namespace ROCKSDB_NAMESPACE
|
|
@ -0,0 +1 @@ |
|||||||
|
Implement LockTracker and LockManager for range lock with range tree. |
Loading…
Reference in new issue