[HUDI-3029] Transaction manager: avoid deadlock when doing begin and end transactions (#4373)
This commit is contained in:
committed by
GitHub
parent
d1d48ed494
commit
733732be7b
@@ -85,7 +85,7 @@ public class TransactionManager implements Serializable {
|
||||
private synchronized void reset(Option<HoodieInstant> callerInstant,
|
||||
Option<HoodieInstant> newTxnOwnerInstant,
|
||||
Option<HoodieInstant> lastCompletedTxnOwnerInstant) {
|
||||
if (!this.currentTxnOwnerInstant.isPresent() || this.currentTxnOwnerInstant == callerInstant) {
|
||||
if (!this.currentTxnOwnerInstant.isPresent() || this.currentTxnOwnerInstant.get().equals(callerInstant.get())) {
|
||||
this.currentTxnOwnerInstant = newTxnOwnerInstant;
|
||||
this.lastCompletedTxnOwnerInstant = lastCompletedTxnOwnerInstant;
|
||||
}
|
||||
|
||||
@@ -190,6 +190,22 @@ public class TestTransactionManager extends HoodieCommonTestHarness {
|
||||
transactionManager.endTransaction();
|
||||
Assertions.assertFalse(transactionManager.getCurrentTransactionOwner().isPresent());
|
||||
Assertions.assertFalse(transactionManager.getLastCompletedTransactionOwner().isPresent());
|
||||
|
||||
// 5. Transactions with new instants but with same timestamps should properly reset owners
|
||||
transactionManager.beginTransaction(getInstant("0000005"), Option.empty());
|
||||
Assertions.assertTrue(transactionManager.getCurrentTransactionOwner().isPresent());
|
||||
Assertions.assertFalse(transactionManager.getLastCompletedTransactionOwner().isPresent());
|
||||
transactionManager.endTransaction(getInstant("0000005"));
|
||||
Assertions.assertFalse(transactionManager.getCurrentTransactionOwner().isPresent());
|
||||
Assertions.assertFalse(transactionManager.getLastCompletedTransactionOwner().isPresent());
|
||||
|
||||
// 6. Transactions with no owners should also go through
|
||||
transactionManager.beginTransaction(Option.empty(), Option.empty());
|
||||
Assertions.assertFalse(transactionManager.getCurrentTransactionOwner().isPresent());
|
||||
Assertions.assertFalse(transactionManager.getLastCompletedTransactionOwner().isPresent());
|
||||
transactionManager.endTransaction(Option.empty());
|
||||
Assertions.assertFalse(transactionManager.getCurrentTransactionOwner().isPresent());
|
||||
Assertions.assertFalse(transactionManager.getLastCompletedTransactionOwner().isPresent());
|
||||
}
|
||||
|
||||
private Option<HoodieInstant> getInstant(String timestamp) {
|
||||
|
||||
Reference in New Issue
Block a user