Skip to content

Commit

Permalink
Fix handling of write intents for aborted transaction
Browse files Browse the repository at this point in the history
Summary:
Transaction could be aborted while we are trying to write intents for it.
So we should handle the case when metadata is not present for transaction.
Also register request to be able to update last write id when operation finishes.

Test Plan: ybd --java-test org.yb.cql.TestReturnsClause#testBatchDMLWithUniqueIndex

Reviewers: mikhail, venkatesh, timur, robert

Reviewed By: robert

Subscribers: ybase

Differential Revision: https://phabricator.dev.yugabyte.com/D5302
  • Loading branch information
spolitov committed Aug 9, 2018
1 parent 73a5e9d commit d55bad6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/yb/tablet/tablet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -640,14 +640,21 @@ void Tablet::PrepareTransactionWriteBatch(
const KeyValueWriteBatchPB& put_batch,
HybridTime hybrid_time,
rocksdb::WriteBatch* rocksdb_write_batch) {
RequestScope request_scope(transaction_participant_.get());
if (put_batch.transaction().has_isolation()) {
// Store transaction metadata (status tablet, isolation level etc.)
transaction_participant()->Add(put_batch.transaction(), rocksdb_write_batch);
}
auto transaction_id = CHECK_RESULT(
FullyDecodeTransactionId(put_batch.transaction().transaction_id()));
auto metadata_with_write_id = transaction_participant()->MetadataWithWriteId(transaction_id);
CHECK(metadata_with_write_id) << "Transaction metadata missing: " << transaction_id;
if (!metadata_with_write_id) {
// If metadata is missing it could be caused by aborted and removed transaction.
// In this case we should not add new intents for it.
LOG(INFO) << "Transaction metadata missing: " << transaction_id
<< ", looks like it was just aborted";
return;
}

auto isolation_level = metadata_with_write_id->first.isolation;
auto write_id = metadata_with_write_id->second;
Expand Down

0 comments on commit d55bad6

Please sign in to comment.