Search in sources :

Example 1 with TransactionTimeoutTracker

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);
    });
}
Also used : TransactionRecoverTrackerImpl(org.apache.pulsar.broker.transaction.recover.TransactionRecoverTrackerImpl) TransactionRecoverTracker(org.apache.pulsar.transaction.coordinator.TransactionRecoverTracker) TransactionTimeoutTracker(org.apache.pulsar.transaction.coordinator.TransactionTimeoutTracker)

Example 2 with TransactionTimeoutTracker

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);
}
Also used : TransactionTimeoutTrackerImpl(org.apache.pulsar.broker.transaction.timeout.TransactionTimeoutTrackerImpl) Field(java.lang.reflect.Field) TransactionTimeoutTrackerFactoryImpl(org.apache.pulsar.broker.transaction.timeout.TransactionTimeoutTrackerFactoryImpl) HashedWheelTimer(io.netty.util.HashedWheelTimer) TripleLongPriorityQueue(org.apache.pulsar.common.util.collections.TripleLongPriorityQueue) TransactionTimeoutTracker(org.apache.pulsar.transaction.coordinator.TransactionTimeoutTracker) Map(java.util.Map) TransactionMetadataStoreService(org.apache.pulsar.broker.TransactionMetadataStoreService) Test(org.testng.annotations.Test)

Example 3 with TransactionTimeoutTracker

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);
    });
}
Also used : TransactionRecoverTrackerImpl(org.apache.pulsar.broker.transaction.recover.TransactionRecoverTrackerImpl) TransactionRecoverTracker(org.apache.pulsar.transaction.coordinator.TransactionRecoverTracker) TransactionTimeoutTracker(org.apache.pulsar.transaction.coordinator.TransactionTimeoutTracker)

Example 4 with TransactionTimeoutTracker

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"));
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentOpenHashMap(org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap) HashMap(java.util.HashMap) TransactionRecoverTracker(org.apache.pulsar.transaction.coordinator.TransactionRecoverTracker) MLTransactionSequenceIdGenerator(org.apache.pulsar.transaction.coordinator.impl.MLTransactionSequenceIdGenerator) MLTransactionMetadataStore(org.apache.pulsar.transaction.coordinator.impl.MLTransactionMetadataStore) MLTransactionLogImpl(org.apache.pulsar.transaction.coordinator.impl.MLTransactionLogImpl) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Field(java.lang.reflect.Field) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) AsyncCallbacks(org.apache.bookkeeper.mledger.AsyncCallbacks) TransactionCoordinatorID(org.apache.pulsar.transaction.coordinator.TransactionCoordinatorID) TransactionTimeoutTracker(org.apache.pulsar.transaction.coordinator.TransactionTimeoutTracker) Test(org.testng.annotations.Test)

Example 5 with TransactionTimeoutTracker

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);
}
Also used : TransactionTimeoutTrackerImpl(org.apache.pulsar.broker.transaction.timeout.TransactionTimeoutTrackerImpl) Field(java.lang.reflect.Field) TransactionTimeoutTrackerFactoryImpl(org.apache.pulsar.broker.transaction.timeout.TransactionTimeoutTrackerFactoryImpl) HashedWheelTimer(io.netty.util.HashedWheelTimer) TripleLongPriorityQueue(org.apache.pulsar.common.util.collections.TripleLongPriorityQueue) TransactionTimeoutTracker(org.apache.pulsar.transaction.coordinator.TransactionTimeoutTracker) Map(java.util.Map) TransactionMetadataStoreService(org.apache.pulsar.broker.TransactionMetadataStoreService) Test(org.testng.annotations.Test)

Aggregations

TransactionTimeoutTracker (org.apache.pulsar.transaction.coordinator.TransactionTimeoutTracker)9 Field (java.lang.reflect.Field)6 TransactionRecoverTracker (org.apache.pulsar.transaction.coordinator.TransactionRecoverTracker)6 Test (org.testng.annotations.Test)6 HashedWheelTimer (io.netty.util.HashedWheelTimer)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 AsyncCallbacks (org.apache.bookkeeper.mledger.AsyncCallbacks)3 ManagedCursor (org.apache.bookkeeper.mledger.ManagedCursor)3 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)3 TransactionMetadataStoreService (org.apache.pulsar.broker.TransactionMetadataStoreService)3 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)3 TransactionRecoverTrackerImpl (org.apache.pulsar.broker.transaction.recover.TransactionRecoverTrackerImpl)3 TransactionTimeoutTrackerFactoryImpl (org.apache.pulsar.broker.transaction.timeout.TransactionTimeoutTrackerFactoryImpl)3 TransactionTimeoutTrackerImpl (org.apache.pulsar.broker.transaction.timeout.TransactionTimeoutTrackerImpl)3 ConcurrentOpenHashMap (org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap)3 TripleLongPriorityQueue (org.apache.pulsar.common.util.collections.TripleLongPriorityQueue)3 TransactionCoordinatorID (org.apache.pulsar.transaction.coordinator.TransactionCoordinatorID)3 MLTransactionLogImpl (org.apache.pulsar.transaction.coordinator.impl.MLTransactionLogImpl)3