2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// 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).
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
|
2020-10-19 19:12:53 +02:00
|
|
|
#include "utilities/transactions/lock/point/point_lock_manager.h"
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
|
|
|
|
#include <algorithm>
|
2020-10-19 19:12:53 +02:00
|
|
|
#include <cinttypes>
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
#include <mutex>
|
|
|
|
|
2017-11-06 19:52:17 +01:00
|
|
|
#include "monitoring/perf_context_imp.h"
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
#include "rocksdb/slice.h"
|
2015-09-08 21:36:48 +02:00
|
|
|
#include "rocksdb/utilities/transaction_db_mutex.h"
|
2019-05-31 02:39:43 +02:00
|
|
|
#include "test_util/sync_point.h"
|
2017-07-29 01:23:50 +02:00
|
|
|
#include "util/cast_util.h"
|
2019-04-08 22:24:29 +02:00
|
|
|
#include "util/hash.h"
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
#include "util/thread_local.h"
|
2017-08-06 02:17:48 +02:00
|
|
|
#include "utilities/transactions/pessimistic_transaction_db.h"
|
2020-10-19 19:12:53 +02:00
|
|
|
#include "utilities/transactions/transaction_db_mutex_impl.h"
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
|
|
|
|
struct LockInfo {
|
2016-12-06 02:18:14 +01:00
|
|
|
bool exclusive;
|
|
|
|
autovector<TransactionID> txn_ids;
|
2015-09-08 21:36:48 +02:00
|
|
|
|
|
|
|
// Transaction locks are not valid after this time in us
|
|
|
|
uint64_t expiration_time;
|
|
|
|
|
2016-12-06 02:18:14 +01:00
|
|
|
LockInfo(TransactionID id, uint64_t time, bool ex)
|
|
|
|
: exclusive(ex), expiration_time(time) {
|
|
|
|
txn_ids.push_back(id);
|
|
|
|
}
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
LockInfo(const LockInfo& lock_info)
|
2016-12-06 02:18:14 +01:00
|
|
|
: exclusive(lock_info.exclusive),
|
|
|
|
txn_ids(lock_info.txn_ids),
|
|
|
|
expiration_time(lock_info.expiration_time) {}
|
2020-10-19 19:12:53 +02:00
|
|
|
void operator=(const LockInfo& lock_info) {
|
|
|
|
exclusive = lock_info.exclusive;
|
|
|
|
txn_ids = lock_info.txn_ids;
|
|
|
|
expiration_time = lock_info.expiration_time;
|
|
|
|
}
|
Meta-internal folly integration with F14FastMap (#9546)
Summary:
Especially after updating to C++17, I don't see a compelling case for
*requiring* any folly components in RocksDB. I was able to purge the existing
hard dependencies, and it can be quite difficult to strip out non-trivial components
from folly for use in RocksDB. (The prospect of doing that on F14 has changed
my mind on the best approach here.)
But this change creates an optional integration where we can plug in
components from folly at compile time, starting here with F14FastMap to replace
std::unordered_map when possible (probably no public APIs for example). I have
replaced the biggest CPU users of std::unordered_map with compile-time
pluggable UnorderedMap which will use F14FastMap when USE_FOLLY is set.
USE_FOLLY is always set in the Meta-internal buck build, and a simulation of
that is in the Makefile for public CI testing. A full folly build is not needed, but
checking out the full folly repo is much simpler for getting the dependency,
and anything else we might want to optionally integrate in the future.
Some picky details:
* I don't think the distributed mutex stuff is actually used, so it was easy to remove.
* I implemented an alternative to `folly::constexpr_log2` (which is much easier
in C++17 than C++11) so that I could pull out the hard dependencies on
`ConstexprMath.h`
* I had to add noexcept move constructors/operators to some types to make
F14's complainUnlessNothrowMoveAndDestroy check happy, and I added a
macro to make that easier in some common cases.
* Updated Meta-internal buck build to use folly F14Map (always)
No updates to HISTORY.md nor INSTALL.md as this is not (yet?) considered a
production integration for open source users.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/9546
Test Plan:
CircleCI tests updated so that a couple of them use folly.
Most internal unit & stress/crash tests updated to use Meta-internal latest folly.
(Note: they should probably use buck but they currently use Makefile.)
Example performance improvement: when filter partitions are pinned in cache,
they are tracked by PartitionedFilterBlockReader::filter_map_ and we can build
a test that exercises that heavily. Build DB with
```
TEST_TMPDIR=/dev/shm/rocksdb ./db_bench -benchmarks=fillrandom -num=10000000 -disable_wal=1 -write_buffer_size=30000000 -bloom_bits=16 -compaction_style=2 -fifo_compaction_max_table_files_size_mb=10000 -fifo_compaction_allow_compaction=0 -partition_index_and_filters
```
and test with (simultaneous runs with & without folly, ~20 times each to see
convergence)
```
TEST_TMPDIR=/dev/shm/rocksdb ./db_bench_folly -readonly -use_existing_db -benchmarks=readrandom -num=10000000 -bloom_bits=16 -compaction_style=2 -fifo_compaction_max_table_files_size_mb=10000 -fifo_compaction_allow_compaction=0 -partition_index_and_filters -duration=40 -pin_l0_filter_and_index_blocks_in_cache
```
Average ops/s no folly: 26229.2
Average ops/s with folly: 26853.3 (+2.4%)
Reviewed By: ajkr
Differential Revision: D34181736
Pulled By: pdillinger
fbshipit-source-id: ffa6ad5104c2880321d8a1aa7187e00ab0d02e94
2022-04-13 16:34:01 +02:00
|
|
|
DECLARE_DEFAULT_MOVES(LockInfo);
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct LockMapStripe {
|
2015-09-08 21:36:48 +02:00
|
|
|
explicit LockMapStripe(std::shared_ptr<TransactionDBMutexFactory> factory) {
|
|
|
|
stripe_mutex = factory->AllocateMutex();
|
|
|
|
stripe_cv = factory->AllocateCondVar();
|
|
|
|
assert(stripe_mutex);
|
|
|
|
assert(stripe_cv);
|
|
|
|
}
|
|
|
|
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
// Mutex must be held before modifying keys map
|
2015-09-08 21:36:48 +02:00
|
|
|
std::shared_ptr<TransactionDBMutex> stripe_mutex;
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
|
|
|
|
// Condition Variable per stripe for waiting on a lock
|
2015-09-08 21:36:48 +02:00
|
|
|
std::shared_ptr<TransactionDBCondVar> stripe_cv;
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
|
|
|
|
// Locked keys mapped to the info about the transactions that locked them.
|
|
|
|
// TODO(agiardullo): Explore performance of other data structures.
|
Meta-internal folly integration with F14FastMap (#9546)
Summary:
Especially after updating to C++17, I don't see a compelling case for
*requiring* any folly components in RocksDB. I was able to purge the existing
hard dependencies, and it can be quite difficult to strip out non-trivial components
from folly for use in RocksDB. (The prospect of doing that on F14 has changed
my mind on the best approach here.)
But this change creates an optional integration where we can plug in
components from folly at compile time, starting here with F14FastMap to replace
std::unordered_map when possible (probably no public APIs for example). I have
replaced the biggest CPU users of std::unordered_map with compile-time
pluggable UnorderedMap which will use F14FastMap when USE_FOLLY is set.
USE_FOLLY is always set in the Meta-internal buck build, and a simulation of
that is in the Makefile for public CI testing. A full folly build is not needed, but
checking out the full folly repo is much simpler for getting the dependency,
and anything else we might want to optionally integrate in the future.
Some picky details:
* I don't think the distributed mutex stuff is actually used, so it was easy to remove.
* I implemented an alternative to `folly::constexpr_log2` (which is much easier
in C++17 than C++11) so that I could pull out the hard dependencies on
`ConstexprMath.h`
* I had to add noexcept move constructors/operators to some types to make
F14's complainUnlessNothrowMoveAndDestroy check happy, and I added a
macro to make that easier in some common cases.
* Updated Meta-internal buck build to use folly F14Map (always)
No updates to HISTORY.md nor INSTALL.md as this is not (yet?) considered a
production integration for open source users.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/9546
Test Plan:
CircleCI tests updated so that a couple of them use folly.
Most internal unit & stress/crash tests updated to use Meta-internal latest folly.
(Note: they should probably use buck but they currently use Makefile.)
Example performance improvement: when filter partitions are pinned in cache,
they are tracked by PartitionedFilterBlockReader::filter_map_ and we can build
a test that exercises that heavily. Build DB with
```
TEST_TMPDIR=/dev/shm/rocksdb ./db_bench -benchmarks=fillrandom -num=10000000 -disable_wal=1 -write_buffer_size=30000000 -bloom_bits=16 -compaction_style=2 -fifo_compaction_max_table_files_size_mb=10000 -fifo_compaction_allow_compaction=0 -partition_index_and_filters
```
and test with (simultaneous runs with & without folly, ~20 times each to see
convergence)
```
TEST_TMPDIR=/dev/shm/rocksdb ./db_bench_folly -readonly -use_existing_db -benchmarks=readrandom -num=10000000 -bloom_bits=16 -compaction_style=2 -fifo_compaction_max_table_files_size_mb=10000 -fifo_compaction_allow_compaction=0 -partition_index_and_filters -duration=40 -pin_l0_filter_and_index_blocks_in_cache
```
Average ops/s no folly: 26229.2
Average ops/s with folly: 26853.3 (+2.4%)
Reviewed By: ajkr
Differential Revision: D34181736
Pulled By: pdillinger
fbshipit-source-id: ffa6ad5104c2880321d8a1aa7187e00ab0d02e94
2022-04-13 16:34:01 +02:00
|
|
|
UnorderedMap<std::string, LockInfo> keys;
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Map of #num_stripes LockMapStripes
|
|
|
|
struct LockMap {
|
2015-09-08 21:36:48 +02:00
|
|
|
explicit LockMap(size_t num_stripes,
|
|
|
|
std::shared_ptr<TransactionDBMutexFactory> factory)
|
|
|
|
: num_stripes_(num_stripes) {
|
|
|
|
lock_map_stripes_.reserve(num_stripes);
|
|
|
|
for (size_t i = 0; i < num_stripes; i++) {
|
|
|
|
LockMapStripe* stripe = new LockMapStripe(factory);
|
|
|
|
lock_map_stripes_.push_back(stripe);
|
|
|
|
}
|
|
|
|
}
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
|
2015-09-08 21:36:48 +02:00
|
|
|
~LockMap() {
|
|
|
|
for (auto stripe : lock_map_stripes_) {
|
|
|
|
delete stripe;
|
|
|
|
}
|
|
|
|
}
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
|
|
|
|
// Number of sepearate LockMapStripes to create, each with their own Mutex
|
|
|
|
const size_t num_stripes_;
|
|
|
|
|
|
|
|
// Count of keys that are currently locked in this column family.
|
2020-10-19 19:12:53 +02:00
|
|
|
// (Only maintained if PointLockManager::max_num_locks_ is positive.)
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
std::atomic<int64_t> lock_cnt{0};
|
|
|
|
|
2015-09-08 21:36:48 +02:00
|
|
|
std::vector<LockMapStripe*> lock_map_stripes_;
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
|
|
|
|
size_t GetStripe(const std::string& key) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
void UnrefLockMapsCache(void* ptr) {
|
|
|
|
// Called when a thread exits or a ThreadLocalPtr gets destroyed.
|
|
|
|
auto lock_maps_cache =
|
Meta-internal folly integration with F14FastMap (#9546)
Summary:
Especially after updating to C++17, I don't see a compelling case for
*requiring* any folly components in RocksDB. I was able to purge the existing
hard dependencies, and it can be quite difficult to strip out non-trivial components
from folly for use in RocksDB. (The prospect of doing that on F14 has changed
my mind on the best approach here.)
But this change creates an optional integration where we can plug in
components from folly at compile time, starting here with F14FastMap to replace
std::unordered_map when possible (probably no public APIs for example). I have
replaced the biggest CPU users of std::unordered_map with compile-time
pluggable UnorderedMap which will use F14FastMap when USE_FOLLY is set.
USE_FOLLY is always set in the Meta-internal buck build, and a simulation of
that is in the Makefile for public CI testing. A full folly build is not needed, but
checking out the full folly repo is much simpler for getting the dependency,
and anything else we might want to optionally integrate in the future.
Some picky details:
* I don't think the distributed mutex stuff is actually used, so it was easy to remove.
* I implemented an alternative to `folly::constexpr_log2` (which is much easier
in C++17 than C++11) so that I could pull out the hard dependencies on
`ConstexprMath.h`
* I had to add noexcept move constructors/operators to some types to make
F14's complainUnlessNothrowMoveAndDestroy check happy, and I added a
macro to make that easier in some common cases.
* Updated Meta-internal buck build to use folly F14Map (always)
No updates to HISTORY.md nor INSTALL.md as this is not (yet?) considered a
production integration for open source users.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/9546
Test Plan:
CircleCI tests updated so that a couple of them use folly.
Most internal unit & stress/crash tests updated to use Meta-internal latest folly.
(Note: they should probably use buck but they currently use Makefile.)
Example performance improvement: when filter partitions are pinned in cache,
they are tracked by PartitionedFilterBlockReader::filter_map_ and we can build
a test that exercises that heavily. Build DB with
```
TEST_TMPDIR=/dev/shm/rocksdb ./db_bench -benchmarks=fillrandom -num=10000000 -disable_wal=1 -write_buffer_size=30000000 -bloom_bits=16 -compaction_style=2 -fifo_compaction_max_table_files_size_mb=10000 -fifo_compaction_allow_compaction=0 -partition_index_and_filters
```
and test with (simultaneous runs with & without folly, ~20 times each to see
convergence)
```
TEST_TMPDIR=/dev/shm/rocksdb ./db_bench_folly -readonly -use_existing_db -benchmarks=readrandom -num=10000000 -bloom_bits=16 -compaction_style=2 -fifo_compaction_max_table_files_size_mb=10000 -fifo_compaction_allow_compaction=0 -partition_index_and_filters -duration=40 -pin_l0_filter_and_index_blocks_in_cache
```
Average ops/s no folly: 26229.2
Average ops/s with folly: 26853.3 (+2.4%)
Reviewed By: ajkr
Differential Revision: D34181736
Pulled By: pdillinger
fbshipit-source-id: ffa6ad5104c2880321d8a1aa7187e00ab0d02e94
2022-04-13 16:34:01 +02:00
|
|
|
static_cast<UnorderedMap<uint32_t, std::shared_ptr<LockMap>>*>(ptr);
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
delete lock_maps_cache;
|
|
|
|
}
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2020-10-19 19:12:53 +02:00
|
|
|
PointLockManager::PointLockManager(PessimisticTransactionDB* txn_db,
|
|
|
|
const TransactionDBOptions& opt)
|
|
|
|
: txn_db_impl_(txn_db),
|
|
|
|
default_num_stripes_(opt.num_stripes),
|
|
|
|
max_num_locks_(opt.max_num_locks),
|
2016-09-28 10:23:33 +02:00
|
|
|
lock_maps_cache_(new ThreadLocalPtr(&UnrefLockMapsCache)),
|
2020-10-19 19:12:53 +02:00
|
|
|
dlock_buffer_(opt.max_num_deadlocks),
|
|
|
|
mutex_factory_(opt.custom_mutex_factory
|
|
|
|
? opt.custom_mutex_factory
|
|
|
|
: std::make_shared<TransactionDBMutexFactoryImpl>()) {}
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
|
|
|
|
size_t LockMap::GetStripe(const std::string& key) const {
|
|
|
|
assert(num_stripes_ > 0);
|
2020-09-28 20:33:31 +02:00
|
|
|
return FastRange64(GetSliceNPHash64(key), num_stripes_);
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
}
|
|
|
|
|
2020-10-19 19:12:53 +02:00
|
|
|
void PointLockManager::AddColumnFamily(const ColumnFamilyHandle* cf) {
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
InstrumentedMutexLock l(&lock_map_mutex_);
|
|
|
|
|
2020-10-19 19:12:53 +02:00
|
|
|
if (lock_maps_.find(cf->GetID()) == lock_maps_.end()) {
|
|
|
|
lock_maps_.emplace(cf->GetID(), std::make_shared<LockMap>(
|
|
|
|
default_num_stripes_, mutex_factory_));
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
} else {
|
|
|
|
// column_family already exists in lock map
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-19 19:12:53 +02:00
|
|
|
void PointLockManager::RemoveColumnFamily(const ColumnFamilyHandle* cf) {
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
// Remove lock_map for this column family. Since the lock map is stored
|
2016-04-28 11:30:44 +02:00
|
|
|
// as a shared ptr, concurrent transactions can still keep using it
|
|
|
|
// until they release their references to it.
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
{
|
|
|
|
InstrumentedMutexLock l(&lock_map_mutex_);
|
|
|
|
|
2020-10-19 19:12:53 +02:00
|
|
|
auto lock_maps_iter = lock_maps_.find(cf->GetID());
|
2020-04-08 22:49:17 +02:00
|
|
|
if (lock_maps_iter == lock_maps_.end()) {
|
|
|
|
return;
|
|
|
|
}
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
|
|
|
|
lock_maps_.erase(lock_maps_iter);
|
|
|
|
} // lock_map_mutex_
|
|
|
|
|
|
|
|
// Clear all thread-local caches
|
|
|
|
autovector<void*> local_caches;
|
|
|
|
lock_maps_cache_->Scrape(&local_caches, nullptr);
|
|
|
|
for (auto cache : local_caches) {
|
|
|
|
delete static_cast<LockMaps*>(cache);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-09 20:17:34 +01:00
|
|
|
// Look up the LockMap std::shared_ptr for a given column_family_id.
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
// Note: The LockMap is only valid as long as the caller is still holding on
|
2018-11-09 20:17:34 +01:00
|
|
|
// to the returned std::shared_ptr.
|
2020-10-19 19:12:53 +02:00
|
|
|
std::shared_ptr<LockMap> PointLockManager::GetLockMap(
|
|
|
|
ColumnFamilyId column_family_id) {
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
// First check thread-local cache
|
|
|
|
if (lock_maps_cache_->Get() == nullptr) {
|
|
|
|
lock_maps_cache_->Reset(new LockMaps());
|
|
|
|
}
|
|
|
|
|
|
|
|
auto lock_maps_cache = static_cast<LockMaps*>(lock_maps_cache_->Get());
|
|
|
|
|
|
|
|
auto lock_map_iter = lock_maps_cache->find(column_family_id);
|
|
|
|
if (lock_map_iter != lock_maps_cache->end()) {
|
|
|
|
// Found lock map for this column family.
|
|
|
|
return lock_map_iter->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not found in local cache, grab mutex and check shared LockMaps
|
|
|
|
InstrumentedMutexLock l(&lock_map_mutex_);
|
|
|
|
|
|
|
|
lock_map_iter = lock_maps_.find(column_family_id);
|
|
|
|
if (lock_map_iter == lock_maps_.end()) {
|
|
|
|
return std::shared_ptr<LockMap>(nullptr);
|
|
|
|
} else {
|
|
|
|
// Found lock map. Store in thread-local cache and return.
|
|
|
|
std::shared_ptr<LockMap>& lock_map = lock_map_iter->second;
|
|
|
|
lock_maps_cache->insert({column_family_id, lock_map});
|
|
|
|
|
|
|
|
return lock_map;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if this lock has expired and can be acquired by another
|
|
|
|
// transaction.
|
2015-09-08 21:36:48 +02:00
|
|
|
// If false, sets *expire_time to the expiration time of the lock according
|
|
|
|
// to Env->GetMicros() or 0 if no expiration.
|
2020-10-19 19:12:53 +02:00
|
|
|
bool PointLockManager::IsLockExpired(TransactionID txn_id,
|
|
|
|
const LockInfo& lock_info, Env* env,
|
|
|
|
uint64_t* expire_time) {
|
2020-03-28 00:12:40 +01:00
|
|
|
if (lock_info.expiration_time == 0) {
|
|
|
|
*expire_time = 0;
|
|
|
|
return false;
|
|
|
|
}
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
|
2020-03-28 00:12:40 +01:00
|
|
|
auto now = env->NowMicros();
|
|
|
|
bool expired = lock_info.expiration_time <= now;
|
|
|
|
if (!expired) {
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
// return how many microseconds until lock will be expired
|
2015-09-08 21:36:48 +02:00
|
|
|
*expire_time = lock_info.expiration_time;
|
|
|
|
} else {
|
2016-12-06 02:18:14 +01:00
|
|
|
for (auto id : lock_info.txn_ids) {
|
|
|
|
if (txn_id == id) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool success = txn_db_impl_->TryStealingExpiredTransactionLocks(id);
|
|
|
|
if (!success) {
|
|
|
|
expired = false;
|
2020-03-28 00:12:40 +01:00
|
|
|
*expire_time = 0;
|
2016-12-06 02:18:14 +01:00
|
|
|
break;
|
|
|
|
}
|
2016-02-02 02:07:05 +01:00
|
|
|
}
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return expired;
|
|
|
|
}
|
|
|
|
|
2020-10-19 19:12:53 +02:00
|
|
|
Status PointLockManager::TryLock(PessimisticTransaction* txn,
|
|
|
|
ColumnFamilyId column_family_id,
|
|
|
|
const std::string& key, Env* env,
|
|
|
|
bool exclusive) {
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
// Lookup lock map for this column family id
|
|
|
|
std::shared_ptr<LockMap> lock_map_ptr = GetLockMap(column_family_id);
|
|
|
|
LockMap* lock_map = lock_map_ptr.get();
|
|
|
|
if (lock_map == nullptr) {
|
|
|
|
char msg[255];
|
|
|
|
snprintf(msg, sizeof(msg), "Column family id not found: %" PRIu32,
|
|
|
|
column_family_id);
|
|
|
|
|
|
|
|
return Status::InvalidArgument(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Need to lock the mutex for the stripe that this key hashes to
|
|
|
|
size_t stripe_num = lock_map->GetStripe(key);
|
|
|
|
assert(lock_map->lock_map_stripes_.size() > stripe_num);
|
2015-09-08 21:36:48 +02:00
|
|
|
LockMapStripe* stripe = lock_map->lock_map_stripes_.at(stripe_num);
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
|
2016-12-06 02:18:14 +01:00
|
|
|
LockInfo lock_info(txn->GetID(), txn->GetExpirationTime(), exclusive);
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
int64_t timeout = txn->GetLockTimeout();
|
|
|
|
|
2016-09-28 02:43:06 +02:00
|
|
|
return AcquireWithTimeout(txn, lock_map, stripe, column_family_id, key, env,
|
2019-04-11 00:54:53 +02:00
|
|
|
timeout, std::move(lock_info));
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Helper function for TryLock().
|
2020-10-19 19:12:53 +02:00
|
|
|
Status PointLockManager::AcquireWithTimeout(
|
2017-08-08 01:07:40 +02:00
|
|
|
PessimisticTransaction* txn, LockMap* lock_map, LockMapStripe* stripe,
|
2020-10-19 19:12:53 +02:00
|
|
|
ColumnFamilyId column_family_id, const std::string& key, Env* env,
|
2019-04-11 00:54:53 +02:00
|
|
|
int64_t timeout, LockInfo&& lock_info) {
|
2015-09-08 21:36:48 +02:00
|
|
|
Status result;
|
|
|
|
uint64_t end_time = 0;
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
|
|
|
|
if (timeout > 0) {
|
2018-02-16 01:43:23 +01:00
|
|
|
uint64_t start_time = env->NowMicros();
|
2015-09-08 21:36:48 +02:00
|
|
|
end_time = start_time + timeout;
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
}
|
|
|
|
|
2015-09-08 21:36:48 +02:00
|
|
|
if (timeout < 0) {
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
// If timeout is negative, we wait indefinitely to acquire the lock
|
2015-09-08 21:36:48 +02:00
|
|
|
result = stripe->stripe_mutex->Lock();
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
} else {
|
2015-09-08 21:36:48 +02:00
|
|
|
result = stripe->stripe_mutex->TryLockFor(timeout);
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
}
|
|
|
|
|
2015-09-08 21:36:48 +02:00
|
|
|
if (!result.ok()) {
|
|
|
|
// failed to acquire mutex
|
|
|
|
return result;
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Acquire lock if we are able to
|
2015-09-08 21:36:48 +02:00
|
|
|
uint64_t expire_time_hint = 0;
|
2016-12-06 02:18:14 +01:00
|
|
|
autovector<TransactionID> wait_ids;
|
2019-04-11 00:54:53 +02:00
|
|
|
result = AcquireLocked(lock_map, stripe, key, env, std::move(lock_info),
|
2016-12-06 02:18:14 +01:00
|
|
|
&expire_time_hint, &wait_ids);
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
|
2015-07-31 05:31:36 +02:00
|
|
|
if (!result.ok() && timeout != 0) {
|
2017-11-06 19:52:17 +01:00
|
|
|
PERF_TIMER_GUARD(key_lock_wait_time);
|
|
|
|
PERF_COUNTER_ADD(key_lock_wait_count, 1);
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
// If we weren't able to acquire the lock, we will keep retrying as long
|
2015-09-08 21:36:48 +02:00
|
|
|
// as the timeout allows.
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
bool timed_out = false;
|
|
|
|
do {
|
2015-09-08 21:36:48 +02:00
|
|
|
// Decide how long to wait
|
|
|
|
int64_t cv_end_time = -1;
|
2020-03-27 23:59:21 +01:00
|
|
|
if (expire_time_hint > 0 && end_time > 0) {
|
|
|
|
cv_end_time = std::min(expire_time_hint, end_time);
|
|
|
|
} else if (expire_time_hint > 0) {
|
2015-09-08 21:36:48 +02:00
|
|
|
cv_end_time = expire_time_hint;
|
2020-03-27 23:59:21 +01:00
|
|
|
} else if (end_time > 0) {
|
2015-09-08 21:36:48 +02:00
|
|
|
cv_end_time = end_time;
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
}
|
|
|
|
|
2016-12-06 02:18:14 +01:00
|
|
|
assert(result.IsBusy() || wait_ids.size() != 0);
|
2016-09-28 10:23:33 +02:00
|
|
|
|
|
|
|
// We are dependent on a transaction to finish, so perform deadlock
|
|
|
|
// detection.
|
2016-12-06 02:18:14 +01:00
|
|
|
if (wait_ids.size() != 0) {
|
2016-09-28 10:23:33 +02:00
|
|
|
if (txn->IsDeadlockDetect()) {
|
2017-08-18 03:49:30 +02:00
|
|
|
if (IncrementWaiters(txn, wait_ids, key, column_family_id,
|
2018-06-27 21:22:17 +02:00
|
|
|
lock_info.exclusive, env)) {
|
2016-09-28 10:23:33 +02:00
|
|
|
result = Status::Busy(Status::SubCode::kDeadlock);
|
|
|
|
stripe->stripe_mutex->UnLock();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2016-12-06 02:18:14 +01:00
|
|
|
txn->SetWaitingTxn(wait_ids, column_family_id, &key);
|
2016-09-28 10:23:33 +02:00
|
|
|
}
|
|
|
|
|
2020-10-19 19:12:53 +02:00
|
|
|
TEST_SYNC_POINT("PointLockManager::AcquireWithTimeout:WaitingTxn");
|
2015-09-08 21:36:48 +02:00
|
|
|
if (cv_end_time < 0) {
|
|
|
|
// Wait indefinitely
|
|
|
|
result = stripe->stripe_cv->Wait(stripe->stripe_mutex);
|
|
|
|
} else {
|
|
|
|
uint64_t now = env->NowMicros();
|
|
|
|
if (static_cast<uint64_t>(cv_end_time) > now) {
|
|
|
|
result = stripe->stripe_cv->WaitFor(stripe->stripe_mutex,
|
|
|
|
cv_end_time - now);
|
|
|
|
}
|
|
|
|
}
|
2016-09-28 10:23:33 +02:00
|
|
|
|
2016-12-06 02:18:14 +01:00
|
|
|
if (wait_ids.size() != 0) {
|
|
|
|
txn->ClearWaitingTxn();
|
2016-09-28 10:23:33 +02:00
|
|
|
if (txn->IsDeadlockDetect()) {
|
2016-12-06 02:18:14 +01:00
|
|
|
DecrementWaiters(txn, wait_ids);
|
2016-09-28 10:23:33 +02:00
|
|
|
}
|
|
|
|
}
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
|
2015-09-08 21:36:48 +02:00
|
|
|
if (result.IsTimedOut()) {
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
timed_out = true;
|
|
|
|
// Even though we timed out, we will still make one more attempt to
|
|
|
|
// acquire lock below (it is possible the lock expired and we
|
|
|
|
// were never signaled).
|
|
|
|
}
|
|
|
|
|
2015-09-08 21:36:48 +02:00
|
|
|
if (result.ok() || result.IsTimedOut()) {
|
2019-04-11 00:54:53 +02:00
|
|
|
result = AcquireLocked(lock_map, stripe, key, env, std::move(lock_info),
|
2016-12-06 02:18:14 +01:00
|
|
|
&expire_time_hint, &wait_ids);
|
2015-09-08 21:36:48 +02:00
|
|
|
}
|
2015-07-31 05:31:36 +02:00
|
|
|
} while (!result.ok() && !timed_out);
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
}
|
|
|
|
|
2015-09-08 21:36:48 +02:00
|
|
|
stripe->stripe_mutex->UnLock();
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-10-19 19:12:53 +02:00
|
|
|
void PointLockManager::DecrementWaiters(
|
2017-08-17 01:49:11 +02:00
|
|
|
const PessimisticTransaction* txn,
|
|
|
|
const autovector<TransactionID>& wait_ids) {
|
2016-09-28 10:23:33 +02:00
|
|
|
std::lock_guard<std::mutex> lock(wait_txn_map_mutex_);
|
2016-12-06 02:18:14 +01:00
|
|
|
DecrementWaitersImpl(txn, wait_ids);
|
2016-09-28 10:23:33 +02:00
|
|
|
}
|
|
|
|
|
2020-10-19 19:12:53 +02:00
|
|
|
void PointLockManager::DecrementWaitersImpl(
|
2017-08-17 01:49:11 +02:00
|
|
|
const PessimisticTransaction* txn,
|
|
|
|
const autovector<TransactionID>& wait_ids) {
|
2016-09-28 10:23:33 +02:00
|
|
|
auto id = txn->GetID();
|
2016-11-19 20:34:26 +01:00
|
|
|
assert(wait_txn_map_.Contains(id));
|
|
|
|
wait_txn_map_.Delete(id);
|
2016-09-28 10:23:33 +02:00
|
|
|
|
2016-12-06 02:18:14 +01:00
|
|
|
for (auto wait_id : wait_ids) {
|
|
|
|
rev_wait_txn_map_.Get(wait_id)--;
|
|
|
|
if (rev_wait_txn_map_.Get(wait_id) == 0) {
|
|
|
|
rev_wait_txn_map_.Delete(wait_id);
|
|
|
|
}
|
2016-09-28 10:23:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-19 19:12:53 +02:00
|
|
|
bool PointLockManager::IncrementWaiters(
|
2017-08-17 01:49:11 +02:00
|
|
|
const PessimisticTransaction* txn,
|
2017-08-18 03:49:30 +02:00
|
|
|
const autovector<TransactionID>& wait_ids, const std::string& key,
|
2018-06-27 21:22:17 +02:00
|
|
|
const uint32_t& cf_id, const bool& exclusive, Env* const env) {
|
2016-09-28 10:23:33 +02:00
|
|
|
auto id = txn->GetID();
|
2018-09-06 03:07:53 +02:00
|
|
|
std::vector<int> queue_parents(static_cast<size_t>(txn->GetDeadlockDetectDepth()));
|
|
|
|
std::vector<TransactionID> queue_values(static_cast<size_t>(txn->GetDeadlockDetectDepth()));
|
2016-09-28 10:23:33 +02:00
|
|
|
std::lock_guard<std::mutex> lock(wait_txn_map_mutex_);
|
2016-11-19 20:34:26 +01:00
|
|
|
assert(!wait_txn_map_.Contains(id));
|
2017-08-18 03:49:30 +02:00
|
|
|
|
2019-04-15 19:30:48 +02:00
|
|
|
wait_txn_map_.Insert(id, {wait_ids, cf_id, exclusive, key});
|
2016-11-19 20:34:26 +01:00
|
|
|
|
2016-12-06 02:18:14 +01:00
|
|
|
for (auto wait_id : wait_ids) {
|
|
|
|
if (rev_wait_txn_map_.Contains(wait_id)) {
|
|
|
|
rev_wait_txn_map_.Get(wait_id)++;
|
|
|
|
} else {
|
|
|
|
rev_wait_txn_map_.Insert(wait_id, 1);
|
|
|
|
}
|
2016-11-19 20:34:26 +01:00
|
|
|
}
|
2016-09-28 10:23:33 +02:00
|
|
|
|
|
|
|
// No deadlock if nobody is waiting on self.
|
2016-11-19 20:34:26 +01:00
|
|
|
if (!rev_wait_txn_map_.Contains(id)) {
|
2016-09-28 10:23:33 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-06 02:18:14 +01:00
|
|
|
const auto* next_ids = &wait_ids;
|
2017-08-18 03:49:30 +02:00
|
|
|
int parent = -1;
|
2018-06-27 21:22:17 +02:00
|
|
|
int64_t deadlock_time = 0;
|
2016-12-06 02:18:14 +01:00
|
|
|
for (int tail = 0, head = 0; head < txn->GetDeadlockDetectDepth(); head++) {
|
2016-12-06 23:29:26 +01:00
|
|
|
int i = 0;
|
2016-12-06 02:18:14 +01:00
|
|
|
if (next_ids) {
|
2016-12-06 23:29:26 +01:00
|
|
|
for (; i < static_cast<int>(next_ids->size()) &&
|
|
|
|
tail + i < txn->GetDeadlockDetectDepth();
|
2016-12-06 02:18:14 +01:00
|
|
|
i++) {
|
2017-08-18 03:49:30 +02:00
|
|
|
queue_values[tail + i] = (*next_ids)[i];
|
|
|
|
queue_parents[tail + i] = parent;
|
2016-12-06 02:18:14 +01:00
|
|
|
}
|
|
|
|
tail += i;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No more items in the list, meaning no deadlock.
|
|
|
|
if (tail == head) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-18 03:49:30 +02:00
|
|
|
auto next = queue_values[head];
|
2016-09-28 10:23:33 +02:00
|
|
|
if (next == id) {
|
2017-08-18 03:49:30 +02:00
|
|
|
std::vector<DeadlockInfo> path;
|
|
|
|
while (head != -1) {
|
|
|
|
assert(wait_txn_map_.Contains(queue_values[head]));
|
|
|
|
|
|
|
|
auto extracted_info = wait_txn_map_.Get(queue_values[head]);
|
|
|
|
path.push_back({queue_values[head], extracted_info.m_cf_id,
|
2018-10-23 19:33:55 +02:00
|
|
|
extracted_info.m_exclusive,
|
|
|
|
extracted_info.m_waiting_key});
|
2017-08-18 03:49:30 +02:00
|
|
|
head = queue_parents[head];
|
|
|
|
}
|
2020-12-10 06:19:55 +01:00
|
|
|
if (!env->GetCurrentTime(&deadlock_time).ok()) {
|
|
|
|
/*
|
|
|
|
TODO(AR) this preserves the current behaviour whilst checking the
|
|
|
|
status of env->GetCurrentTime to ensure that ASSERT_STATUS_CHECKED
|
|
|
|
passes. Should we instead raise an error if !ok() ?
|
|
|
|
*/
|
|
|
|
deadlock_time = 0;
|
|
|
|
}
|
2017-08-18 03:49:30 +02:00
|
|
|
std::reverse(path.begin(), path.end());
|
2018-06-27 21:22:17 +02:00
|
|
|
dlock_buffer_.AddNewPath(DeadlockPath(path, deadlock_time));
|
|
|
|
deadlock_time = 0;
|
2016-12-06 02:18:14 +01:00
|
|
|
DecrementWaitersImpl(txn, wait_ids);
|
2016-09-28 10:23:33 +02:00
|
|
|
return true;
|
2016-11-19 20:34:26 +01:00
|
|
|
} else if (!wait_txn_map_.Contains(next)) {
|
2016-12-06 02:18:14 +01:00
|
|
|
next_ids = nullptr;
|
|
|
|
continue;
|
2016-09-28 10:23:33 +02:00
|
|
|
} else {
|
2017-08-18 03:49:30 +02:00
|
|
|
parent = head;
|
|
|
|
next_ids = &(wait_txn_map_.Get(next).m_neighbors);
|
2016-09-28 10:23:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait cycle too big, just assume deadlock.
|
2020-12-10 06:19:55 +01:00
|
|
|
if (!env->GetCurrentTime(&deadlock_time).ok()) {
|
|
|
|
/*
|
|
|
|
TODO(AR) this preserves the current behaviour whilst checking the status
|
|
|
|
of env->GetCurrentTime to ensure that ASSERT_STATUS_CHECKED passes.
|
|
|
|
Should we instead raise an error if !ok() ?
|
|
|
|
*/
|
|
|
|
deadlock_time = 0;
|
|
|
|
}
|
2018-06-27 21:22:17 +02:00
|
|
|
dlock_buffer_.AddNewPath(DeadlockPath(deadlock_time, true));
|
2016-12-06 02:18:14 +01:00
|
|
|
DecrementWaitersImpl(txn, wait_ids);
|
2016-09-28 10:23:33 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
// Try to lock this key after we have acquired the mutex.
|
2015-09-08 21:36:48 +02:00
|
|
|
// Sets *expire_time to the expiration time in microseconds
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
// or 0 if no expiration.
|
|
|
|
// REQUIRED: Stripe mutex must be held.
|
2020-10-19 19:12:53 +02:00
|
|
|
Status PointLockManager::AcquireLocked(LockMap* lock_map, LockMapStripe* stripe,
|
|
|
|
const std::string& key, Env* env,
|
|
|
|
LockInfo&& txn_lock_info,
|
|
|
|
uint64_t* expire_time,
|
|
|
|
autovector<TransactionID>* txn_ids) {
|
2016-12-06 02:18:14 +01:00
|
|
|
assert(txn_lock_info.txn_ids.size() == 1);
|
|
|
|
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
Status result;
|
|
|
|
// Check if this key is already locked
|
2018-02-21 02:34:44 +01:00
|
|
|
auto stripe_iter = stripe->keys.find(key);
|
|
|
|
if (stripe_iter != stripe->keys.end()) {
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
// Lock already held
|
2018-02-21 02:34:44 +01:00
|
|
|
LockInfo& lock_info = stripe_iter->second;
|
2016-12-06 02:18:14 +01:00
|
|
|
assert(lock_info.txn_ids.size() == 1 || !lock_info.exclusive);
|
|
|
|
|
|
|
|
if (lock_info.exclusive || txn_lock_info.exclusive) {
|
|
|
|
if (lock_info.txn_ids.size() == 1 &&
|
|
|
|
lock_info.txn_ids[0] == txn_lock_info.txn_ids[0]) {
|
|
|
|
// The list contains one txn and we're it, so just take it.
|
|
|
|
lock_info.exclusive = txn_lock_info.exclusive;
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
lock_info.expiration_time = txn_lock_info.expiration_time;
|
|
|
|
} else {
|
2016-12-06 02:18:14 +01:00
|
|
|
// Check if it's expired. Skips over txn_lock_info.txn_ids[0] in case
|
|
|
|
// it's there for a shared lock with multiple holders which was not
|
|
|
|
// caught in the first case.
|
|
|
|
if (IsLockExpired(txn_lock_info.txn_ids[0], lock_info, env,
|
|
|
|
expire_time)) {
|
|
|
|
// lock is expired, can steal it
|
|
|
|
lock_info.txn_ids = txn_lock_info.txn_ids;
|
|
|
|
lock_info.exclusive = txn_lock_info.exclusive;
|
|
|
|
lock_info.expiration_time = txn_lock_info.expiration_time;
|
|
|
|
// lock_cnt does not change
|
|
|
|
} else {
|
|
|
|
result = Status::TimedOut(Status::SubCode::kLockTimeout);
|
|
|
|
*txn_ids = lock_info.txn_ids;
|
|
|
|
}
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
}
|
2016-12-06 02:18:14 +01:00
|
|
|
} else {
|
|
|
|
// We are requesting shared access to a shared lock, so just grant it.
|
|
|
|
lock_info.txn_ids.push_back(txn_lock_info.txn_ids[0]);
|
|
|
|
// Using std::max means that expiration time never goes down even when
|
|
|
|
// a transaction is removed from the list. The correct solution would be
|
|
|
|
// to track expiry for every transaction, but this would also work for
|
|
|
|
// now.
|
|
|
|
lock_info.expiration_time =
|
|
|
|
std::max(lock_info.expiration_time, txn_lock_info.expiration_time);
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
}
|
|
|
|
} else { // Lock not held.
|
|
|
|
// Check lock limit
|
|
|
|
if (max_num_locks_ > 0 &&
|
|
|
|
lock_map->lock_cnt.load(std::memory_order_acquire) >= max_num_locks_) {
|
2015-08-15 01:45:05 +02:00
|
|
|
result = Status::Busy(Status::SubCode::kLockLimit);
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
} else {
|
|
|
|
// acquire lock
|
2019-04-11 00:54:53 +02:00
|
|
|
stripe->keys.emplace(key, std::move(txn_lock_info));
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
|
|
|
|
// Maintain lock count if there is a limit on the number of locks
|
|
|
|
if (max_num_locks_) {
|
|
|
|
lock_map->lock_cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-10-19 19:12:53 +02:00
|
|
|
void PointLockManager::UnLockKey(PessimisticTransaction* txn,
|
|
|
|
const std::string& key, LockMapStripe* stripe,
|
|
|
|
LockMap* lock_map, Env* env) {
|
2018-04-13 02:55:14 +02:00
|
|
|
#ifdef NDEBUG
|
|
|
|
(void)env;
|
|
|
|
#endif
|
2016-12-06 02:18:14 +01:00
|
|
|
TransactionID txn_id = txn->GetID();
|
|
|
|
|
|
|
|
auto stripe_iter = stripe->keys.find(key);
|
|
|
|
if (stripe_iter != stripe->keys.end()) {
|
|
|
|
auto& txns = stripe_iter->second.txn_ids;
|
|
|
|
auto txn_it = std::find(txns.begin(), txns.end(), txn_id);
|
|
|
|
// Found the key we locked. unlock it.
|
|
|
|
if (txn_it != txns.end()) {
|
|
|
|
if (txns.size() == 1) {
|
|
|
|
stripe->keys.erase(stripe_iter);
|
|
|
|
} else {
|
|
|
|
auto last_it = txns.end() - 1;
|
|
|
|
if (txn_it != last_it) {
|
|
|
|
*txn_it = *last_it;
|
|
|
|
}
|
|
|
|
txns.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (max_num_locks_ > 0) {
|
|
|
|
// Maintain lock count if there is a limit on the number of locks.
|
|
|
|
assert(lock_map->lock_cnt.load(std::memory_order_relaxed) > 0);
|
|
|
|
lock_map->lock_cnt--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// This key is either not locked or locked by someone else. This should
|
|
|
|
// only happen if the unlocking transaction has expired.
|
|
|
|
assert(txn->GetExpirationTime() > 0 &&
|
|
|
|
txn->GetExpirationTime() < env->NowMicros());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-19 19:12:53 +02:00
|
|
|
void PointLockManager::UnLock(PessimisticTransaction* txn,
|
|
|
|
ColumnFamilyId column_family_id,
|
|
|
|
const std::string& key, Env* env) {
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
std::shared_ptr<LockMap> lock_map_ptr = GetLockMap(column_family_id);
|
|
|
|
LockMap* lock_map = lock_map_ptr.get();
|
|
|
|
if (lock_map == nullptr) {
|
|
|
|
// Column Family must have been dropped.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lock the mutex for the stripe that this key hashes to
|
|
|
|
size_t stripe_num = lock_map->GetStripe(key);
|
|
|
|
assert(lock_map->lock_map_stripes_.size() > stripe_num);
|
2015-09-08 21:36:48 +02:00
|
|
|
LockMapStripe* stripe = lock_map->lock_map_stripes_.at(stripe_num);
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
|
2020-10-21 23:02:00 +02:00
|
|
|
stripe->stripe_mutex->Lock().PermitUncheckedError();
|
2016-12-06 02:18:14 +01:00
|
|
|
UnLockKey(txn, key, stripe, lock_map, env);
|
2015-09-08 21:36:48 +02:00
|
|
|
stripe->stripe_mutex->UnLock();
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
|
|
|
|
// Signal waiting threads to retry locking
|
2015-09-08 21:36:48 +02:00
|
|
|
stripe->stripe_cv->NotifyAll();
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
}
|
|
|
|
|
2020-10-19 19:12:53 +02:00
|
|
|
void PointLockManager::UnLock(PessimisticTransaction* txn,
|
|
|
|
const LockTracker& tracker, Env* env) {
|
Replace tracked_keys with a new LockTracker interface in TransactionDB (#7013)
Summary:
We're going to support more locking protocols such as range lock in transaction.
However, in current design, `TransactionBase` has a member `tracked_keys` which assumes that point lock (lock a single key) is used, and is used in snapshot checking (isolation protocol). When using range lock, we may use read committed instead of snapshot checking as the isolation protocol.
The most significant usage scenarios of `tracked_keys` are:
1. pessimistic transaction uses it to track the locked keys, and unlock these keys when commit or rollback.
2. optimistic transaction does not lock keys upfront, it only tracks the lock intentions in tracked_keys, and do write conflict checking when commit.
3. each `SavePoint` tracks the keys that are locked since the `SavePoint`, `RollbackToSavePoint` or `PopSavePoint` relies on both the tracked keys in `SavePoint`s and `tracked_keys`.
Based on these scenarios, if we can abstract out a `LockTracker` interface to hold a set of tracked locks (can be keys or key ranges), and have methods that can be composed together to implement the scenarios, then `tracked_keys` can be an internal data structure of one implementation of `LockTracker`. See `utilities/transactions/lock/lock_tracker.h` for the detailed interface design, and `utilities/transactions/lock/point_lock_tracker.cc` for the implementation.
In the future, a `RangeLockTracker` can be implemented to track range locks without affecting other components.
After this PR, a clean interface for lock manager should be possible, and then ideally, we can have pluggable locking protocols.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7013
Test Plan: Run `transaction_test` and `optimistic_transaction_test`.
Reviewed By: ajkr
Differential Revision: D22163706
Pulled By: cheng-chang
fbshipit-source-id: f2860577b5334e31dd2994f5bc6d7c40d502b1b4
2020-08-06 21:36:48 +02:00
|
|
|
std::unique_ptr<LockTracker::ColumnFamilyIterator> cf_it(
|
|
|
|
tracker.GetColumnFamilyIterator());
|
|
|
|
assert(cf_it != nullptr);
|
|
|
|
while (cf_it->HasNext()) {
|
|
|
|
ColumnFamilyId cf = cf_it->Next();
|
|
|
|
std::shared_ptr<LockMap> lock_map_ptr = GetLockMap(cf);
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
LockMap* lock_map = lock_map_ptr.get();
|
Replace tracked_keys with a new LockTracker interface in TransactionDB (#7013)
Summary:
We're going to support more locking protocols such as range lock in transaction.
However, in current design, `TransactionBase` has a member `tracked_keys` which assumes that point lock (lock a single key) is used, and is used in snapshot checking (isolation protocol). When using range lock, we may use read committed instead of snapshot checking as the isolation protocol.
The most significant usage scenarios of `tracked_keys` are:
1. pessimistic transaction uses it to track the locked keys, and unlock these keys when commit or rollback.
2. optimistic transaction does not lock keys upfront, it only tracks the lock intentions in tracked_keys, and do write conflict checking when commit.
3. each `SavePoint` tracks the keys that are locked since the `SavePoint`, `RollbackToSavePoint` or `PopSavePoint` relies on both the tracked keys in `SavePoint`s and `tracked_keys`.
Based on these scenarios, if we can abstract out a `LockTracker` interface to hold a set of tracked locks (can be keys or key ranges), and have methods that can be composed together to implement the scenarios, then `tracked_keys` can be an internal data structure of one implementation of `LockTracker`. See `utilities/transactions/lock/lock_tracker.h` for the detailed interface design, and `utilities/transactions/lock/point_lock_tracker.cc` for the implementation.
In the future, a `RangeLockTracker` can be implemented to track range locks without affecting other components.
After this PR, a clean interface for lock manager should be possible, and then ideally, we can have pluggable locking protocols.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7013
Test Plan: Run `transaction_test` and `optimistic_transaction_test`.
Reviewed By: ajkr
Differential Revision: D22163706
Pulled By: cheng-chang
fbshipit-source-id: f2860577b5334e31dd2994f5bc6d7c40d502b1b4
2020-08-06 21:36:48 +02:00
|
|
|
if (!lock_map) {
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
// Column Family must have been dropped.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bucket keys by lock_map_ stripe
|
Meta-internal folly integration with F14FastMap (#9546)
Summary:
Especially after updating to C++17, I don't see a compelling case for
*requiring* any folly components in RocksDB. I was able to purge the existing
hard dependencies, and it can be quite difficult to strip out non-trivial components
from folly for use in RocksDB. (The prospect of doing that on F14 has changed
my mind on the best approach here.)
But this change creates an optional integration where we can plug in
components from folly at compile time, starting here with F14FastMap to replace
std::unordered_map when possible (probably no public APIs for example). I have
replaced the biggest CPU users of std::unordered_map with compile-time
pluggable UnorderedMap which will use F14FastMap when USE_FOLLY is set.
USE_FOLLY is always set in the Meta-internal buck build, and a simulation of
that is in the Makefile for public CI testing. A full folly build is not needed, but
checking out the full folly repo is much simpler for getting the dependency,
and anything else we might want to optionally integrate in the future.
Some picky details:
* I don't think the distributed mutex stuff is actually used, so it was easy to remove.
* I implemented an alternative to `folly::constexpr_log2` (which is much easier
in C++17 than C++11) so that I could pull out the hard dependencies on
`ConstexprMath.h`
* I had to add noexcept move constructors/operators to some types to make
F14's complainUnlessNothrowMoveAndDestroy check happy, and I added a
macro to make that easier in some common cases.
* Updated Meta-internal buck build to use folly F14Map (always)
No updates to HISTORY.md nor INSTALL.md as this is not (yet?) considered a
production integration for open source users.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/9546
Test Plan:
CircleCI tests updated so that a couple of them use folly.
Most internal unit & stress/crash tests updated to use Meta-internal latest folly.
(Note: they should probably use buck but they currently use Makefile.)
Example performance improvement: when filter partitions are pinned in cache,
they are tracked by PartitionedFilterBlockReader::filter_map_ and we can build
a test that exercises that heavily. Build DB with
```
TEST_TMPDIR=/dev/shm/rocksdb ./db_bench -benchmarks=fillrandom -num=10000000 -disable_wal=1 -write_buffer_size=30000000 -bloom_bits=16 -compaction_style=2 -fifo_compaction_max_table_files_size_mb=10000 -fifo_compaction_allow_compaction=0 -partition_index_and_filters
```
and test with (simultaneous runs with & without folly, ~20 times each to see
convergence)
```
TEST_TMPDIR=/dev/shm/rocksdb ./db_bench_folly -readonly -use_existing_db -benchmarks=readrandom -num=10000000 -bloom_bits=16 -compaction_style=2 -fifo_compaction_max_table_files_size_mb=10000 -fifo_compaction_allow_compaction=0 -partition_index_and_filters -duration=40 -pin_l0_filter_and_index_blocks_in_cache
```
Average ops/s no folly: 26229.2
Average ops/s with folly: 26853.3 (+2.4%)
Reviewed By: ajkr
Differential Revision: D34181736
Pulled By: pdillinger
fbshipit-source-id: ffa6ad5104c2880321d8a1aa7187e00ab0d02e94
2022-04-13 16:34:01 +02:00
|
|
|
UnorderedMap<size_t, std::vector<const std::string*>> keys_by_stripe(
|
Replace tracked_keys with a new LockTracker interface in TransactionDB (#7013)
Summary:
We're going to support more locking protocols such as range lock in transaction.
However, in current design, `TransactionBase` has a member `tracked_keys` which assumes that point lock (lock a single key) is used, and is used in snapshot checking (isolation protocol). When using range lock, we may use read committed instead of snapshot checking as the isolation protocol.
The most significant usage scenarios of `tracked_keys` are:
1. pessimistic transaction uses it to track the locked keys, and unlock these keys when commit or rollback.
2. optimistic transaction does not lock keys upfront, it only tracks the lock intentions in tracked_keys, and do write conflict checking when commit.
3. each `SavePoint` tracks the keys that are locked since the `SavePoint`, `RollbackToSavePoint` or `PopSavePoint` relies on both the tracked keys in `SavePoint`s and `tracked_keys`.
Based on these scenarios, if we can abstract out a `LockTracker` interface to hold a set of tracked locks (can be keys or key ranges), and have methods that can be composed together to implement the scenarios, then `tracked_keys` can be an internal data structure of one implementation of `LockTracker`. See `utilities/transactions/lock/lock_tracker.h` for the detailed interface design, and `utilities/transactions/lock/point_lock_tracker.cc` for the implementation.
In the future, a `RangeLockTracker` can be implemented to track range locks without affecting other components.
After this PR, a clean interface for lock manager should be possible, and then ideally, we can have pluggable locking protocols.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7013
Test Plan: Run `transaction_test` and `optimistic_transaction_test`.
Reviewed By: ajkr
Differential Revision: D22163706
Pulled By: cheng-chang
fbshipit-source-id: f2860577b5334e31dd2994f5bc6d7c40d502b1b4
2020-08-06 21:36:48 +02:00
|
|
|
lock_map->num_stripes_);
|
|
|
|
std::unique_ptr<LockTracker::KeyIterator> key_it(
|
|
|
|
tracker.GetKeyIterator(cf));
|
|
|
|
assert(key_it != nullptr);
|
|
|
|
while (key_it->HasNext()) {
|
|
|
|
const std::string& key = key_it->Next();
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
size_t stripe_num = lock_map->GetStripe(key);
|
|
|
|
keys_by_stripe[stripe_num].push_back(&key);
|
|
|
|
}
|
|
|
|
|
|
|
|
// For each stripe, grab the stripe mutex and unlock all keys in this stripe
|
|
|
|
for (auto& stripe_iter : keys_by_stripe) {
|
|
|
|
size_t stripe_num = stripe_iter.first;
|
|
|
|
auto& stripe_keys = stripe_iter.second;
|
|
|
|
|
|
|
|
assert(lock_map->lock_map_stripes_.size() > stripe_num);
|
2015-09-08 21:36:48 +02:00
|
|
|
LockMapStripe* stripe = lock_map->lock_map_stripes_.at(stripe_num);
|
|
|
|
|
2020-10-21 23:02:00 +02:00
|
|
|
stripe->stripe_mutex->Lock().PermitUncheckedError();
|
2015-09-08 21:36:48 +02:00
|
|
|
|
|
|
|
for (const std::string* key : stripe_keys) {
|
2016-12-06 02:18:14 +01:00
|
|
|
UnLockKey(txn, *key, stripe, lock_map, env);
|
2015-09-08 21:36:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
stripe->stripe_mutex->UnLock();
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
|
|
|
|
// Signal waiting threads to retry locking
|
2015-09-08 21:36:48 +02:00
|
|
|
stripe->stripe_cv->NotifyAll();
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-19 19:12:53 +02:00
|
|
|
PointLockManager::PointLockStatus PointLockManager::GetPointLockStatus() {
|
|
|
|
PointLockStatus data;
|
2016-09-28 02:43:06 +02:00
|
|
|
// Lock order here is important. The correct order is lock_map_mutex_, then
|
|
|
|
// for every column family ID in ascending order lock every stripe in
|
|
|
|
// ascending order.
|
|
|
|
InstrumentedMutexLock l(&lock_map_mutex_);
|
|
|
|
|
2016-09-28 10:23:33 +02:00
|
|
|
std::vector<uint32_t> cf_ids;
|
|
|
|
for (const auto& map : lock_maps_) {
|
|
|
|
cf_ids.push_back(map.first);
|
|
|
|
}
|
|
|
|
std::sort(cf_ids.begin(), cf_ids.end());
|
2016-09-28 02:43:06 +02:00
|
|
|
|
2016-09-28 10:23:33 +02:00
|
|
|
for (auto i : cf_ids) {
|
|
|
|
const auto& stripes = lock_maps_[i]->lock_map_stripes_;
|
2016-09-28 02:43:06 +02:00
|
|
|
// Iterate and lock all stripes in ascending order.
|
2016-09-28 10:23:33 +02:00
|
|
|
for (const auto& j : stripes) {
|
2020-10-21 23:02:00 +02:00
|
|
|
j->stripe_mutex->Lock().PermitUncheckedError();
|
2016-09-28 10:23:33 +02:00
|
|
|
for (const auto& it : j->keys) {
|
2016-12-06 02:18:14 +01:00
|
|
|
struct KeyLockInfo info;
|
|
|
|
info.exclusive = it.second.exclusive;
|
|
|
|
info.key = it.first;
|
|
|
|
for (const auto& id : it.second.txn_ids) {
|
|
|
|
info.ids.push_back(id);
|
|
|
|
}
|
|
|
|
data.insert({i, info});
|
2016-09-28 02:43:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unlock everything. Unlocking order is not important.
|
|
|
|
for (auto i : cf_ids) {
|
2016-09-28 10:23:33 +02:00
|
|
|
const auto& stripes = lock_maps_[i]->lock_map_stripes_;
|
|
|
|
for (const auto& j : stripes) {
|
2016-09-28 02:43:06 +02:00
|
|
|
j->stripe_mutex->UnLock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2020-10-19 19:12:53 +02:00
|
|
|
|
|
|
|
std::vector<DeadlockPath> PointLockManager::GetDeadlockInfoBuffer() {
|
2017-08-18 03:49:30 +02:00
|
|
|
return dlock_buffer_.PrepareBuffer();
|
|
|
|
}
|
|
|
|
|
2020-10-19 19:12:53 +02:00
|
|
|
void PointLockManager::Resize(uint32_t target_size) {
|
2017-08-18 03:49:30 +02:00
|
|
|
dlock_buffer_.Resize(target_size);
|
|
|
|
}
|
2016-09-28 02:43:06 +02:00
|
|
|
|
2020-10-19 19:12:53 +02:00
|
|
|
PointLockManager::RangeLockStatus PointLockManager::GetRangeLockStatus() {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Status PointLockManager::TryLock(PessimisticTransaction* /* txn */,
|
|
|
|
ColumnFamilyId /* cf_id */,
|
|
|
|
const Endpoint& /* start */,
|
|
|
|
const Endpoint& /* end */, Env* /* env */,
|
|
|
|
bool /* exclusive */) {
|
|
|
|
return Status::NotSupported(
|
|
|
|
"PointLockManager does not support range locking");
|
|
|
|
}
|
|
|
|
|
|
|
|
void PointLockManager::UnLock(PessimisticTransaction* /* txn */,
|
|
|
|
ColumnFamilyId /* cf_id */,
|
|
|
|
const Endpoint& /* start */,
|
|
|
|
const Endpoint& /* end */, Env* /* env */) {
|
|
|
|
// no-op
|
|
|
|
}
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
Pessimistic Transactions
Summary:
Initial implementation of Pessimistic Transactions. This diff contains the api changes discussed in D38913. This diff is pretty large, so let me know if people would prefer to meet up to discuss it.
MyRocks folks: please take a look at the API in include/rocksdb/utilities/transaction[_db].h and let me know if you have any issues.
Also, you'll notice a couple of TODOs in the implementation of RollbackToSavePoint(). After chatting with Siying, I'm going to send out a separate diff for an alternate implementation of this feature that implements the rollback inside of WriteBatch/WriteBatchWithIndex. We can then decide which route is preferable.
Next, I'm planning on doing some perf testing and then integrating this diff into MongoRocks for further testing.
Test Plan: Unit tests, db_bench parallel testing.
Reviewers: igor, rven, sdong, yhchiang, yoshinorim
Reviewed By: sdong
Subscribers: hermanlee4, maykov, spetrunia, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D40869
2015-05-26 02:37:33 +02:00
|
|
|
#endif // ROCKSDB_LITE
|