use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.
the class StoreMigration method run.
public void run(final FileSystemAbstraction fs, final File storeDirectory, Config config, LogProvider userLogProvider) throws IOException {
StoreLogService logService = StoreLogService.withUserLogProvider(userLogProvider).inLogsDirectory(fs, storeDirectory);
VisibleMigrationProgressMonitor progressMonitor = new VisibleMigrationProgressMonitor(logService.getUserLog(StoreMigration.class));
LifeSupport life = new LifeSupport();
life.add(logService);
// Add participants from kernel extensions...
LegacyIndexProvider legacyIndexProvider = new LegacyIndexProvider();
Log log = userLogProvider.getLog(StoreMigration.class);
try (PageCache pageCache = createPageCache(fs, config)) {
Dependencies deps = new Dependencies();
deps.satisfyDependencies(fs, config, legacyIndexProvider, pageCache, logService);
KernelContext kernelContext = new SimpleKernelContext(storeDirectory, DatabaseInfo.UNKNOWN, deps);
KernelExtensions kernelExtensions = life.add(new KernelExtensions(kernelContext, GraphDatabaseDependencies.newDependencies().kernelExtensions(), deps, ignore()));
// Add the kernel store migrator
life.start();
SchemaIndexProvider schemaIndexProvider = kernelExtensions.resolveDependency(SchemaIndexProvider.class, HighestSelectionStrategy.getInstance());
LabelScanStoreProvider labelScanStoreProvider = kernelExtensions.resolveDependency(LabelScanStoreProvider.class, new NamedLabelScanStoreSelectionStrategy(config));
long startTime = System.currentTimeMillis();
DatabaseMigrator migrator = new DatabaseMigrator(progressMonitor, fs, config, logService, schemaIndexProvider, labelScanStoreProvider, legacyIndexProvider.getIndexProviders(), pageCache, RecordFormatSelector.selectForConfig(config, userLogProvider));
migrator.migrate(storeDirectory);
long duration = System.currentTimeMillis() - startTime;
log.info(format("Migration completed in %d s%n", duration / 1000));
} catch (Exception e) {
throw new StoreUpgrader.UnableToUpgradeException("Failure during upgrade", e);
} finally {
life.shutdown();
}
}
use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.
the class ApplyTransactionsCommand method applyTransactions.
private long applyTransactions(File fromPath, GraphDatabaseAPI toDb, long fromTxExclusive, long toTxInclusive, PrintStream out) throws IOException, TransactionFailureException {
DependencyResolver resolver = toDb.getDependencyResolver();
TransactionRepresentationCommitProcess commitProcess = new TransactionRepresentationCommitProcess(resolver.resolveDependency(TransactionAppender.class), resolver.resolveDependency(StorageEngine.class));
LifeSupport life = new LifeSupport();
try (DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
PageCache pageCache = StandalonePageCacheFactory.createPageCache(fileSystem)) {
LogicalTransactionStore source = life.add(new ReadOnlyTransactionStore(pageCache, fileSystem, fromPath, new Monitors()));
life.start();
long lastAppliedTx = fromTxExclusive;
// Some progress if there are more than a couple of transactions to apply
ProgressListener progress = toTxInclusive - fromTxExclusive >= 100 ? textual(out).singlePart("Application progress", toTxInclusive - fromTxExclusive) : ProgressListener.NONE;
try (IOCursor<CommittedTransactionRepresentation> cursor = source.getTransactions(fromTxExclusive + 1)) {
while (cursor.next()) {
CommittedTransactionRepresentation transaction = cursor.get();
TransactionRepresentation transactionRepresentation = transaction.getTransactionRepresentation();
try {
commitProcess.commit(new TransactionToApply(transactionRepresentation), NULL, EXTERNAL);
progress.add(1);
} catch (final Throwable e) {
System.err.println("ERROR applying transaction " + transaction.getCommitEntry().getTxId());
throw e;
}
lastAppliedTx = transaction.getCommitEntry().getTxId();
if (lastAppliedTx == toTxInclusive) {
break;
}
}
}
return lastAppliedTx;
} finally {
life.shutdown();
}
}
use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.
the class DatabaseRebuildTool method run.
public void run(String... arguments) throws Exception {
if (arguments.length == 0) {
System.err.println("Tool for rebuilding database from transaction logs onto a new store");
System.err.println("Example: dbrebuild --from path/to/some.db --to path/to/new.db apply next");
System.err.println(" dbrebuild --from path/to/some.db --to path/to/new.db -i");
System.err.println(" --from : which db to use as source for reading transactions");
System.err.println(" --to : where to build the new db");
System.err.println(" --overwrite-to : always starts from empty 'to' db");
System.err.println(" -i : interactive mode (enter a shell)");
return;
}
Args args = Args.withFlags("i", "overwrite-to").parse(arguments);
File fromPath = getFrom(args);
File toPath = getTo(args);
GraphDatabaseBuilder dbBuilder = newDbBuilder(toPath, args);
boolean interactive = args.getBoolean("i");
if (interactive && !args.orphans().isEmpty()) {
throw new IllegalArgumentException("No additional commands allowed in interactive mode");
}
@SuppressWarnings("resource") InputStream input = interactive ? in : oneCommand(args.orphansAsArray());
LifeSupport life = new LifeSupport();
ConsoleInput consoleInput = console(fromPath, dbBuilder, input, interactive ? staticPrompt("# ") : NO_PROMPT, life);
life.start();
try {
consoleInput.waitFor();
} finally {
life.shutdown();
}
}
use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.
the class ClusterTopologyChangesIT method failedInstanceShouldReceiveCorrectCoordinatorIdUponRejoiningCluster.
@Test
public void failedInstanceShouldReceiveCorrectCoordinatorIdUponRejoiningCluster() throws Throwable {
// Given
HighlyAvailableGraphDatabase initialMaster = cluster.getMaster();
// When
cluster.shutdown(initialMaster);
cluster.await(masterAvailable(initialMaster));
cluster.await(masterSeesSlavesAsAvailable(1));
// create node on new master to ensure that it has the greatest tx id
createNodeOn(cluster.getMaster());
cluster.sync();
LifeSupport life = new LifeSupport();
ClusterClientModule clusterClient = newClusterClient(life, new InstanceId(1));
cleanup.add(life);
final AtomicReference<InstanceId> coordinatorIdWhenReJoined = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
clusterClient.clusterClient.addClusterListener(new ClusterListener.Adapter() {
@Override
public void enteredCluster(ClusterConfiguration clusterConfiguration) {
coordinatorIdWhenReJoined.set(clusterConfiguration.getElected(COORDINATOR));
latch.countDown();
}
});
life.start();
// Then
assertTrue(latch.await(20, SECONDS));
assertEquals(new InstanceId(2), coordinatorIdWhenReJoined.get());
}
use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.
the class BackupProtocolTest method shouldGatherForensicsInFullBackupRequest.
private void shouldGatherForensicsInFullBackupRequest(boolean forensics) throws Exception {
// GIVEN
Response<Void> response = Response.EMPTY;
StoreId storeId = response.getStoreId();
String host = "localhost";
int port = BackupServer.DEFAULT_PORT;
LifeSupport life = new LifeSupport();
LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>();
BackupClient client = life.add(new BackupClient(host, port, null, NullLogProvider.getInstance(), storeId, 10_000, mock(ResponseUnpacker.class), mock(ByteCounterMonitor.class), mock(RequestMonitor.class), reader));
ControlledBackupInterface backup = new ControlledBackupInterface();
life.add(new BackupServer(backup, new HostnamePort(host, port), NullLogProvider.getInstance(), mock(ByteCounterMonitor.class), mock(RequestMonitor.class)));
life.start();
try {
// WHEN
StoreWriter writer = mock(StoreWriter.class);
client.fullBackup(writer, forensics);
// THEN
assertEquals(forensics, backup.receivedForensics);
} finally {
life.shutdown();
}
}
Aggregations