use of org.apache.pulsar.broker.TransactionMetadataStoreService in project pulsar by apache.
the class ServerCnx method handleAddSubscriptionToTxn.
@Override
protected void handleAddSubscriptionToTxn(CommandAddSubscriptionToTxn command) {
final TxnID txnID = new TxnID(command.getTxnidMostBits(), command.getTxnidLeastBits());
final long requestId = command.getRequestId();
if (log.isDebugEnabled()) {
log.debug("Receive add published partition to txn request {} from {} with txnId {}", requestId, remoteAddress, txnID);
}
final TransactionCoordinatorID tcId = TransactionCoordinatorID.get(command.getTxnidMostBits());
if (!checkTransactionEnableAndSendError(requestId)) {
return;
}
TransactionMetadataStoreService transactionMetadataStoreService = service.pulsar().getTransactionMetadataStoreService();
transactionMetadataStoreService.addAckedPartitionToTxn(txnID, MLTransactionMetadataStore.subscriptionToTxnSubscription(command.getSubscriptionsList())).whenComplete(((v, ex) -> {
if (ex == null) {
if (log.isDebugEnabled()) {
log.debug("Send response success for add published partition to txn request {}", requestId);
}
ctx.writeAndFlush(Commands.newAddSubscriptionToTxnResponse(requestId, txnID.getLeastSigBits(), txnID.getMostSigBits()));
} else {
ex = handleTxnException(ex, BaseCommand.Type.ADD_SUBSCRIPTION_TO_TXN.name(), requestId);
ctx.writeAndFlush(Commands.newAddSubscriptionToTxnResponse(requestId, txnID.getMostSigBits(), BrokerServiceException.getClientErrorCode(ex), ex.getMessage()));
transactionMetadataStoreService.handleOpFail(ex, tcId);
}
}));
}
use of org.apache.pulsar.broker.TransactionMetadataStoreService in project pulsar by apache.
the class TransactionCoordinatorClientTest method afterSetup.
@Override
protected void afterSetup() throws Exception {
for (PulsarService pulsarService : pulsarServices) {
TransactionBufferClient tbClient = Mockito.mock(TransactionBufferClientImpl.class);
Mockito.when(tbClient.commitTxnOnTopic(anyString(), anyLong(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(null));
Mockito.when(tbClient.abortTxnOnTopic(anyString(), anyLong(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(null));
Mockito.when(tbClient.commitTxnOnSubscription(anyString(), anyString(), anyLong(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(null));
Mockito.when(tbClient.abortTxnOnSubscription(anyString(), anyString(), anyLong(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(null));
TransactionMetadataStoreService metadataStoreService = pulsarService.getTransactionMetadataStoreService();
Class<TransactionMetadataStoreService> clazz = TransactionMetadataStoreService.class;
Field field = clazz.getDeclaredField("tbClient");
field.setAccessible(true);
field.set(metadataStoreService, tbClient);
}
}
use of org.apache.pulsar.broker.TransactionMetadataStoreService in project pulsar by apache.
the class TransactionClientConnectTest method start.
public void start() throws Exception {
// wait transaction coordinator init success
pulsarClient.newTransaction().withTransactionTimeout(30, TimeUnit.SECONDS).build().get();
pulsarClient.newTransaction().withTransactionTimeout(30, TimeUnit.SECONDS).build().get();
TransactionMetadataStoreService transactionMetadataStoreService = getPulsarServiceList().get(0).getTransactionMetadataStoreService();
// remove transaction metadap0-ta store
transactionMetadataStoreService.removeTransactionMetadataStore(TransactionCoordinatorID.get(0)).get();
}
use of org.apache.pulsar.broker.TransactionMetadataStoreService in project pulsar by apache.
the class ServerCnx method handleTcClientConnectRequest.
@Override
protected void handleTcClientConnectRequest(CommandTcClientConnectRequest command) {
final long requestId = command.getRequestId();
final TransactionCoordinatorID tcId = TransactionCoordinatorID.get(command.getTcId());
if (log.isDebugEnabled()) {
log.debug("Receive tc client connect request {} to transaction meta store {} from {}.", requestId, tcId, remoteAddress);
}
if (!checkTransactionEnableAndSendError(requestId)) {
return;
}
TransactionMetadataStoreService transactionMetadataStoreService = service.pulsar().getTransactionMetadataStoreService();
transactionMetadataStoreService.handleTcClientConnect(tcId).thenAccept(connection -> {
if (log.isDebugEnabled()) {
log.debug("Handle tc client connect request {} to transaction meta store {} from {} success.", requestId, tcId, remoteAddress);
}
commandSender.sendTcClientConnectResponse(requestId);
}).exceptionally(e -> {
log.error("Handle tc client connect request {} to transaction meta store {} from {} fail.", requestId, tcId, remoteAddress, e.getCause());
commandSender.sendTcClientConnectResponse(requestId, BrokerServiceException.getClientErrorCode(e), e.getMessage());
return null;
});
}
use of org.apache.pulsar.broker.TransactionMetadataStoreService in project pulsar by apache.
the class TransactionMetadataStoreServiceTest method testAddAndRemoveTransactionMetadataStore.
@Test
public void testAddAndRemoveTransactionMetadataStore() throws Exception {
TransactionMetadataStoreService transactionMetadataStoreService = pulsar.getTransactionMetadataStoreService();
Assert.assertNotNull(transactionMetadataStoreService);
admin.lookups().lookupTopic(TopicName.TRANSACTION_COORDINATOR_ASSIGN.getPartition(0).toString());
transactionMetadataStoreService.handleTcClientConnect(TransactionCoordinatorID.get(0));
Awaitility.await().until(() -> transactionMetadataStoreService.getStores().size() == 1);
transactionMetadataStoreService.removeTransactionMetadataStore(TransactionCoordinatorID.get(0));
Awaitility.await().until(() -> transactionMetadataStoreService.getStores().size() == 0);
}
Aggregations