|
|
|
@ -21,14 +21,14 @@ TransactionBaseImpl::TransactionBaseImpl(DB* db, |
|
|
|
|
: db_(db), |
|
|
|
|
write_options_(write_options), |
|
|
|
|
cmp_(GetColumnFamilyUserComparator(db->DefaultColumnFamily())), |
|
|
|
|
write_batch_(new WriteBatchWithIndex(cmp_, 0, true)), |
|
|
|
|
start_time_(db_->GetEnv()->NowMicros()) {} |
|
|
|
|
start_time_(db_->GetEnv()->NowMicros()), |
|
|
|
|
write_batch_(cmp_, 0, true) {} |
|
|
|
|
|
|
|
|
|
TransactionBaseImpl::~TransactionBaseImpl() {} |
|
|
|
|
|
|
|
|
|
void TransactionBaseImpl::Clear() { |
|
|
|
|
save_points_.reset(nullptr); |
|
|
|
|
write_batch_->Clear(); |
|
|
|
|
write_batch_.Clear(); |
|
|
|
|
tracked_keys_.clear(); |
|
|
|
|
num_puts_ = 0; |
|
|
|
|
num_deletes_ = 0; |
|
|
|
@ -40,7 +40,11 @@ void TransactionBaseImpl::SetSnapshot() { |
|
|
|
|
auto db_impl = reinterpret_cast<DBImpl*>(db_); |
|
|
|
|
|
|
|
|
|
const Snapshot* snapshot = db_impl->GetSnapshotForWriteConflictBoundary(); |
|
|
|
|
snapshot_.reset(new ManagedSnapshot(db_, snapshot)); |
|
|
|
|
|
|
|
|
|
// Set a custom deleter for the snapshot_ SharedPtr as the snapshot needs to
|
|
|
|
|
// be released, not deleted when it is no longer referenced.
|
|
|
|
|
snapshot_.reset(snapshot, std::bind(&TransactionBaseImpl::ReleaseSnapshot, |
|
|
|
|
this, std::placeholders::_1, db_)); |
|
|
|
|
snapshot_needed_ = false; |
|
|
|
|
snapshot_notifier_ = nullptr; |
|
|
|
|
} |
|
|
|
@ -84,7 +88,7 @@ void TransactionBaseImpl::SetSavePoint() { |
|
|
|
|
} |
|
|
|
|
save_points_->emplace(snapshot_, snapshot_needed_, snapshot_notifier_, |
|
|
|
|
num_puts_, num_deletes_, num_merges_); |
|
|
|
|
write_batch_->SetSavePoint(); |
|
|
|
|
write_batch_.SetSavePoint(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Status TransactionBaseImpl::RollbackToSavePoint() { |
|
|
|
@ -99,7 +103,7 @@ Status TransactionBaseImpl::RollbackToSavePoint() { |
|
|
|
|
num_merges_ = save_point.num_merges_; |
|
|
|
|
|
|
|
|
|
// Rollback batch
|
|
|
|
|
Status s = write_batch_->RollbackToSavePoint(); |
|
|
|
|
Status s = write_batch_.RollbackToSavePoint(); |
|
|
|
|
assert(s.ok()); |
|
|
|
|
|
|
|
|
|
// Rollback any keys that were tracked since the last savepoint
|
|
|
|
@ -119,7 +123,7 @@ Status TransactionBaseImpl::RollbackToSavePoint() { |
|
|
|
|
|
|
|
|
|
return s; |
|
|
|
|
} else { |
|
|
|
|
assert(write_batch_->RollbackToSavePoint().IsNotFound()); |
|
|
|
|
assert(write_batch_.RollbackToSavePoint().IsNotFound()); |
|
|
|
|
return Status::NotFound(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -127,8 +131,8 @@ Status TransactionBaseImpl::RollbackToSavePoint() { |
|
|
|
|
Status TransactionBaseImpl::Get(const ReadOptions& read_options, |
|
|
|
|
ColumnFamilyHandle* column_family, |
|
|
|
|
const Slice& key, std::string* value) { |
|
|
|
|
return write_batch_->GetFromBatchAndDB(db_, read_options, column_family, key, |
|
|
|
|
value); |
|
|
|
|
return write_batch_.GetFromBatchAndDB(db_, read_options, column_family, key, |
|
|
|
|
value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Status TransactionBaseImpl::GetForUpdate(const ReadOptions& read_options, |
|
|
|
@ -189,7 +193,7 @@ Iterator* TransactionBaseImpl::GetIterator(const ReadOptions& read_options) { |
|
|
|
|
Iterator* db_iter = db_->NewIterator(read_options); |
|
|
|
|
assert(db_iter); |
|
|
|
|
|
|
|
|
|
return write_batch_->NewIteratorWithBase(db_iter); |
|
|
|
|
return write_batch_.NewIteratorWithBase(db_iter); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Iterator* TransactionBaseImpl::GetIterator(const ReadOptions& read_options, |
|
|
|
@ -197,7 +201,7 @@ Iterator* TransactionBaseImpl::GetIterator(const ReadOptions& read_options, |
|
|
|
|
Iterator* db_iter = db_->NewIterator(read_options, column_family); |
|
|
|
|
assert(db_iter); |
|
|
|
|
|
|
|
|
|
return write_batch_->NewIteratorWithBase(column_family, db_iter); |
|
|
|
|
return write_batch_.NewIteratorWithBase(column_family, db_iter); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Status TransactionBaseImpl::Put(ColumnFamilyHandle* column_family, |
|
|
|
@ -353,11 +357,11 @@ Status TransactionBaseImpl::DeleteUntracked(ColumnFamilyHandle* column_family, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void TransactionBaseImpl::PutLogData(const Slice& blob) { |
|
|
|
|
write_batch_->PutLogData(blob); |
|
|
|
|
write_batch_.PutLogData(blob); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
WriteBatchWithIndex* TransactionBaseImpl::GetWriteBatch() { |
|
|
|
|
return write_batch_.get(); |
|
|
|
|
return &write_batch_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
uint64_t TransactionBaseImpl::GetElapsedTime() const { |
|
|
|
@ -413,13 +417,17 @@ const TransactionKeyMap* TransactionBaseImpl::GetTrackedKeysSinceSavePoint() { |
|
|
|
|
WriteBatchBase* TransactionBaseImpl::GetBatchForWrite() { |
|
|
|
|
if (indexing_enabled_) { |
|
|
|
|
// Use WriteBatchWithIndex
|
|
|
|
|
return write_batch_.get(); |
|
|
|
|
return &write_batch_; |
|
|
|
|
} else { |
|
|
|
|
// Don't use WriteBatchWithIndex. Return base WriteBatch.
|
|
|
|
|
return write_batch_->GetWriteBatch(); |
|
|
|
|
return write_batch_.GetWriteBatch(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void TransactionBaseImpl::ReleaseSnapshot(const Snapshot* snapshot, DB* db) { |
|
|
|
|
db->ReleaseSnapshot(snapshot); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // namespace rocksdb
|
|
|
|
|
|
|
|
|
|
#endif // ROCKSDB_LITE
|
|
|
|
|