Search in sources :

Example 1 with TransactionCommittingResponseUnpacker

use of org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker in project neo4j by neo4j.

the class BackupService method incrementalWithContext.

/**
     * Performs an incremental backup based off the given context. This means
     * receiving and applying selectively (i.e. irrespective of the actual state
     * of the target db) a set of transactions starting at the desired txId and
     * spanning up to the latest of the master
     *
     * @param targetDb The database that contains a previous full copy
     * @param context The context, containing transaction id to start streaming transaction from
     * @return A backup context, ready to perform
     */
private BackupOutcome incrementalWithContext(String sourceHostNameOrIp, int sourcePort, GraphDatabaseAPI targetDb, long timeout, RequestContext context) throws IncrementalBackupNotPossibleException {
    DependencyResolver resolver = targetDb.getDependencyResolver();
    ProgressTxHandler handler = new ProgressTxHandler();
    TransactionCommittingResponseUnpacker unpacker = new TransactionCommittingResponseUnpacker(resolver, DEFAULT_BATCH_SIZE, 0);
    Monitors monitors = resolver.resolveDependency(Monitors.class);
    LogProvider logProvider = resolver.resolveDependency(LogService.class).getInternalLogProvider();
    BackupClient client = new BackupClient(sourceHostNameOrIp, sourcePort, null, logProvider, targetDb.storeId(), timeout, unpacker, monitors.newMonitor(ByteCounterMonitor.class, BackupClient.class), monitors.newMonitor(RequestMonitor.class, BackupClient.class), new VersionAwareLogEntryReader<>());
    try (Lifespan lifespan = new Lifespan(unpacker, client)) {
        try (Response<Void> response = client.incrementalBackup(context)) {
            unpacker.unpackResponse(response, handler);
        }
    } catch (MismatchingStoreIdException e) {
        throw new RuntimeException(DIFFERENT_STORE, e);
    } catch (RuntimeException | IOException e) {
        if (e.getCause() != null && e.getCause() instanceof MissingLogDataException) {
            throw new IncrementalBackupNotPossibleException(TOO_OLD_BACKUP, e.getCause());
        }
        if (e.getCause() != null && e.getCause() instanceof ConnectException) {
            throw new RuntimeException(e.getMessage(), e.getCause());
        }
        throw new RuntimeException("Failed to perform incremental backup.", e);
    } catch (Throwable throwable) {
        throw new RuntimeException("Unexpected error", throwable);
    }
    return new BackupOutcome(handler.getLastSeenTransactionId(), true);
}
Also used : MismatchingStoreIdException(org.neo4j.kernel.impl.store.MismatchingStoreIdException) IOException(java.io.IOException) TransactionCommittingResponseUnpacker(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker) DependencyResolver(org.neo4j.graphdb.DependencyResolver) NullLogProvider(org.neo4j.logging.NullLogProvider) FormattedLogProvider(org.neo4j.logging.FormattedLogProvider) LogProvider(org.neo4j.logging.LogProvider) ByteCounterMonitor(org.neo4j.kernel.monitoring.ByteCounterMonitor) Monitors(org.neo4j.kernel.monitoring.Monitors) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) LogService(org.neo4j.kernel.impl.logging.LogService) StoreLogService(org.neo4j.kernel.impl.logging.StoreLogService) MissingLogDataException(org.neo4j.kernel.impl.transaction.log.MissingLogDataException) RequestMonitor(org.neo4j.com.monitor.RequestMonitor) ConnectException(java.net.ConnectException)

Example 2 with TransactionCommittingResponseUnpacker

use of org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker in project neo4j by neo4j.

the class MasterClientTest method clientShouldReadAndApplyTransactionLogsOnNewLockSessionRequest.

@Test
public void clientShouldReadAndApplyTransactionLogsOnNewLockSessionRequest() throws Throwable {
    // Given
    MasterImpl master = spy(newMasterImpl(mockMasterImplSpiWith(StoreId.DEFAULT)));
    doReturn(voidResponseWithTransactionLogs()).when(master).newLockSession(any(RequestContext.class));
    newMasterServer(master);
    Dependencies deps = mock(Dependencies.class);
    TransactionCommitProcess commitProcess = mock(TransactionCommitProcess.class);
    when(deps.commitProcess()).thenReturn(commitProcess);
    when(deps.logService()).thenReturn(NullLogService.getInstance());
    when(deps.kernelTransactions()).thenReturn(mock(KernelTransactions.class));
    ResponseUnpacker unpacker = life.add(new TransactionCommittingResponseUnpacker(deps, DEFAULT_BATCH_SIZE, 0));
    MasterClient masterClient = newMasterClient320(StoreId.DEFAULT, unpacker);
    // When
    masterClient.newLockSession(new RequestContext(1, 2, 3, 4, 5));
    // Then
    verify(commitProcess).commit(any(TransactionToApply.class), any(CommitEvent.class), any(TransactionApplicationMode.class));
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) MasterImpl(org.neo4j.kernel.ha.com.master.MasterImpl) MasterClient(org.neo4j.kernel.ha.com.slave.MasterClient) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) KernelTransactions(org.neo4j.kernel.impl.api.KernelTransactions) TransactionApplicationMode(org.neo4j.storageengine.api.TransactionApplicationMode) CommitEvent(org.neo4j.kernel.impl.transaction.tracing.CommitEvent) RequestContext(org.neo4j.com.RequestContext) Dependencies(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker.Dependencies) TransactionCommittingResponseUnpacker(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker) TransactionCommittingResponseUnpacker(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker) ResponseUnpacker(org.neo4j.com.storecopy.ResponseUnpacker) MasterImplTest(org.neo4j.kernel.ha.com.master.MasterImplTest) Test(org.junit.Test)

Aggregations

TransactionCommittingResponseUnpacker (org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker)2 IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 Test (org.junit.Test)1 RequestContext (org.neo4j.com.RequestContext)1 RequestMonitor (org.neo4j.com.monitor.RequestMonitor)1 ResponseUnpacker (org.neo4j.com.storecopy.ResponseUnpacker)1 Dependencies (org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker.Dependencies)1 DependencyResolver (org.neo4j.graphdb.DependencyResolver)1 MasterImpl (org.neo4j.kernel.ha.com.master.MasterImpl)1 MasterImplTest (org.neo4j.kernel.ha.com.master.MasterImplTest)1 MasterClient (org.neo4j.kernel.ha.com.slave.MasterClient)1 KernelTransactions (org.neo4j.kernel.impl.api.KernelTransactions)1 TransactionCommitProcess (org.neo4j.kernel.impl.api.TransactionCommitProcess)1 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)1 LogService (org.neo4j.kernel.impl.logging.LogService)1 StoreLogService (org.neo4j.kernel.impl.logging.StoreLogService)1 MismatchingStoreIdException (org.neo4j.kernel.impl.store.MismatchingStoreIdException)1 MissingLogDataException (org.neo4j.kernel.impl.transaction.log.MissingLogDataException)1 CommitEvent (org.neo4j.kernel.impl.transaction.tracing.CommitEvent)1