Search in sources :

Example 41 with DefaultFileSystemAbstraction

use of org.neo4j.io.fs.DefaultFileSystemAbstraction in project neo4j by neo4j.

the class CheckTxLogs method main.

public static void main(String[] args) throws Exception {
    PrintStream out = System.out;
    Args arguments = Args.withFlags(HELP_FLAG, VALIDATE_CHECKPOINTS_FLAG).parse(args);
    if (arguments.getBoolean(HELP_FLAG)) {
        printUsageAndExit(out);
    }
    boolean validateCheckPoints = arguments.getBoolean(VALIDATE_CHECKPOINTS_FLAG);
    CheckType<?, ?>[] checkTypes = parseChecks(arguments);
    File dir = parseDir(out, arguments);
    boolean success = false;
    try (FileSystemAbstraction fs = new DefaultFileSystemAbstraction()) {
        PhysicalLogFiles logFiles = new PhysicalLogFiles(dir, fs);
        int numberOfLogFilesFound = (int) (logFiles.getHighestLogVersion() - logFiles.getLowestLogVersion() + 1);
        out.println("Found " + numberOfLogFilesFound + " log files to verify in " + dir.getCanonicalPath());
        CheckTxLogs tool = new CheckTxLogs(out, fs);
        PrintingInconsistenciesHandler handler = new PrintingInconsistenciesHandler(out);
        success = tool.scan(logFiles, handler, checkTypes);
        if (validateCheckPoints) {
            success &= tool.validateCheckPoints(logFiles, handler);
        }
    }
    if (!success) {
        System.exit(1);
    }
}
Also used : PrintStream(java.io.PrintStream) Args(org.neo4j.helpers.Args) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) CheckType(org.neo4j.tools.txlog.checktypes.CheckType) File(java.io.File) CheckPoint(org.neo4j.kernel.impl.transaction.log.entry.CheckPoint) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)

Example 42 with DefaultFileSystemAbstraction

use of org.neo4j.io.fs.DefaultFileSystemAbstraction in project neo4j by neo4j.

the class ConcurrentStressIT method readAndWrite.

private void readAndWrite(int nReaders, int time, TimeUnit unit) throws Throwable {
    try (DefaultFileSystemAbstraction fsa = new DefaultFileSystemAbstraction()) {
        T raftLog = createRaftLog(fsa, dir.directory());
        try {
            ExecutorService es = Executors.newCachedThreadPool();
            Collection<Future<Long>> futures = new ArrayList<>();
            futures.add(es.submit(new TimedTask(() -> {
                write(raftLog);
            }, time, unit)));
            for (int i = 0; i < nReaders; i++) {
                futures.add(es.submit(new TimedTask(() -> {
                    read(raftLog);
                }, time, unit)));
            }
            for (Future<Long> f : futures) {
                long iterations = f.get();
            }
            es.shutdown();
        } finally {
            //noinspection ThrowFromFinallyBlock
            raftLog.shutdown();
        }
    }
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future)

Example 43 with DefaultFileSystemAbstraction

use of org.neo4j.io.fs.DefaultFileSystemAbstraction in project neo4j by neo4j.

the class ReplayRaftLog method main.

public static void main(String[] args) throws IOException {
    Args arg = Args.parse(args);
    String from = arg.get("from");
    System.out.println("From is " + from);
    String to = arg.get("to");
    System.out.println("to is " + to);
    File logDirectory = new File(from);
    System.out.println("logDirectory = " + logDirectory);
    Config config = Config.embeddedDefaults(stringMap());
    try (DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
        LogProvider logProvider = getInstance();
        CoreLogPruningStrategy pruningStrategy = new CoreLogPruningStrategyFactory(config.get(raft_log_pruning_strategy), logProvider).newInstance();
        SegmentedRaftLog log = new SegmentedRaftLog(fileSystem, logDirectory, config.get(raft_log_rotation_size), new CoreReplicatedContentMarshal(), logProvider, config.get(raft_log_reader_pool_size), Clocks.systemClock(), new OnDemandJobScheduler(), pruningStrategy);
        // Not really, but we need to have a way to pass in the commit index
        long totalCommittedEntries = log.appendIndex();
        for (int i = 0; i <= totalCommittedEntries; i++) {
            ReplicatedContent content = readLogEntry(log, i).content();
            if (content instanceof ReplicatedTransaction) {
                ReplicatedTransaction tx = (ReplicatedTransaction) content;
                ReplicatedTransactionFactory.extractTransactionRepresentation(tx, new byte[0]).accept(element -> {
                    System.out.println(element);
                    return false;
                });
            }
        }
    }
}
Also used : Args(org.neo4j.helpers.Args) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) SegmentedRaftLog(org.neo4j.causalclustering.core.consensus.log.segmented.SegmentedRaftLog) ReplicatedTransaction(org.neo4j.causalclustering.core.state.machines.tx.ReplicatedTransaction) Config(org.neo4j.kernel.configuration.Config) CoreLogPruningStrategyFactory(org.neo4j.causalclustering.core.consensus.log.segmented.CoreLogPruningStrategyFactory) CoreLogPruningStrategy(org.neo4j.causalclustering.core.consensus.log.segmented.CoreLogPruningStrategy) OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) LogProvider(org.neo4j.logging.LogProvider) CoreReplicatedContentMarshal(org.neo4j.causalclustering.messaging.CoreReplicatedContentMarshal) ReplicatedContent(org.neo4j.causalclustering.core.replication.ReplicatedContent) File(java.io.File)

