Search in sources :

Example 1 with MissingLogDataException

use of org.neo4j.kernel.impl.transaction.log.MissingLogDataException in project neo4j by neo4j.

the class SwitchToSlave method checkDataConsistencyWithMaster.

void checkDataConsistencyWithMaster(URI availableMasterId, Master master, StoreId storeId, TransactionIdStore transactionIdStore) {
    TransactionId myLastCommittedTxData = transactionIdStore.getLastCommittedTransaction();
    long myLastCommittedTx = myLastCommittedTxData.transactionId();
    HandshakeResult handshake;
    try (Response<HandshakeResult> response = master.handshake(myLastCommittedTx, storeId)) {
        handshake = response.response();
        requestContextFactory.setEpoch(handshake.epoch());
    } catch (BranchedDataException e) {
        // Rethrow wrapped in a branched data exception on our side, to clarify where the problem originates.
        throw new BranchedDataException("The database stored on this machine has diverged from that " + "of the master. This will be automatically resolved.", e);
    } catch (RuntimeException e) {
        // server-side exception
        if (e.getCause() instanceof MissingLogDataException) {
            /*
                 * This means the master was unable to find a log entry for the txid we just asked. This
                 * probably means the thing we asked for is too old or too new. Anyway, since it doesn't
                 * have the tx it is better if we just throw our store away and ask for a new copy. Next
                 * time around it shouldn't have to even pass from here.
                 */
            throw new StoreOutOfDateException("The master is missing the log required to complete the " + "consistency check", e.getCause());
        }
        throw e;
    }
    long myChecksum = myLastCommittedTxData.checksum();
    if (myChecksum != handshake.txChecksum()) {
        String msg = "The cluster contains two logically different versions of the database.. This will be " + "automatically resolved. Details: I (server_id:" + config.get(ClusterSettings.server_id) + ") think checksum for txId (" + myLastCommittedTx + ") is " + myChecksum + ", but master (server_id:" + getServerId(availableMasterId) + ") says that it's " + handshake.txChecksum() + ", where handshake is " + handshake;
        throw new BranchedDataException(msg);
    }
    msgLog.info("Checksum for last committed tx ok with lastTxId=" + myLastCommittedTx + " with checksum=" + myChecksum, true);
}
Also used : HandshakeResult(org.neo4j.kernel.ha.com.master.HandshakeResult) StoreOutOfDateException(org.neo4j.kernel.ha.StoreOutOfDateException) BranchedDataException(org.neo4j.kernel.ha.BranchedDataException) MissingLogDataException(org.neo4j.kernel.impl.transaction.log.MissingLogDataException) TransactionId(org.neo4j.kernel.impl.store.TransactionId)

Example 2 with MissingLogDataException

use of org.neo4j.kernel.impl.transaction.log.MissingLogDataException 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)

Aggregations

MissingLogDataException (org.neo4j.kernel.impl.transaction.log.MissingLogDataException)2 IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 RequestMonitor (org.neo4j.com.monitor.RequestMonitor)1 TransactionCommittingResponseUnpacker (org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker)1 DependencyResolver (org.neo4j.graphdb.DependencyResolver)1 BranchedDataException (org.neo4j.kernel.ha.BranchedDataException)1 StoreOutOfDateException (org.neo4j.kernel.ha.StoreOutOfDateException)1 HandshakeResult (org.neo4j.kernel.ha.com.master.HandshakeResult)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 TransactionId (org.neo4j.kernel.impl.store.TransactionId)1 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)1 ByteCounterMonitor (org.neo4j.kernel.monitoring.ByteCounterMonitor)1 Monitors (org.neo4j.kernel.monitoring.Monitors)1 FormattedLogProvider (org.neo4j.logging.FormattedLogProvider)1 LogProvider (org.neo4j.logging.LogProvider)1 NullLogProvider (org.neo4j.logging.NullLogProvider)1