Search in sources :

Example 16 with PageCache

use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.

the class RsdrMain method main.

public static void main(String[] args) throws IOException {
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
        console.printf("Neo4j Raw Store Diagnostics Reader%n");
        if (args.length != 1 || !fileSystem.isDirectory(new File(args[0]))) {
            console.printf("Usage: rsdr <store directory>%n");
            return;
        }
        File storedir = new File(args[0]);
        Config config = buildConfig();
        try (PageCache pageCache = createPageCache(fileSystem, config)) {
            File neoStore = new File(storedir, MetaDataStore.DEFAULT_NAME);
            StoreFactory factory = openStore(fileSystem, neoStore, config, pageCache);
            NeoStores neoStores = factory.openAllNeoStores();
            interact(fileSystem, neoStores);
        }
    }
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Config(org.neo4j.kernel.configuration.Config) NeoStores(org.neo4j.kernel.impl.store.NeoStores) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) ConfigurableStandalonePageCacheFactory.createPageCache(org.neo4j.kernel.impl.pagecache.ConfigurableStandalonePageCacheFactory.createPageCache)

Example 17 with PageCache

use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.

the class RebuildFromLogs method rebuild.

public void rebuild(File source, File target, long txId) throws Exception, InconsistentStoreException {
    try (PageCache pageCache = StandalonePageCacheFactory.createPageCache(fs)) {
        PhysicalLogFiles logFiles = new PhysicalLogFiles(source, fs);
        long highestVersion = logFiles.getHighestLogVersion();
        if (highestVersion < 0) {
            printUsage("Inconsistent number of log files found in " + source);
            return;
        }
        long txCount = findLastTransactionId(logFiles, highestVersion);
        ProgressMonitorFactory progress;
        if (txCount < 0) {
            progress = ProgressMonitorFactory.NONE;
            System.err.println("Unable to report progress, cannot find highest txId, attempting rebuild anyhow.");
        } else {
            progress = ProgressMonitorFactory.textual(System.err);
        }
        progress.singlePart(format("Rebuilding store from %s transactions ", txCount), txCount);
        long lastTxId;
        try (TransactionApplier applier = new TransactionApplier(fs, target, pageCache)) {
            lastTxId = applier.applyTransactionsFrom(source, txId);
        }
        // set last tx id in neostore otherwise the db is not usable
        MetaDataStore.setRecord(pageCache, new File(target, MetaDataStore.DEFAULT_NAME), MetaDataStore.Position.LAST_TRANSACTION_ID, lastTxId);
        checkConsistency(target, pageCache);
    }
}
Also used : ProgressMonitorFactory(org.neo4j.helpers.progress.ProgressMonitorFactory) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) ExternallyManagedPageCache(org.neo4j.com.storecopy.ExternallyManagedPageCache) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)

Example 18 with PageCache

use of org.neo4j.io.pagecache.PageCache 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();
    }
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) TransactionAppender(org.neo4j.kernel.impl.transaction.log.TransactionAppender) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) StorageEngine(org.neo4j.storageengine.api.StorageEngine) ReadOnlyTransactionStore(org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionStore) DependencyResolver(org.neo4j.graphdb.DependencyResolver) ProgressListener(org.neo4j.helpers.progress.ProgressListener) TransactionRepresentationCommitProcess(org.neo4j.kernel.impl.api.TransactionRepresentationCommitProcess) Monitors(org.neo4j.kernel.monitoring.Monitors) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) PageCache(org.neo4j.io.pagecache.PageCache)

Example 19 with PageCache

use of org.neo4j.io.pagecache.PageCache 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 20 with PageCache

use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.

the class StartStopLoad method assertStoreConsistent.

private void assertStoreConsistent(String storeDir, KernelExtensions kernelExtensions) {
    File fromDirectory = new File(storeDir);
    File parent = fromDirectory.getParentFile();
    try (TemporaryStoreDirectory storeDirectory = new TemporaryStoreDirectory(fs, pageCache, parent);
        PageCache pageCache = StandalonePageCacheFactory.createPageCache(fs)) {
        fs.copyRecursively(fromDirectory, storeDirectory.storeDir());
        new CopiedStoreRecovery(Config.defaults(), kernelExtensions.listFactories(), pageCache).recoverCopiedStore(storeDirectory.storeDir());
        ConsistencyCheckService.Result result = runConsistencyCheckTool(new String[] { storeDir });
        if (!result.isSuccessful()) {
            throw new RuntimeException("Not consistent database in " + storeDir);
        }
    } catch (Throwable e) {
        throw new RuntimeException("Failed to run CC on " + storeDir, e);
    }
}
Also used : CopiedStoreRecovery(org.neo4j.causalclustering.catchup.storecopy.CopiedStoreRecovery) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) TemporaryStoreDirectory(org.neo4j.causalclustering.catchup.storecopy.TemporaryStoreDirectory) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache)

Aggregations

PageCache (org.neo4j.io.pagecache.PageCache)134 Test (org.junit.Test)90 File (java.io.File)74 Config (org.neo4j.kernel.configuration.Config)39 IOException (java.io.IOException)32 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)31 StoreVersionCheck (org.neo4j.kernel.impl.storemigration.StoreVersionCheck)19 LegacyStoreVersionCheck (org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck)17 UpgradableDatabase (org.neo4j.kernel.impl.storemigration.UpgradableDatabase)16 PagedFile (org.neo4j.io.pagecache.PagedFile)15 LogService (org.neo4j.kernel.impl.logging.LogService)13 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)12 NullLogService (org.neo4j.kernel.impl.logging.NullLogService)12 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)12 NeoStores (org.neo4j.kernel.impl.store.NeoStores)11 RecordFormatSelector.selectForConfig (org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForConfig)11 RecordFormatSelector.selectForStoreOrConfig (org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForStoreOrConfig)11 Before (org.junit.Before)10 TransactionId (org.neo4j.kernel.impl.store.TransactionId)10 StoreCopyClient (org.neo4j.com.storecopy.StoreCopyClient)9