Search in sources :

Example 66 with FileSystemAbstraction

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

the class DumpLogicalLog method main.

/**
     * Usage: [--txfilter "regex"] [--ccfilter cc-report-file] [--tofile] storeDirOrFile1 storeDirOrFile2 ...
     *
     * --txfilter
     * Will match regex against each {@link LogEntry} and if there is a match,
     * include transaction containing the LogEntry in the dump.
     * regex matching is done with {@link Pattern}
     *
     * --ccfilter
     * Will look at an inconsistency report file from consistency checker and
     * include transactions that are relevant to them
     *
     * --tofile
     * Redirects output to dump-logical-log.txt in the store directory
     */
public static void main(String[] args) throws IOException {
    Args arguments = Args.withFlags(TO_FILE).parse(args);
    TimeZone timeZone = parseTimeZoneConfig(arguments);
    Predicate<LogEntry[]> filter = parseFilter(arguments, timeZone);
    Function<LogEntry, String> serializer = parseSerializer(filter, timeZone);
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        Printer printer = getPrinter(arguments)) {
        for (String fileAsString : arguments.orphans()) {
            new DumpLogicalLog(fileSystem).dump(fileAsString, printer.getFor(fileAsString), filter, serializer);
        }
    }
}
Also used : Args(org.neo4j.helpers.Args) TimeZone.getTimeZone(java.util.TimeZone.getTimeZone) TimeZone(java.util.TimeZone) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry)

Example 67 with FileSystemAbstraction

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

the class CheckTxLogsTest method writeContent.

private void writeContent(File log, ThrowingConsumer<TransactionLogWriter, IOException> consumer) throws IOException {
    FileSystemAbstraction fs = ensureLogExists(log);
    try (StoreChannel channel = fs.open(log, "rw");
        LogVersionedStoreChannel versionedChannel = new PhysicalLogVersionedStoreChannel(channel, 0, (byte) 0);
        PhysicalFlushableChannel writableLogChannel = new PhysicalFlushableChannel(versionedChannel)) {
        long offset = channel.size();
        channel.position(offset);
        consumer.accept(new TransactionLogWriter(new LogEntryWriter(writableLogChannel)));
    }
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) PhysicalFlushableChannel(org.neo4j.kernel.impl.transaction.log.PhysicalFlushableChannel) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) TransactionLogWriter(org.neo4j.kernel.impl.transaction.log.TransactionLogWriter) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)

Example 68 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction 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 69 with FileSystemAbstraction

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

the class SegmentedRaftLogRotationTruncationPruneTest method createRaftLog.

private RaftLog createRaftLog() throws Exception {
    File directory = new File(RAFT_LOG_DIRECTORY_NAME);
    FileSystemAbstraction fileSystem = new EphemeralFileSystemAbstraction();
    fileSystem.mkdir(directory);
    LogProvider logProvider = getInstance();
    CoreLogPruningStrategy pruningStrategy = new CoreLogPruningStrategyFactory("1 entries", logProvider).newInstance();
    SegmentedRaftLog newRaftLog = new SegmentedRaftLog(fileSystem, directory, 1, new DummyRaftableContentSerializer(), logProvider, 8, Clocks.fakeClock(), new OnDemandJobScheduler(), pruningStrategy);
    newRaftLog.start();
    return newRaftLog;
}
Also used : LogProvider(org.neo4j.logging.LogProvider) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) File(java.io.File) DummyRaftableContentSerializer(org.neo4j.causalclustering.core.consensus.log.DummyRaftableContentSerializer)

Example 70 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction 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)

Aggregations

FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)125 File (java.io.File)88 Test (org.junit.Test)82 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)34 IOException (java.io.IOException)28 Config (org.neo4j.kernel.configuration.Config)23 EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)22 PageCache (org.neo4j.io.pagecache.PageCache)22 DelegatingFileSystemAbstraction (org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction)20 ByteBuffer (java.nio.ByteBuffer)13 StoreChannel (org.neo4j.io.fs.StoreChannel)11 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)10 UncloseableDelegatingFileSystemAbstraction (org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction)9 DefaultIdGeneratorFactory (org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory)9 OutputStream (java.io.OutputStream)8 AdversarialFileSystemAbstraction (org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction)8 DelegatingStoreChannel (org.neo4j.graphdb.mockfs.DelegatingStoreChannel)8 Map (java.util.Map)7 Matchers.containsString (org.hamcrest.Matchers.containsString)7 AdversarialPagedFile (org.neo4j.adversaries.pagecache.AdversarialPagedFile)7