use of org.apache.pulsar.transaction.coordinator.proto.TxnStatus in project pulsar by apache.
the class TransactionMetadataStoreProviderTest method testGetTxnStatusSuccess.
@Test
public void testGetTxnStatusSuccess() throws Exception {
TxnID txnID = this.store.newTransaction(0L).get();
TxnStatus txnStatus = this.store.getTxnStatus(txnID).get();
assertEquals(txnStatus, TxnStatus.OPEN);
}
use of org.apache.pulsar.transaction.coordinator.proto.TxnStatus in project pulsar by apache.
the class TransactionMetadataStoreProviderTest method testUpdateTxnStatusSuccess.
@Test
public void testUpdateTxnStatusSuccess() throws Exception {
TxnID txnID = this.store.newTransaction(0L).get();
TxnStatus txnStatus = this.store.getTxnStatus(txnID).get();
assertEquals(txnStatus, TxnStatus.OPEN);
// update the status
this.store.updateTxnStatus(txnID, TxnStatus.COMMITTING, TxnStatus.OPEN, false).get();
// get the new status
TxnStatus newTxnStatus = this.store.getTxnStatus(txnID).get();
assertEquals(newTxnStatus, TxnStatus.COMMITTING);
}
use of org.apache.pulsar.transaction.coordinator.proto.TxnStatus in project pulsar by apache.
the class TransactionMetadataStoreProviderTest method testUpdateTxnStatusNotExpectedStatus.
@Test
public void testUpdateTxnStatusNotExpectedStatus() throws Exception {
TxnID txnID = this.store.newTransaction(0L).get();
TxnStatus txnStatus = this.store.getTxnStatus(txnID).get();
assertEquals(txnStatus, TxnStatus.OPEN);
// update the status
try {
this.store.updateTxnStatus(txnID, TxnStatus.COMMITTING, TxnStatus.COMMITTING, false).get();
fail("Should fail to update txn status if it is not in expected status");
} catch (ExecutionException ee) {
assertTrue(ee.getCause() instanceof InvalidTxnStatusException);
}
// get the txn status, it should be changed.
TxnStatus newTxnStatus = this.store.getTxnStatus(txnID).get();
assertEquals(newTxnStatus, TxnStatus.OPEN);
}
use of org.apache.pulsar.transaction.coordinator.proto.TxnStatus in project pulsar by apache.
the class TransactionMetadataStoreProviderTest method testUpdateTxnStatusCannotTransition.
@Test
public void testUpdateTxnStatusCannotTransition() throws Exception {
TxnID txnID = this.store.newTransaction(0L).get();
TxnStatus txnStatus = this.store.getTxnStatus(txnID).get();
assertEquals(txnStatus, TxnStatus.OPEN);
// update the status
try {
this.store.updateTxnStatus(txnID, TxnStatus.COMMITTED, TxnStatus.OPEN, false).get();
fail("Should fail to update txn status if it can not transition to the new status");
} catch (ExecutionException ee) {
assertTrue(ee.getCause() instanceof InvalidTxnStatusException);
}
// get the txn status, it should be changed.
TxnStatus newTxnStatus = this.store.getTxnStatus(txnID).get();
assertEquals(newTxnStatus, TxnStatus.OPEN);
}
use of org.apache.pulsar.transaction.coordinator.proto.TxnStatus in project pulsar by yahoo.
the class MLTransactionMetadataStore method addAckedPartitionToTxn.
@Override
public CompletableFuture<Void> addAckedPartitionToTxn(TxnID txnID, List<TransactionSubscription> txnSubscriptions) {
CompletableFuture<Void> promise = new CompletableFuture<>();
internalPinnedExecutor.execute(() -> {
if (!checkIfReady()) {
promise.completeExceptionally(new CoordinatorException.TransactionMetadataStoreStateException(tcID, State.Ready, getState(), "add acked partition"));
return;
}
getTxnPositionPair(txnID).thenCompose(txnMetaListPair -> {
TransactionMetadataEntry transactionMetadataEntry = new TransactionMetadataEntry().setTxnidMostBits(txnID.getMostSigBits()).setTxnidLeastBits(txnID.getLeastSigBits()).setMetadataOp(TransactionMetadataOp.ADD_SUBSCRIPTION).addAllSubscriptions(txnSubscriptionToSubscription(txnSubscriptions)).setLastModificationTime(System.currentTimeMillis()).setMaxLocalTxnId(sequenceIdGenerator.getCurrentSequenceId());
return transactionLog.append(transactionMetadataEntry).thenAccept(position -> {
appendLogCount.increment();
try {
synchronized (txnMetaListPair.getLeft()) {
txnMetaListPair.getLeft().addAckedPartitions(txnSubscriptions);
txnMetaMap.get(txnID.getLeastSigBits()).getRight().add(position);
}
promise.complete(null);
} catch (InvalidTxnStatusException e) {
transactionLog.deletePosition(Collections.singletonList(position));
log.error("TxnID : " + txnMetaListPair.getLeft().id().toString() + " add acked subscription error with TxnStatus : " + txnMetaListPair.getLeft().status().name(), e);
promise.completeExceptionally(e);
}
});
}).exceptionally(ex -> {
promise.completeExceptionally(ex);
return null;
});
});
return promise;
}
Aggregations