Search in sources :

Example 11 with Lifespan

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());
    }
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) Test(org.junit.Test)

Example 12 with Lifespan

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));
            }
        }
    }
}
Also used : SchemaStorage(org.neo4j.kernel.impl.store.SchemaStorage) NeoStores(org.neo4j.kernel.impl.store.NeoStores) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) StandalonePageCacheFactory.createPageCache(org.neo4j.io.pagecache.impl.muninn.StandalonePageCacheFactory.createPageCache) PageCache(org.neo4j.io.pagecache.PageCache)

Example 13 with Lifespan

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 });
    }
}
Also used : ReadOnlyTransactionIdStore(org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionIdStore) Monitors(org.neo4j.kernel.monitoring.Monitors) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) ReadOnlyLogVersionRepository(org.neo4j.kernel.impl.transaction.log.ReadOnlyLogVersionRepository) LogHeaderCache(org.neo4j.kernel.impl.transaction.log.LogHeaderCache) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)

Example 14 with Lifespan

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));
        }
    }
}
Also used : NodeStore(org.neo4j.kernel.impl.store.NodeStore) CountsComputer(org.neo4j.kernel.impl.store.CountsComputer) NeoStores(org.neo4j.kernel.impl.store.NeoStores) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) PagedFile(org.neo4j.io.pagecache.PagedFile) StoreFile(org.neo4j.kernel.impl.storemigration.StoreFile) File(java.io.File) Lifespan(org.neo4j.kernel.lifecycle.Lifespan)

Example 15 with Lifespan

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;
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) TransactionAppender(org.neo4j.kernel.impl.transaction.log.TransactionAppender) BatchingTransactionAppender(org.neo4j.kernel.impl.transaction.log.BatchingTransactionAppender) DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) TransactionMetadataCache(org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache) LogFile(org.neo4j.kernel.impl.transaction.log.LogFile) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) LogHeaderCache(org.neo4j.kernel.impl.transaction.log.LogHeaderCache)

Aggregations

Lifespan (org.neo4j.kernel.lifecycle.Lifespan)32 Test (org.junit.Test)22 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)8 Transaction (org.neo4j.graphdb.Transaction)6 File (java.io.File)5 Node (org.neo4j.graphdb.Node)4 DurableStateStorage (org.neo4j.causalclustering.core.state.storage.DurableStateStorage)3 EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)3 StoreChannel (org.neo4j.io.fs.StoreChannel)3 CountsOracle (org.neo4j.kernel.impl.store.CountsOracle)3 PhysicalLogFiles (org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)3 ReadOnlyTransactionIdStore (org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionIdStore)3 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)3 Monitors (org.neo4j.kernel.monitoring.Monitors)3 IOException (java.io.IOException)2 ByteBuffer (java.nio.ByteBuffer)2 Future (java.util.concurrent.Future)2 StateMarshal (org.neo4j.causalclustering.core.state.storage.StateMarshal)2 MemberId (org.neo4j.causalclustering.identity.MemberId)2 PageCache (org.neo4j.io.pagecache.PageCache)2