use of org.apache.pulsar.transaction.coordinator.TransactionTimeoutTracker 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.TransactionTimeoutTracker in project pulsar by yahoo.
the class TransactionRecoverTrackerTest method openStatusRecoverTrackerTest.
@Test
public void openStatusRecoverTrackerTest() throws Exception {
TransactionMetadataStoreService transactionMetadataStoreService = mock(TransactionMetadataStoreService.class);
TransactionTimeoutTracker timeoutTracker = new TransactionTimeoutTrackerFactoryImpl(transactionMetadataStoreService, new HashedWheelTimer()).newTracker(TransactionCoordinatorID.get(1));
TransactionRecoverTrackerImpl recoverTracker = new TransactionRecoverTrackerImpl(transactionMetadataStoreService, timeoutTracker, 1);
recoverTracker.handleOpenStatusTransaction(1, 200);
recoverTracker.handleOpenStatusTransaction(2, 300);
Field field = TransactionRecoverTrackerImpl.class.getDeclaredField("openTransactions");
field.setAccessible(true);
Map<Long, Long> map = (Map<Long, Long>) field.get(recoverTracker);
assertEquals(map.size(), 2);
assertEquals(map.get(1L).longValue(), 200L);
assertEquals(map.get(2L).longValue(), 300L);
field = TransactionTimeoutTrackerImpl.class.getDeclaredField("priorityQueue");
field.setAccessible(true);
TripleLongPriorityQueue priorityQueue = (TripleLongPriorityQueue) field.get(timeoutTracker);
assertEquals(priorityQueue.size(), 0);
recoverTracker.appendOpenTransactionToTimeoutTracker();
assertEquals(priorityQueue.size(), 2);
}
use of org.apache.pulsar.transaction.coordinator.TransactionTimeoutTracker 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.TransactionTimeoutTracker 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.TransactionTimeoutTracker in project incubator-pulsar by apache.
the class TransactionRecoverTrackerTest method openStatusRecoverTrackerTest.
@Test
public void openStatusRecoverTrackerTest() throws Exception {
TransactionMetadataStoreService transactionMetadataStoreService = mock(TransactionMetadataStoreService.class);
TransactionTimeoutTracker timeoutTracker = new TransactionTimeoutTrackerFactoryImpl(transactionMetadataStoreService, new HashedWheelTimer()).newTracker(TransactionCoordinatorID.get(1));
TransactionRecoverTrackerImpl recoverTracker = new TransactionRecoverTrackerImpl(transactionMetadataStoreService, timeoutTracker, 1);
recoverTracker.handleOpenStatusTransaction(1, 200);
recoverTracker.handleOpenStatusTransaction(2, 300);
Field field = TransactionRecoverTrackerImpl.class.getDeclaredField("openTransactions");
field.setAccessible(true);
Map<Long, Long> map = (Map<Long, Long>) field.get(recoverTracker);
assertEquals(map.size(), 2);
assertEquals(map.get(1L).longValue(), 200L);
assertEquals(map.get(2L).longValue(), 300L);
field = TransactionTimeoutTrackerImpl.class.getDeclaredField("priorityQueue");
field.setAccessible(true);
TripleLongPriorityQueue priorityQueue = (TripleLongPriorityQueue) field.get(timeoutTracker);
assertEquals(priorityQueue.size(), 0);
recoverTracker.appendOpenTransactionToTimeoutTracker();
assertEquals(priorityQueue.size(), 2);
}
Aggregations