Search in sources :

Example 1 with TransactionRecoverTracker

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);
    });
}
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 TransactionRecoverTracker

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);
    });
}
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 3 with TransactionRecoverTracker

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"));
}
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 4 with TransactionRecoverTracker

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"));
}
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 TransactionRecoverTracker

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

Aggregations

TransactionRecoverTracker (org.apache.pulsar.transaction.coordinator.TransactionRecoverTracker)6 TransactionTimeoutTracker (org.apache.pulsar.transaction.coordinator.TransactionTimeoutTracker)6 Field (java.lang.reflect.Field)3 HashMap (java.util.HashMap)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 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)3 TransactionRecoverTrackerImpl (org.apache.pulsar.broker.transaction.recover.TransactionRecoverTrackerImpl)3 ConcurrentOpenHashMap (org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap)3 TransactionCoordinatorID (org.apache.pulsar.transaction.coordinator.TransactionCoordinatorID)3 MLTransactionLogImpl (org.apache.pulsar.transaction.coordinator.impl.MLTransactionLogImpl)3 MLTransactionMetadataStore (org.apache.pulsar.transaction.coordinator.impl.MLTransactionMetadataStore)3 MLTransactionSequenceIdGenerator (org.apache.pulsar.transaction.coordinator.impl.MLTransactionSequenceIdGenerator)3 Test (org.testng.annotations.Test)3