use of org.neo4j.kernel.lifecycle.Lifespan in project neo4j by neo4j.
the class AbstractKeyValueStoreTest method shouldPickFileWithGreatestTransactionId.
@Test
public void shouldPickFileWithGreatestTransactionId() throws Exception {
try (Lifespan life = new Lifespan()) {
Store store = life.add(createTestStore());
// when
for (long txId = 2; txId <= 10; txId++) {
store.updater(txId).get().close();
store.prepareRotation(txId).rotate();
}
}
// then
try (Lifespan life = new Lifespan()) {
Store store = life.add(createTestStore());
assertEquals(10L, store.headers().get(TX_ID).longValue());
}
}
use of org.neo4j.kernel.lifecycle.Lifespan in project neo4j by neo4j.
the class DumpCountsStore method dumpCountsStore.
public static void dumpCountsStore(FileSystemAbstraction fs, File path, PrintStream out) throws IOException {
try (PageCache pages = createPageCache(fs);
Lifespan life = new Lifespan()) {
if (fs.isDirectory(path)) {
StoreFactory factory = new StoreFactory(path, pages, fs, NullLogProvider.getInstance());
NeoStores neoStores = factory.openAllNeoStores();
SchemaStorage schemaStorage = new SchemaStorage(neoStores.getSchemaStore());
neoStores.getCounts().accept(new DumpCountsStore(out, neoStores, schemaStorage));
} else {
VisitableCountsTracker tracker = new VisitableCountsTracker(NullLogProvider.getInstance(), fs, pages, Config.empty(), path);
if (fs.fileExists(path)) {
tracker.visitFile(path, new DumpCountsStore(out));
} else {
life.add(tracker).accept(new DumpCountsStore(out));
}
}
}
}
use of org.neo4j.kernel.lifecycle.Lifespan in project neo4j by neo4j.
the class TransactionLogRecoveryIT method writePartialTx.
private void writePartialTx(File storeDir) throws IOException {
PhysicalLogFiles logFiles = new PhysicalLogFiles(storeDir, fs);
ReadOnlyLogVersionRepository logVersionRepository = new ReadOnlyLogVersionRepository(pageCache.getPageCache(fs), storeDir);
ReadOnlyTransactionIdStore txIdStore = new ReadOnlyTransactionIdStore(pageCache.getPageCache(fs), storeDir);
PhysicalLogFile logFile = new PhysicalLogFile(fs, logFiles, Long.MAX_VALUE, /*don't rotate*/
txIdStore::getLastCommittedTransactionId, logVersionRepository, new Monitors().newMonitor(PhysicalLogFile.Monitor.class), new LogHeaderCache(10));
try (Lifespan ignored = new Lifespan(logFile)) {
LogEntryWriter writer = new LogEntryWriter(logFile.getWriter());
writer.writeStartEntry(0, 0, 0x123456789ABCDEFL, txIdStore.getLastCommittedTransactionId() + 1, new byte[] { 0 });
}
}
use of org.neo4j.kernel.lifecycle.Lifespan in project neo4j by neo4j.
the class StoreMigrator method rebuildCountsFromScratch.
private void rebuildCountsFromScratch(File storeDir, long lastTxId, PageCache pageCache) {
final File storeFileBase = new File(storeDir, MetaDataStore.DEFAULT_NAME + StoreFactory.COUNTS_STORE);
StoreFactory storeFactory = new StoreFactory(storeDir, pageCache, fileSystem, NullLogProvider.getInstance());
try (NeoStores neoStores = storeFactory.openAllNeoStores()) {
NodeStore nodeStore = neoStores.getNodeStore();
RelationshipStore relationshipStore = neoStores.getRelationshipStore();
try (Lifespan life = new Lifespan()) {
int highLabelId = (int) neoStores.getLabelTokenStore().getHighId();
int highRelationshipTypeId = (int) neoStores.getRelationshipTypeTokenStore().getHighId();
CountsComputer initializer = new CountsComputer(lastTxId, nodeStore, relationshipStore, highLabelId, highRelationshipTypeId);
life.add(new CountsTracker(logService.getInternalLogProvider(), fileSystem, pageCache, config, storeFileBase).setInitializer(initializer));
}
}
}
use of org.neo4j.kernel.lifecycle.Lifespan in project neo4j by neo4j.
the class Runner method call.
@Override
public Long call() throws Exception {
long lastCommittedTransactionId;
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
Lifespan life = new Lifespan()) {
TransactionIdStore transactionIdStore = new DeadSimpleTransactionIdStore();
TransactionMetadataCache transactionMetadataCache = new TransactionMetadataCache(100_000);
LogHeaderCache logHeaderCache = new LogHeaderCache(1000);
LogFile logFile = life.add(createPhysicalLogFile(transactionIdStore, logHeaderCache, fileSystem));
TransactionAppender transactionAppender = life.add(createBatchingTransactionAppender(transactionIdStore, transactionMetadataCache, logFile));
ExecutorService executorService = Executors.newFixedThreadPool(threads);
try {
Future<?>[] handlers = new Future[threads];
for (int i = 0; i < threads; i++) {
TransactionRepresentationFactory factory = new TransactionRepresentationFactory();
Worker task = new Worker(transactionAppender, factory, condition);
handlers[i] = executorService.submit(task);
}
// wait for all the workers to complete
for (Future<?> handle : handlers) {
handle.get();
}
} finally {
executorService.shutdown();
}
lastCommittedTransactionId = transactionIdStore.getLastCommittedTransactionId();
}
return lastCommittedTransactionId;
}
Aggregations