Example 44 with DefaultFileSystemAbstraction

use of org.neo4j.io.fs.DefaultFileSystemAbstraction in project neo4j by neo4j.

the class RestartIT method readReplicaTest.

@Test
public void readReplicaTest() throws Exception {
    // given
    Cluster cluster = clusterRule.withNumberOfCoreMembers(2).withNumberOfReadReplicas(1).startCluster();
    // when
    final GraphDatabaseService coreDB = cluster.awaitLeader(5, TimeUnit.SECONDS).database();
    try (Transaction tx = coreDB.beginTx()) {
        Node node = coreDB.createNode(label("boo"));
        node.setProperty("foobar", "baz_bat");
        tx.success();
    }
    cluster.addCoreMemberWithId(2).start();
    cluster.shutdown();
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
        for (CoreClusterMember core : cluster.coreMembers()) {
            ConsistencyCheckService.Result result = new ConsistencyCheckService().runFullConsistencyCheck(core.storeDir(), Config.embeddedDefaults(), ProgressMonitorFactory.NONE, NullLogProvider.getInstance(), fileSystem, false, new CheckConsistencyConfig(true, true, true, false));
            assertTrue("Inconsistent: " + core, result.isSuccessful());
        }
        for (ReadReplica readReplica : cluster.readReplicas()) {
            ConsistencyCheckService.Result result = new ConsistencyCheckService().runFullConsistencyCheck(readReplica.storeDir(), Config.embeddedDefaults(), ProgressMonitorFactory.NONE, NullLogProvider.getInstance(), fileSystem, false, new CheckConsistencyConfig(true, true, true, false));
            assertTrue("Inconsistent: " + readReplica, result.isSuccessful());
        }
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) CheckConsistencyConfig(org.neo4j.consistency.checking.full.CheckConsistencyConfig) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Transaction(org.neo4j.graphdb.Transaction) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Node(org.neo4j.graphdb.Node) Cluster(org.neo4j.causalclustering.discovery.Cluster) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) Test(org.junit.Test)

Example 45 with DefaultFileSystemAbstraction

use of org.neo4j.io.fs.DefaultFileSystemAbstraction in project neo4j by neo4j.

the class ConvertNonCausalClusteringStoreIT method shouldReplicateTransactionToCoreMembers.

@Test
public void shouldReplicateTransactionToCoreMembers() throws Throwable {
    // given
    File dbDir = clusterRule.testDirectory().cleanDirectory("classic-db");
    int classicNodeCount = 1024;
    File classicNeo4jStore = createNeoStore(dbDir, classicNodeCount);
    Cluster cluster = this.clusterRule.withRecordFormat(recordFormat).createCluster();
    try (DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
        for (CoreClusterMember core : cluster.coreMembers()) {
            fileSystem.copyRecursively(classicNeo4jStore, core.storeDir());
        }
    }
    cluster.start();
    // when
    cluster.coreTx((coreDB, tx) -> {
        Node node = coreDB.createNode(label("boo"));
        node.setProperty("foobar", "baz_bat");
        tx.success();
    });
    cluster.addReadReplicaWithIdAndRecordFormat(4, recordFormat).start();
    // then
    for (final CoreClusterMember server : cluster.coreMembers()) {
        CoreGraphDatabase db = server.database();
        try (Transaction tx = db.beginTx()) {
            ThrowingSupplier<Long, Exception> nodeCount = () -> count(db.getAllNodes());
            Config config = db.getDependencyResolver().resolveDependency(Config.class);
            assertEventually("node to appear on core server " + config.get(raft_advertised_address), nodeCount, greaterThan((long) classicNodeCount), 15, SECONDS);
            assertEquals(classicNodeCount + 1, count(db.getAllNodes()));
            tx.success();
        }
    }
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Transaction(org.neo4j.graphdb.Transaction) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Config(org.neo4j.kernel.configuration.Config) Node(org.neo4j.graphdb.Node) Cluster(org.neo4j.causalclustering.discovery.Cluster) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) File(java.io.File) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)82 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)43 File (java.io.File)24 Path (java.nio.file.Path)21 PageCache (org.neo4j.io.pagecache.PageCache)21 Test (org.junit.Test)14 Test (org.junit.jupiter.api.Test)13 IOException (java.io.IOException)12 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)11 Config (org.neo4j.kernel.configuration.Config)11 Config (org.neo4j.configuration.Config)9 ThreadPoolJobScheduler (org.neo4j.test.scheduler.ThreadPoolJobScheduler)8 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)7 Transaction (org.neo4j.graphdb.Transaction)7 PrintStream (java.io.PrintStream)6 Before (org.junit.Before)6 CommandFailed (org.neo4j.commandline.admin.CommandFailed)6 Args (org.neo4j.helpers.Args)6 StandalonePageCacheFactory.createPageCache (org.neo4j.io.pagecache.impl.muninn.StandalonePageCacheFactory.createPageCache)6 JobScheduler (org.neo4j.scheduler.JobScheduler)6