use of org.apache.pulsar.transaction.coordinator.TransactionRecoverTracker in project pulsar by yahoo.
the class TransactionMetadataStoreService method openTransactionMetadataStore.
public CompletableFuture<TransactionMetadataStore> openTransactionMetadataStore(TransactionCoordinatorID tcId) {
return pulsarService.getBrokerService().getManagedLedgerConfig(getMLTransactionLogName(tcId)).thenCompose(v -> {
TransactionTimeoutTracker timeoutTracker = timeoutTrackerFactory.newTracker(tcId);
TransactionRecoverTracker recoverTracker = new TransactionRecoverTrackerImpl(TransactionMetadataStoreService.this, timeoutTracker, tcId.getId());
return transactionMetadataStoreProvider.openStore(tcId, pulsarService.getManagedLedgerFactory(), v, timeoutTracker, recoverTracker);
});
}
use of org.apache.pulsar.transaction.coordinator.TransactionRecoverTracker in project incubator-pulsar by apache.
the class TransactionMetadataStoreService method openTransactionMetadataStore.
public CompletableFuture<TransactionMetadataStore> openTransactionMetadataStore(TransactionCoordinatorID tcId) {
return pulsarService.getBrokerService().getManagedLedgerConfig(getMLTransactionLogName(tcId)).thenCompose(v -> {
TransactionTimeoutTracker timeoutTracker = timeoutTrackerFactory.newTracker(tcId);
TransactionRecoverTracker recoverTracker = new TransactionRecoverTrackerImpl(TransactionMetadataStoreService.this, timeoutTracker, tcId.getId());
return transactionMetadataStoreProvider.openStore(tcId, pulsarService.getManagedLedgerFactory(), v, timeoutTracker, recoverTracker);
});
}
use of org.apache.pulsar.transaction.coordinator.TransactionRecoverTracker in project incubator-pulsar by apache.
the class TransactionTest method testEndTCRecoveringWhenManagerLedgerDisReadable.
@Test
public void testEndTCRecoveringWhenManagerLedgerDisReadable() throws Exception {
String topic = NAMESPACE1 + "/testEndTBRecoveringWhenManagerLedgerDisReadable";
admin.topics().createNonPartitionedTopic(topic);
PersistentTopic persistentTopic = (PersistentTopic) getPulsarServiceList().get(0).getBrokerService().getTopic(topic, false).get().get();
persistentTopic.getManagedLedger().getConfig().setAutoSkipNonRecoverableData(true);
Map<String, String> map = new HashMap<>();
map.put(MLTransactionSequenceIdGenerator.MAX_LOCAL_TXN_ID, "1");
persistentTopic.getManagedLedger().setProperties(map);
ManagedCursor managedCursor = mock(ManagedCursor.class);
doReturn(true).when(managedCursor).hasMoreEntries();
doAnswer(invocation -> {
AsyncCallbacks.ReadEntriesCallback callback = invocation.getArgument(1);
callback.readEntriesFailed(new ManagedLedgerException.NonRecoverableLedgerException("No ledger exist"), null);
return null;
}).when(managedCursor).asyncReadEntries(anyInt(), any(), any(), any());
MLTransactionSequenceIdGenerator mlTransactionSequenceIdGenerator = new MLTransactionSequenceIdGenerator();
persistentTopic.getManagedLedger().getConfig().setManagedLedgerInterceptor(mlTransactionSequenceIdGenerator);
MLTransactionLogImpl mlTransactionLog = new MLTransactionLogImpl(new TransactionCoordinatorID(1), null, persistentTopic.getManagedLedger().getConfig());
Class<MLTransactionLogImpl> mlTransactionLogClass = MLTransactionLogImpl.class;
Field field = mlTransactionLogClass.getDeclaredField("cursor");
field.setAccessible(true);
field.set(mlTransactionLog, managedCursor);
field = mlTransactionLogClass.getDeclaredField("managedLedger");
field.setAccessible(true);
field.set(mlTransactionLog, persistentTopic.getManagedLedger());
TransactionRecoverTracker transactionRecoverTracker = mock(TransactionRecoverTracker.class);
doNothing().when(transactionRecoverTracker).appendOpenTransactionToTimeoutTracker();
doNothing().when(transactionRecoverTracker).handleCommittingAndAbortingTransaction();
TransactionTimeoutTracker timeoutTracker = mock(TransactionTimeoutTracker.class);
doNothing().when(timeoutTracker).start();
MLTransactionMetadataStore metadataStore1 = new MLTransactionMetadataStore(new TransactionCoordinatorID(1), mlTransactionLog, timeoutTracker, transactionRecoverTracker, mlTransactionSequenceIdGenerator);
Awaitility.await().untilAsserted(() -> assertEquals(metadataStore1.getCoordinatorStats().state, "Ready"));
doAnswer(invocation -> {
AsyncCallbacks.ReadEntriesCallback callback = invocation.getArgument(1);
callback.readEntriesFailed(new ManagedLedgerException.ManagedLedgerFencedException(), null);
return null;
}).when(managedCursor).asyncReadEntries(anyInt(), any(), any(), any());
MLTransactionMetadataStore metadataStore2 = new MLTransactionMetadataStore(new TransactionCoordinatorID(1), mlTransactionLog, timeoutTracker, transactionRecoverTracker, mlTransactionSequenceIdGenerator);
Awaitility.await().untilAsserted(() -> assertEquals(metadataStore2.getCoordinatorStats().state, "Ready"));
doAnswer(invocation -> {
AsyncCallbacks.ReadEntriesCallback callback = invocation.getArgument(1);
callback.readEntriesFailed(new ManagedLedgerException.CursorAlreadyClosedException("test"), null);
return null;
}).when(managedCursor).asyncReadEntries(anyInt(), any(), any(), any());
MLTransactionMetadataStore metadataStore3 = new MLTransactionMetadataStore(new TransactionCoordinatorID(1), mlTransactionLog, timeoutTracker, transactionRecoverTracker, mlTransactionSequenceIdGenerator);
Awaitility.await().untilAsserted(() -> assertEquals(metadataStore3.getCoordinatorStats().state, "Ready"));
}
use of org.apache.pulsar.transaction.coordinator.TransactionRecoverTracker in project pulsar by yahoo.
the class TransactionTest method testEndTCRecoveringWhenManagerLedgerDisReadable.
@Test
public void testEndTCRecoveringWhenManagerLedgerDisReadable() throws Exception {
String topic = NAMESPACE1 + "/testEndTBRecoveringWhenManagerLedgerDisReadable";
admin.topics().createNonPartitionedTopic(topic);
PersistentTopic persistentTopic = (PersistentTopic) getPulsarServiceList().get(0).getBrokerService().getTopic(topic, false).get().get();
persistentTopic.getManagedLedger().getConfig().setAutoSkipNonRecoverableData(true);
Map<String, String> map = new HashMap<>();
map.put(MLTransactionSequenceIdGenerator.MAX_LOCAL_TXN_ID, "1");
persistentTopic.getManagedLedger().setProperties(map);
ManagedCursor managedCursor = mock(ManagedCursor.class);
doReturn(true).when(managedCursor).hasMoreEntries();
doAnswer(invocation -> {
AsyncCallbacks.ReadEntriesCallback callback = invocation.getArgument(1);
callback.readEntriesFailed(new ManagedLedgerException.NonRecoverableLedgerException("No ledger exist"), null);
return null;
}).when(managedCursor).asyncReadEntries(anyInt(), any(), any(), any());
MLTransactionSequenceIdGenerator mlTransactionSequenceIdGenerator = new MLTransactionSequenceIdGenerator();
persistentTopic.getManagedLedger().getConfig().setManagedLedgerInterceptor(mlTransactionSequenceIdGenerator);
MLTransactionLogImpl mlTransactionLog = new MLTransactionLogImpl(new TransactionCoordinatorID(1), null, persistentTopic.getManagedLedger().getConfig());
Class<MLTransactionLogImpl> mlTransactionLogClass = MLTransactionLogImpl.class;
Field field = mlTransactionLogClass.getDeclaredField("cursor");
field.setAccessible(true);
field.set(mlTransactionLog, managedCursor);
field = mlTransactionLogClass.getDeclaredField("managedLedger");
field.setAccessible(true);
field.set(mlTransactionLog, persistentTopic.getManagedLedger());
TransactionRecoverTracker transactionRecoverTracker = mock(TransactionRecoverTracker.class);
doNothing().when(transactionRecoverTracker).appendOpenTransactionToTimeoutTracker();
doNothing().when(transactionRecoverTracker).handleCommittingAndAbortingTransaction();
TransactionTimeoutTracker timeoutTracker = mock(TransactionTimeoutTracker.class);
doNothing().when(timeoutTracker).start();
MLTransactionMetadataStore metadataStore1 = new MLTransactionMetadataStore(new TransactionCoordinatorID(1), mlTransactionLog, timeoutTracker, transactionRecoverTracker, mlTransactionSequenceIdGenerator);
Awaitility.await().untilAsserted(() -> assertEquals(metadataStore1.getCoordinatorStats().state, "Ready"));
doAnswer(invocation -> {
AsyncCallbacks.ReadEntriesCallback callback = invocation.getArgument(1);
callback.readEntriesFailed(new ManagedLedgerException.ManagedLedgerFencedException(), null);
return null;
}).when(managedCursor).asyncReadEntries(anyInt(), any(), any(), any());
MLTransactionMetadataStore metadataStore2 = new MLTransactionMetadataStore(new TransactionCoordinatorID(1), mlTransactionLog, timeoutTracker, transactionRecoverTracker, mlTransactionSequenceIdGenerator);
Awaitility.await().untilAsserted(() -> assertEquals(metadataStore2.getCoordinatorStats().state, "Ready"));
doAnswer(invocation -> {
AsyncCallbacks.ReadEntriesCallback callback = invocation.getArgument(1);
callback.readEntriesFailed(new ManagedLedgerException.CursorAlreadyClosedException("test"), null);
return null;
}).when(managedCursor).asyncReadEntries(anyInt(), any(), any(), any());
MLTransactionMetadataStore metadataStore3 = new MLTransactionMetadataStore(new TransactionCoordinatorID(1), mlTransactionLog, timeoutTracker, transactionRecoverTracker, mlTransactionSequenceIdGenerator);
Awaitility.await().untilAsserted(() -> assertEquals(metadataStore3.getCoordinatorStats().state, "Ready"));
}
use of org.apache.pulsar.transaction.coordinator.TransactionRecoverTracker in project pulsar by apache.
the class TransactionMetadataStoreService method openTransactionMetadataStore.
public CompletableFuture<TransactionMetadataStore> openTransactionMetadataStore(TransactionCoordinatorID tcId) {
return pulsarService.getBrokerService().getManagedLedgerConfig(getMLTransactionLogName(tcId)).thenCompose(v -> {
TransactionTimeoutTracker timeoutTracker = timeoutTrackerFactory.newTracker(tcId);
TransactionRecoverTracker recoverTracker = new TransactionRecoverTrackerImpl(TransactionMetadataStoreService.this, timeoutTracker, tcId.getId());
return transactionMetadataStoreProvider.openStore(tcId, pulsarService.getManagedLedgerFactory(), v, timeoutTracker, recoverTracker);
});
}
Aggregations