use of org.neo4j.kernel.monitoring.Monitors 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);
}
use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class RemoteStore method getPullIndex.
/**
* Later stages of the startup process require at least one transaction to
* figure out the mapping between the transaction log and the consensus log.
*
* If there are no transaction logs then we can pull from and including
* the index which the metadata store points to. This would be the case
* for example with a backup taken during an idle period of the system.
*
* However, if there are transaction logs then we want to find out where
* they end and pull from there, excluding the last one so that we do not
* get duplicate entries.
*/
private long getPullIndex(File storeDir) throws IOException {
/* this is the metadata store */
ReadOnlyTransactionIdStore txIdStore = new ReadOnlyTransactionIdStore(pageCache, storeDir);
/* Clean as in clean shutdown. Without transaction logs this should be the truth,
* but otherwise it can be used as a starting point for scanning the logs. */
long lastCleanTxId = txIdStore.getLastCommittedTransactionId();
/* these are the transaction logs */
ReadOnlyTransactionStore txStore = new ReadOnlyTransactionStore(pageCache, fs, storeDir, new Monitors());
long lastTxId = BASE_TX_ID;
try (Lifespan ignored = new Lifespan(txStore)) {
TransactionCursor cursor;
try {
cursor = txStore.getTransactions(lastCleanTxId);
} catch (NoSuchTransactionException e) {
log.info("No transaction logs found. Will use metadata store as base for pull request.");
return lastCleanTxId;
}
while (cursor.next()) {
CommittedTransactionRepresentation tx = cursor.get();
lastTxId = tx.getCommitEntry().getTxId();
}
if (lastTxId < lastCleanTxId) {
throw new IllegalStateException("Metadata index was higher than transaction log index.");
}
// we don't want to pull a transaction we already have in the log, hence +1
return lastTxId + 1;
}
}
use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class Prover method bootstrapCluster.
private void bootstrapCluster() throws Exception {
String instance1 = "cluster://localhost:5001";
String instance2 = "cluster://localhost:5002";
String instance3 = "cluster://localhost:5003";
ClusterConfiguration config = new ClusterConfiguration("default", NullLogProvider.getInstance(), instance1, instance2, instance3);
ClusterState state = new ClusterState(asList(newClusterInstance(new InstanceId(1), new URI(instance1), new Monitors(), config, 10, NullLogProvider.getInstance()), newClusterInstance(new InstanceId(2), new URI(instance2), new Monitors(), config, 10, NullLogProvider.getInstance()), newClusterInstance(new InstanceId(3), new URI(instance3), new Monitors(), config, 10, NullLogProvider.getInstance())), emptySetOf(ClusterAction.class));
state = state.performAction(new MessageDeliveryAction(Message.to(ClusterMessage.create, new URI(instance3), "defaultcluster").setHeader(Message.CONVERSATION_ID, "-1").setHeader(Message.FROM, instance3)));
state = state.performAction(new MessageDeliveryAction(Message.to(ClusterMessage.join, new URI(instance2), new Object[] { "defaultcluster", new URI[] { new URI(instance3) } }).setHeader(Message.CONVERSATION_ID, "-1").setHeader(Message.FROM, instance2)));
state = state.performAction(new MessageDeliveryAction(Message.to(ClusterMessage.join, new URI(instance1), new Object[] { "defaultcluster", new URI[] { new URI(instance3) } }).setHeader(Message.CONVERSATION_ID, "-1").setHeader(Message.FROM, instance1)));
state.addPendingActions(new InstanceCrashedAction(instance3));
unexploredKnownStates.add(state);
db.newState(state);
}
use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class TestProver method aClusterSnapshotShouldEqualItsOrigin.
@Test
public void aClusterSnapshotShouldEqualItsOrigin() throws Exception {
// Given
ClusterConfiguration config = new ClusterConfiguration("default", NullLogProvider.getInstance(), "cluster://localhost:5001", "cluster://localhost:5002", "cluster://localhost:5003");
ClusterState state = new ClusterState(asList(newClusterInstance(new InstanceId(1), new URI("cluster://localhost:5001"), new Monitors(), config, 10, NullLogProvider.getInstance()), newClusterInstance(new InstanceId(2), new URI("cluster://localhost:5002"), new Monitors(), config, 10, NullLogProvider.getInstance()), newClusterInstance(new InstanceId(3), new URI("cluster://localhost:5003"), new Monitors(), config, 10, NullLogProvider.getInstance())), emptySetOf(ClusterAction.class));
// When
ClusterState snapshot = state.snapshot();
// Then
assertEquals(state, snapshot);
assertEquals(state.hashCode(), snapshot.hashCode());
}
use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class TestProver method twoStatesWithSameSetupAndPendingMessagesShouldBeEqual.
@Test
public void twoStatesWithSameSetupAndPendingMessagesShouldBeEqual() throws Exception {
// Given
ClusterConfiguration config = new ClusterConfiguration("default", NullLogProvider.getInstance(), "cluster://localhost:5001", "cluster://localhost:5002", "cluster://localhost:5003");
ClusterState state = new ClusterState(asList(newClusterInstance(new InstanceId(1), new URI("cluster://localhost:5001"), new Monitors(), config, 10, NullLogProvider.getInstance()), newClusterInstance(new InstanceId(2), new URI("cluster://localhost:5002"), new Monitors(), config, 10, NullLogProvider.getInstance()), newClusterInstance(new InstanceId(3), new URI("cluster://localhost:5003"), new Monitors(), config, 10, NullLogProvider.getInstance())), emptySetOf(ClusterAction.class));
// When
ClusterState firstState = state.performAction(new MessageDeliveryAction(Message.to(ClusterMessage.join, new URI("cluster://localhost:5002"), new Object[] { "defaultcluster", new URI[] { new URI("cluster://localhost:5003") } }).setHeader(Message.CONVERSATION_ID, "-1").setHeader(Message.FROM, "cluster://localhost:5002")));
ClusterState secondState = state.performAction(new MessageDeliveryAction(Message.to(ClusterMessage.join, new URI("cluster://localhost:5002"), new Object[] { "defaultcluster", new URI[] { new URI("cluster://localhost:5003") } }).setHeader(Message.CONVERSATION_ID, "-1").setHeader(Message.FROM, "cluster://localhost:5002")));
// Then
assertEquals(firstState, secondState);
assertEquals(firstState.hashCode(), secondState.hashCode());
}
Aggregations