2017-08-03 15:46:47 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
|
2017-08-07 23:07:40 +00:00
|
|
|
#include "utilities/transactions/write_prepared_txn.h"
|
2017-08-03 15:46:47 +00:00
|
|
|
|
2018-01-09 16:47:46 +00:00
|
|
|
#ifndef __STDC_FORMAT_MACROS
|
|
|
|
#define __STDC_FORMAT_MACROS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
2017-08-03 15:46:47 +00:00
|
|
|
#include <map>
|
2018-02-06 02:32:54 +00:00
|
|
|
#include <set>
|
2017-08-03 15:46:47 +00:00
|
|
|
|
|
|
|
#include "db/column_family.h"
|
|
|
|
#include "db/db_impl.h"
|
|
|
|
#include "rocksdb/db.h"
|
|
|
|
#include "rocksdb/status.h"
|
|
|
|
#include "rocksdb/utilities/transaction_db.h"
|
2017-08-07 23:07:40 +00:00
|
|
|
#include "utilities/transactions/pessimistic_transaction.h"
|
2017-11-02 18:05:55 +00:00
|
|
|
#include "utilities/transactions/write_prepared_txn_db.h"
|
2017-08-03 15:46:47 +00:00
|
|
|
|
|
|
|
namespace rocksdb {
|
|
|
|
|
|
|
|
struct WriteOptions;
|
|
|
|
|
2017-08-16 23:49:11 +00:00
|
|
|
WritePreparedTxn::WritePreparedTxn(WritePreparedTxnDB* txn_db,
|
|
|
|
const WriteOptions& write_options,
|
|
|
|
const TransactionOptions& txn_options)
|
|
|
|
: PessimisticTransaction(txn_db, write_options, txn_options),
|
2018-02-06 02:32:54 +00:00
|
|
|
wpt_db_(txn_db) {}
|
2017-08-03 15:46:47 +00:00
|
|
|
|
2017-09-11 15:58:52 +00:00
|
|
|
Status WritePreparedTxn::Get(const ReadOptions& read_options,
|
|
|
|
ColumnFamilyHandle* column_family,
|
|
|
|
const Slice& key, PinnableSlice* pinnable_val) {
|
2017-10-06 21:18:30 +00:00
|
|
|
auto snapshot = read_options.snapshot;
|
2017-09-11 15:58:52 +00:00
|
|
|
auto snap_seq =
|
|
|
|
snapshot != nullptr ? snapshot->GetSequenceNumber() : kMaxSequenceNumber;
|
|
|
|
|
|
|
|
WritePreparedTxnReadCallback callback(wpt_db_, snap_seq);
|
|
|
|
return write_batch_.GetFromBatchAndDB(db_, read_options, column_family, key,
|
|
|
|
pinnable_val, &callback);
|
|
|
|
}
|
|
|
|
|
2017-10-10 00:05:34 +00:00
|
|
|
Iterator* WritePreparedTxn::GetIterator(const ReadOptions& options) {
|
|
|
|
// Make sure to get iterator from WritePrepareTxnDB, not the root db.
|
|
|
|
Iterator* db_iter = wpt_db_->NewIterator(options);
|
|
|
|
assert(db_iter);
|
|
|
|
|
|
|
|
return write_batch_.NewIteratorWithBase(db_iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
Iterator* WritePreparedTxn::GetIterator(const ReadOptions& options,
|
|
|
|
ColumnFamilyHandle* column_family) {
|
|
|
|
// Make sure to get iterator from WritePrepareTxnDB, not the root db.
|
|
|
|
Iterator* db_iter = wpt_db_->NewIterator(options, column_family);
|
|
|
|
assert(db_iter);
|
|
|
|
|
2018-01-09 16:47:46 +00:00
|
|
|
return write_batch_.NewIteratorWithBase(column_family, db_iter);
|
2017-10-10 00:05:34 +00:00
|
|
|
}
|
|
|
|
|
2017-08-07 23:07:40 +00:00
|
|
|
Status WritePreparedTxn::PrepareInternal() {
|
2017-08-16 23:49:11 +00:00
|
|
|
WriteOptions write_options = write_options_;
|
|
|
|
write_options.disableWAL = false;
|
2017-12-01 07:39:56 +00:00
|
|
|
const bool WRITE_AFTER_COMMIT = true;
|
2017-11-11 19:23:43 +00:00
|
|
|
WriteBatchInternal::MarkEndPrepare(GetWriteBatch()->GetWriteBatch(), name_,
|
2017-12-01 07:39:56 +00:00
|
|
|
!WRITE_AFTER_COMMIT);
|
|
|
|
const bool DISABLE_MEMTABLE = true;
|
2017-09-18 21:36:53 +00:00
|
|
|
uint64_t seq_used = kMaxSequenceNumber;
|
2018-02-06 02:32:54 +00:00
|
|
|
// For each duplicate key we account for a new sub-batch
|
|
|
|
prepare_batch_cnt_ = 1;
|
2018-02-16 16:36:47 +00:00
|
|
|
if (UNLIKELY(GetWriteBatch()->HasDuplicateKeys())) {
|
|
|
|
ROCKS_LOG_WARN(db_impl_->immutable_db_options().info_log,
|
|
|
|
"Duplicate key overhead");
|
2018-02-06 02:32:54 +00:00
|
|
|
SubBatchCounter counter(*wpt_db_->GetCFComparatorMap());
|
|
|
|
auto s = GetWriteBatch()->GetWriteBatch()->Iterate(&counter);
|
|
|
|
assert(s.ok());
|
|
|
|
prepare_batch_cnt_ = counter.BatchCount();
|
2017-10-05 14:28:37 +00:00
|
|
|
}
|
2017-08-16 23:49:11 +00:00
|
|
|
Status s =
|
|
|
|
db_impl_->WriteImpl(write_options, GetWriteBatch()->GetWriteBatch(),
|
|
|
|
/*callback*/ nullptr, &log_number_, /*log ref*/ 0,
|
2018-02-06 02:32:54 +00:00
|
|
|
!DISABLE_MEMTABLE, &seq_used, prepare_batch_cnt_);
|
2018-01-09 16:47:46 +00:00
|
|
|
assert(!s.ok() || seq_used != kMaxSequenceNumber);
|
2017-09-28 23:43:04 +00:00
|
|
|
auto prepare_seq = seq_used;
|
|
|
|
SetId(prepare_seq);
|
2018-01-09 16:47:46 +00:00
|
|
|
// TODO(myabandeh): AddPrepared better to be called in the pre-release
|
|
|
|
// callback otherwise there is a non-zero chance of max dvancing prepare_seq
|
|
|
|
// and readers assume the data as committed.
|
|
|
|
if (s.ok()) {
|
|
|
|
wpt_db_->AddPrepared(prepare_seq);
|
|
|
|
}
|
2017-08-16 23:49:11 +00:00
|
|
|
return s;
|
2017-08-03 15:46:47 +00:00
|
|
|
}
|
|
|
|
|
2017-08-07 23:07:40 +00:00
|
|
|
Status WritePreparedTxn::CommitWithoutPrepareInternal() {
|
2018-02-06 02:32:54 +00:00
|
|
|
// For each duplicate key we account for a new sub-batch
|
|
|
|
size_t batch_cnt = 1;
|
2018-02-16 16:36:47 +00:00
|
|
|
if (UNLIKELY(GetWriteBatch()->HasDuplicateKeys())) {
|
2018-02-06 02:32:54 +00:00
|
|
|
batch_cnt = 0; // this will trigger a batch cnt compute
|
2017-10-05 14:28:37 +00:00
|
|
|
}
|
2018-02-06 02:32:54 +00:00
|
|
|
return CommitBatchInternal(GetWriteBatch()->GetWriteBatch(), batch_cnt);
|
2017-09-08 22:53:51 +00:00
|
|
|
}
|
|
|
|
|
2018-02-06 02:32:54 +00:00
|
|
|
Status WritePreparedTxn::CommitBatchInternal(WriteBatch* batch,
|
|
|
|
size_t batch_cnt) {
|
2018-02-13 00:27:39 +00:00
|
|
|
return wpt_db_->WriteInternal(write_options_, batch, batch_cnt, this);
|
2017-08-03 15:46:47 +00:00
|
|
|
}
|
|
|
|
|
2017-08-07 23:07:40 +00:00
|
|
|
Status WritePreparedTxn::CommitInternal() {
|
2018-01-09 16:47:46 +00:00
|
|
|
ROCKS_LOG_DETAILS(db_impl_->immutable_db_options().info_log,
|
|
|
|
"CommitInternal prepare_seq: %" PRIu64, GetID());
|
2017-08-16 23:49:11 +00:00
|
|
|
// We take the commit-time batch and append the Commit marker.
|
|
|
|
// The Memtable will ignore the Commit marker in non-recovery mode
|
|
|
|
WriteBatch* working_batch = GetCommitTimeWriteBatch();
|
2017-10-06 21:18:30 +00:00
|
|
|
const bool empty = working_batch->Count() == 0;
|
2017-08-16 23:49:11 +00:00
|
|
|
WriteBatchInternal::MarkCommit(working_batch, name_);
|
|
|
|
|
2017-11-02 00:23:52 +00:00
|
|
|
const bool for_recovery = use_only_the_last_commit_time_batch_for_recovery_;
|
|
|
|
if (!empty && for_recovery) {
|
|
|
|
// When not writing to memtable, we can still cache the latest write batch.
|
|
|
|
// The cached batch will be written to memtable in WriteRecoverableState
|
|
|
|
// during FlushMemTable
|
|
|
|
WriteBatchInternal::SetAsLastestPersistentState(working_batch);
|
|
|
|
}
|
2017-08-16 23:49:11 +00:00
|
|
|
|
2017-12-01 07:39:56 +00:00
|
|
|
auto prepare_seq = GetId();
|
|
|
|
const bool includes_data = !empty && !for_recovery;
|
2018-02-06 02:32:54 +00:00
|
|
|
assert(prepare_batch_cnt_);
|
|
|
|
size_t commit_batch_cnt = 0;
|
2018-02-16 16:36:47 +00:00
|
|
|
if (UNLIKELY(includes_data)) {
|
|
|
|
ROCKS_LOG_WARN(db_impl_->immutable_db_options().info_log,
|
|
|
|
"Duplicate key overhead");
|
2018-02-06 02:32:54 +00:00
|
|
|
SubBatchCounter counter(*wpt_db_->GetCFComparatorMap());
|
|
|
|
auto s = working_batch->Iterate(&counter);
|
|
|
|
assert(s.ok());
|
|
|
|
commit_batch_cnt = counter.BatchCount();
|
|
|
|
}
|
2017-12-01 07:39:56 +00:00
|
|
|
WritePreparedCommitEntryPreReleaseCallback update_commit_map(
|
2018-02-06 02:32:54 +00:00
|
|
|
wpt_db_, db_impl_, prepare_seq, prepare_batch_cnt_, commit_batch_cnt);
|
2017-12-01 07:39:56 +00:00
|
|
|
const bool disable_memtable = !includes_data;
|
2017-09-28 23:43:04 +00:00
|
|
|
uint64_t seq_used = kMaxSequenceNumber;
|
|
|
|
// Since the prepared batch is directly written to memtable, there is already
|
|
|
|
// a connection between the memtable and its WAL, so there is no need to
|
|
|
|
// redundantly reference the log that contains the prepared data.
|
|
|
|
const uint64_t zero_log_number = 0ull;
|
2018-02-16 16:36:47 +00:00
|
|
|
size_t batch_cnt = UNLIKELY(commit_batch_cnt) ? commit_batch_cnt : 1;
|
2017-12-01 07:39:56 +00:00
|
|
|
auto s = db_impl_->WriteImpl(write_options_, working_batch, nullptr, nullptr,
|
|
|
|
zero_log_number, disable_memtable, &seq_used,
|
2018-02-06 02:32:54 +00:00
|
|
|
batch_cnt, &update_commit_map);
|
2018-01-09 16:47:46 +00:00
|
|
|
assert(!s.ok() || seq_used != kMaxSequenceNumber);
|
2017-08-16 23:49:11 +00:00
|
|
|
return s;
|
2017-08-07 23:07:40 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 02:46:42 +00:00
|
|
|
Status WritePreparedTxn::RollbackInternal() {
|
2018-01-09 16:47:46 +00:00
|
|
|
ROCKS_LOG_WARN(db_impl_->immutable_db_options().info_log,
|
|
|
|
"RollbackInternal prepare_seq: %" PRIu64, GetId());
|
2017-10-03 02:46:42 +00:00
|
|
|
WriteBatch rollback_batch;
|
|
|
|
assert(GetId() != kMaxSequenceNumber);
|
|
|
|
assert(GetId() > 0);
|
|
|
|
// In WritePrepared, the txn is is the same as prepare seq
|
|
|
|
auto last_visible_txn = GetId() - 1;
|
|
|
|
struct RollbackWriteBatchBuilder : public WriteBatch::Handler {
|
|
|
|
DBImpl* db_;
|
|
|
|
ReadOptions roptions;
|
|
|
|
WritePreparedTxnReadCallback callback;
|
|
|
|
WriteBatch* rollback_batch_;
|
2018-02-06 02:32:54 +00:00
|
|
|
std::map<uint32_t, const Comparator*>& comparators_;
|
|
|
|
using CFKeys = std::set<Slice, SetComparator>;
|
|
|
|
std::map<uint32_t, CFKeys> keys_;
|
|
|
|
RollbackWriteBatchBuilder(
|
|
|
|
DBImpl* db, WritePreparedTxnDB* wpt_db, SequenceNumber snap_seq,
|
|
|
|
WriteBatch* dst_batch,
|
|
|
|
std::map<uint32_t, const Comparator*>& comparators)
|
|
|
|
: db_(db),
|
|
|
|
callback(wpt_db, snap_seq),
|
|
|
|
rollback_batch_(dst_batch),
|
|
|
|
comparators_(comparators) {}
|
2017-10-03 02:46:42 +00:00
|
|
|
|
|
|
|
Status Rollback(uint32_t cf, const Slice& key) {
|
2018-02-06 02:32:54 +00:00
|
|
|
Status s;
|
|
|
|
CFKeys& cf_keys = keys_[cf];
|
|
|
|
if (cf_keys.size() == 0) { // just inserted
|
|
|
|
auto cmp = comparators_[cf];
|
|
|
|
keys_[cf] = CFKeys(SetComparator(cmp));
|
|
|
|
}
|
|
|
|
auto it = cf_keys.insert(key);
|
|
|
|
if (it.second ==
|
|
|
|
false) { // second is false if a element already existed.
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2017-10-03 02:46:42 +00:00
|
|
|
PinnableSlice pinnable_val;
|
|
|
|
bool not_used;
|
|
|
|
auto cf_handle = db_->GetColumnFamilyHandle(cf);
|
2018-02-06 02:32:54 +00:00
|
|
|
s = db_->GetImpl(roptions, cf_handle, key, &pinnable_val, ¬_used,
|
|
|
|
&callback);
|
2017-10-03 02:46:42 +00:00
|
|
|
assert(s.ok() || s.IsNotFound());
|
|
|
|
if (s.ok()) {
|
|
|
|
s = rollback_batch_->Put(cf_handle, key, pinnable_val);
|
|
|
|
assert(s.ok());
|
|
|
|
} else if (s.IsNotFound()) {
|
|
|
|
// There has been no readable value before txn. By adding a delete we
|
|
|
|
// make sure that there will be none afterwards either.
|
|
|
|
s = rollback_batch_->Delete(cf_handle, key);
|
|
|
|
assert(s.ok());
|
|
|
|
} else {
|
|
|
|
// Unexpected status. Return it to the user.
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2018-02-22 20:36:41 +00:00
|
|
|
Status PutCF(uint32_t cf, const Slice& key, const Slice& val) override {
|
2017-10-03 02:46:42 +00:00
|
|
|
return Rollback(cf, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status DeleteCF(uint32_t cf, const Slice& key) override {
|
|
|
|
return Rollback(cf, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status SingleDeleteCF(uint32_t cf, const Slice& key) override {
|
|
|
|
return Rollback(cf, key);
|
|
|
|
}
|
|
|
|
|
2018-02-22 20:36:41 +00:00
|
|
|
Status MergeCF(uint32_t cf, const Slice& key, const Slice& val) override {
|
2017-10-03 02:46:42 +00:00
|
|
|
return Rollback(cf, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status MarkNoop(bool) override { return Status::OK(); }
|
|
|
|
Status MarkBeginPrepare() override { return Status::OK(); }
|
|
|
|
Status MarkEndPrepare(const Slice&) override { return Status::OK(); }
|
|
|
|
Status MarkCommit(const Slice&) override { return Status::OK(); }
|
|
|
|
Status MarkRollback(const Slice&) override {
|
|
|
|
return Status::InvalidArgument();
|
|
|
|
}
|
2017-11-11 19:23:43 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual bool WriteAfterCommit() const override { return false; }
|
2018-02-06 02:32:54 +00:00
|
|
|
} rollback_handler(db_impl_, wpt_db_, last_visible_txn, &rollback_batch,
|
|
|
|
*wpt_db_->GetCFComparatorMap());
|
2017-10-03 02:46:42 +00:00
|
|
|
auto s = GetWriteBatch()->GetWriteBatch()->Iterate(&rollback_handler);
|
|
|
|
assert(s.ok());
|
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
2017-11-15 16:19:57 +00:00
|
|
|
// The Rollback marker will be used as a batch separator
|
2017-10-03 02:46:42 +00:00
|
|
|
WriteBatchInternal::MarkRollback(&rollback_batch, name_);
|
2017-12-18 16:03:18 +00:00
|
|
|
bool do_one_write = !db_impl_->immutable_db_options().two_write_queues;
|
2017-12-01 07:39:56 +00:00
|
|
|
const bool DISABLE_MEMTABLE = true;
|
2017-10-03 02:46:42 +00:00
|
|
|
const uint64_t no_log_ref = 0;
|
|
|
|
uint64_t seq_used = kMaxSequenceNumber;
|
2018-02-06 02:32:54 +00:00
|
|
|
const size_t ZERO_PREPARES = 0;
|
|
|
|
const size_t ONE_BATCH = 1;
|
2017-12-18 16:03:18 +00:00
|
|
|
WritePreparedCommitEntryPreReleaseCallback update_commit_map(
|
2018-02-06 02:32:54 +00:00
|
|
|
wpt_db_, db_impl_, kMaxSequenceNumber, ZERO_PREPARES, ONE_BATCH);
|
2017-10-03 02:46:42 +00:00
|
|
|
s = db_impl_->WriteImpl(write_options_, &rollback_batch, nullptr, nullptr,
|
2018-02-06 02:32:54 +00:00
|
|
|
no_log_ref, !DISABLE_MEMTABLE, &seq_used, ONE_BATCH,
|
2017-12-18 16:03:18 +00:00
|
|
|
do_one_write ? &update_commit_map : nullptr);
|
2018-01-09 16:47:46 +00:00
|
|
|
assert(!s.ok() || seq_used != kMaxSequenceNumber);
|
2017-12-01 07:39:56 +00:00
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
2017-12-18 16:03:18 +00:00
|
|
|
if (do_one_write) {
|
|
|
|
// Mark the txn as rolled back
|
|
|
|
uint64_t& rollback_seq = seq_used;
|
|
|
|
wpt_db_->RollbackPrepared(GetId(), rollback_seq);
|
|
|
|
return s;
|
|
|
|
} // else do the 2nd write for commit
|
2017-10-03 02:46:42 +00:00
|
|
|
uint64_t& prepare_seq = seq_used;
|
2018-01-09 16:47:46 +00:00
|
|
|
ROCKS_LOG_DETAILS(db_impl_->immutable_db_options().info_log,
|
|
|
|
"RollbackInternal 2nd write prepare_seq: %" PRIu64,
|
|
|
|
prepare_seq);
|
2017-12-01 07:39:56 +00:00
|
|
|
// Commit the batch by writing an empty batch to the queue that will release
|
|
|
|
// the commit sequence number to readers.
|
2018-02-21 21:40:31 +00:00
|
|
|
const size_t ZERO_COMMITS = 0;
|
|
|
|
const bool PREP_HEAP_SKIPPED = true;
|
2017-12-18 16:03:18 +00:00
|
|
|
WritePreparedCommitEntryPreReleaseCallback update_commit_map_with_prepare(
|
2018-02-21 21:40:31 +00:00
|
|
|
wpt_db_, db_impl_, prepare_seq, ONE_BATCH, ZERO_COMMITS,
|
|
|
|
PREP_HEAP_SKIPPED);
|
2017-12-01 07:39:56 +00:00
|
|
|
WriteBatch empty_batch;
|
|
|
|
empty_batch.PutLogData(Slice());
|
|
|
|
// In the absence of Prepare markers, use Noop as a batch separator
|
|
|
|
WriteBatchInternal::InsertNoop(&empty_batch);
|
|
|
|
s = db_impl_->WriteImpl(write_options_, &empty_batch, nullptr, nullptr,
|
2018-02-06 02:32:54 +00:00
|
|
|
no_log_ref, DISABLE_MEMTABLE, &seq_used, ONE_BATCH,
|
2017-12-18 16:03:18 +00:00
|
|
|
&update_commit_map_with_prepare);
|
2018-01-09 16:47:46 +00:00
|
|
|
assert(!s.ok() || seq_used != kMaxSequenceNumber);
|
2017-10-03 02:46:42 +00:00
|
|
|
// Mark the txn as rolled back
|
2017-12-01 07:39:56 +00:00
|
|
|
uint64_t& rollback_seq = seq_used;
|
2018-01-09 16:47:46 +00:00
|
|
|
if (s.ok()) {
|
|
|
|
wpt_db_->RollbackPrepared(GetId(), rollback_seq);
|
|
|
|
}
|
2017-10-03 02:46:42 +00:00
|
|
|
|
|
|
|
return s;
|
2017-08-03 15:46:47 +00:00
|
|
|
}
|
|
|
|
|
2017-11-02 01:56:25 +00:00
|
|
|
Status WritePreparedTxn::ValidateSnapshot(ColumnFamilyHandle* column_family,
|
|
|
|
const Slice& key,
|
2017-11-11 21:08:22 +00:00
|
|
|
SequenceNumber* tracked_at_seq) {
|
2017-11-02 01:56:25 +00:00
|
|
|
assert(snapshot_);
|
|
|
|
|
|
|
|
SequenceNumber snap_seq = snapshot_->GetSequenceNumber();
|
2017-11-11 21:08:22 +00:00
|
|
|
// tracked_at_seq is either max or the last snapshot with which this key was
|
2017-11-02 01:56:25 +00:00
|
|
|
// trackeed so there is no need to apply the IsInSnapshot to this comparison
|
2017-11-11 21:08:22 +00:00
|
|
|
// here as tracked_at_seq is not a prepare seq.
|
|
|
|
if (*tracked_at_seq <= snap_seq) {
|
2017-11-02 01:56:25 +00:00
|
|
|
// If the key has been previous validated at a sequence number earlier
|
|
|
|
// than the curent snapshot's sequence number, we already know it has not
|
|
|
|
// been modified.
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
2017-11-11 21:08:22 +00:00
|
|
|
*tracked_at_seq = snap_seq;
|
2017-11-02 01:56:25 +00:00
|
|
|
|
|
|
|
ColumnFamilyHandle* cfh =
|
|
|
|
column_family ? column_family : db_impl_->DefaultColumnFamily();
|
|
|
|
|
|
|
|
WritePreparedTxnReadCallback snap_checker(wpt_db_, snap_seq);
|
2017-11-11 21:08:22 +00:00
|
|
|
return TransactionUtil::CheckKeyForConflicts(db_impl_, cfh, key.ToString(),
|
|
|
|
snap_seq, false /* cache_only */,
|
|
|
|
&snap_checker);
|
2017-11-02 01:56:25 +00:00
|
|
|
}
|
|
|
|
|
2018-02-06 02:32:54 +00:00
|
|
|
Status WritePreparedTxn::RebuildFromWriteBatch(WriteBatch* src_batch) {
|
|
|
|
auto ret = PessimisticTransaction::RebuildFromWriteBatch(src_batch);
|
|
|
|
prepare_batch_cnt_ = 1;
|
2018-02-16 16:36:47 +00:00
|
|
|
if (UNLIKELY(GetWriteBatch()->HasDuplicateKeys())) {
|
|
|
|
ROCKS_LOG_WARN(db_impl_->immutable_db_options().info_log,
|
|
|
|
"Duplicate key overhead");
|
2018-02-06 02:32:54 +00:00
|
|
|
SubBatchCounter counter(*wpt_db_->GetCFComparatorMap());
|
|
|
|
auto s = GetWriteBatch()->GetWriteBatch()->Iterate(&counter);
|
|
|
|
assert(s.ok());
|
|
|
|
prepare_batch_cnt_ = counter.BatchCount();
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-08-03 15:46:47 +00:00
|
|
|
} // namespace rocksdb
|
|
|
|
|
|
|
|
#endif // ROCKSDB_LITE
|