Search in sources :

Example 11 with PhysicalLogFiles

use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles 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 12 with PhysicalLogFiles

use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles in project neo4j by neo4j.

the class CheckTxLogsTest method shouldReportNoInconsistenciesIfTxIdSequenceIsStriclyIncreasingAndHasNoGaps.

@Test
public void shouldReportNoInconsistenciesIfTxIdSequenceIsStriclyIncreasingAndHasNoGaps() throws Exception {
    // given
    Function<Long, Command.NodeCommand> newNodeCommandFunction = (i) -> new Command.NodeCommand(new NodeRecord(i, false, false, -1, -1, -1), new NodeRecord(i, true, false, -1, -1, -1));
    writeTxContent(logFile(1), 40L, newNodeCommandFunction.apply(1L));
    writeTxContent(logFile(1), 41L, newNodeCommandFunction.apply(2L));
    writeTxContent(logFile(1), 42L, newNodeCommandFunction.apply(3L));
    writeTxContent(logFile(2), 43L, newNodeCommandFunction.apply(4L));
    writeTxContent(logFile(2), 44L, newNodeCommandFunction.apply(5L));
    writeTxContent(logFile(2), 45L, newNodeCommandFunction.apply(6L));
    CapturingInconsistenciesHandler handler = new CapturingInconsistenciesHandler();
    CheckTxLogs checker = new CheckTxLogs(System.out, fsRule.get());
    // when
    checker.scan(new PhysicalLogFiles(storeDirectory, fsRule.get()), handler, CHECK_TYPES);
    // then
    assertTrue(handler.txIdSequenceInconsistencies.isEmpty());
}
Also used : Arrays(java.util.Arrays) PropertyType(org.neo4j.kernel.impl.store.PropertyType) PhysicalFlushableChannel(org.neo4j.kernel.impl.transaction.log.PhysicalFlushableChannel) EphemeralFileSystemRule(org.neo4j.test.rule.fs.EphemeralFileSystemRule) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) CheckTypes(org.neo4j.tools.txlog.checktypes.CheckTypes) PROPERTY(org.neo4j.tools.txlog.checktypes.CheckTypes.PROPERTY) Function(java.util.function.Function) ArrayList(java.util.ArrayList) NEO_STORE(org.neo4j.tools.txlog.checktypes.CheckTypes.NEO_STORE) Assert.assertThat(org.junit.Assert.assertThat) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Command(org.neo4j.kernel.impl.transaction.command.Command) StoreChannel(org.neo4j.io.fs.StoreChannel) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) RELATIONSHIP_GROUP(org.neo4j.tools.txlog.checktypes.CheckTypes.RELATIONSHIP_GROUP) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) ThrowingConsumer(org.neo4j.function.ThrowingConsumer) Matchers.lessThan(org.hamcrest.Matchers.lessThan) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) CHECK_TYPES(org.neo4j.tools.txlog.checktypes.CheckTypes.CHECK_TYPES) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) LogHeaderWriter(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderWriter) File(java.io.File) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) List(java.util.List) Rule(org.junit.Rule) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) RELATIONSHIP(org.neo4j.tools.txlog.checktypes.CheckTypes.RELATIONSHIP) Assert.assertFalse(org.junit.Assert.assertFalse) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) LOG_HEADER_SIZE(org.neo4j.kernel.impl.transaction.log.entry.LogHeader.LOG_HEADER_SIZE) NODE(org.neo4j.tools.txlog.checktypes.CheckTypes.NODE) NeoStoreRecord(org.neo4j.kernel.impl.store.record.NeoStoreRecord) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) TransactionLogWriter(org.neo4j.kernel.impl.transaction.log.TransactionLogWriter) SuppressOutput(org.neo4j.test.rule.SuppressOutput) Assert.assertEquals(org.junit.Assert.assertEquals) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) Test(org.junit.Test)

Example 13 with PhysicalLogFiles

use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles in project neo4j by neo4j.

the class CheckTxLogsTest method shouldReportNeoStoreInconsistenciesFromDifferentLogs.

@Test
public void shouldReportNeoStoreInconsistenciesFromDifferentLogs() throws IOException {
    // Given
    File log1 = logFile(1);
    File log2 = logFile(2);
    File log3 = logFile(3);
    writeTxContent(log1, 0, new Command.NeoStoreCommand(new NeoStoreRecord(), createNeoStoreRecord(42)), new Command.PropertyCommand(propertyRecord(5, false, -1, -1), propertyRecord(5, true, -1, -1, 777)), new Command.NeoStoreCommand(createNeoStoreRecord(42), createNeoStoreRecord(21)));
    writeTxContent(log2, 0, new Command.NeoStoreCommand(createNeoStoreRecord(12), createNeoStoreRecord(21)));
    writeTxContent(log3, 0, new Command.NeoStoreCommand(createNeoStoreRecord(13), createNeoStoreRecord(21)));
    CapturingInconsistenciesHandler handler = new CapturingInconsistenciesHandler();
    CheckTxLogs checker = new CheckTxLogs(System.out, fsRule.get());
    // When
    checker.scan(new PhysicalLogFiles(storeDirectory, fsRule.get()), handler, NEO_STORE);
    // Then
    assertEquals(2, handler.recordInconsistencies.size());
    NeoStoreRecord seenRecord1 = (NeoStoreRecord) handler.recordInconsistencies.get(0).committed.record();
    NeoStoreRecord currentRecord1 = (NeoStoreRecord) handler.recordInconsistencies.get(0).current.record();
    assertEquals(21, seenRecord1.getNextProp());
    assertEquals(12, currentRecord1.getNextProp());
    NeoStoreRecord seenRecord2 = (NeoStoreRecord) handler.recordInconsistencies.get(1).committed.record();
    NeoStoreRecord currentRecord2 = (NeoStoreRecord) handler.recordInconsistencies.get(1).current.record();
    assertEquals(21, seenRecord2.getNextProp());
    assertEquals(13, currentRecord2.getNextProp());
}
Also used : NeoStoreRecord(org.neo4j.kernel.impl.store.record.NeoStoreRecord) Command(org.neo4j.kernel.impl.transaction.command.Command) File(java.io.File) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) Test(org.junit.Test)

Example 14 with PhysicalLogFiles

use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles in project neo4j by neo4j.

the class CheckTxLogsTest method shouldReportNodeInconsistenciesFromDifferentLogs.

@Test
public void shouldReportNodeInconsistenciesFromDifferentLogs() throws IOException {
    // Given
    File log1 = logFile(1);
    File log2 = logFile(2);
    File log3 = logFile(3);
    writeTxContent(log1, 0, new Command.NodeCommand(new NodeRecord(42, false, false, -1, -1, 1), new NodeRecord(42, true, false, 42, -1, 1)), new Command.PropertyCommand(propertyRecord(5, true, -1, -1, 777), propertyRecord(5, true, -1, -1, 777, 888)), new Command.NodeCommand(new NodeRecord(1, true, true, 2, -1, 1), new NodeRecord(1, true, false, -1, -1, 1)));
    writeTxContent(log2, 0, new Command.NodeCommand(new NodeRecord(2, false, false, -1, -1, 1), new NodeRecord(2, true, false, -1, -1, 1)));
    writeTxContent(log3, 0, new Command.NodeCommand(new NodeRecord(42, true, true, 42, -1, 1), new NodeRecord(42, true, true, 42, 10, 1)), new Command.NodeCommand(new NodeRecord(2, true, false, -1, -1, 5), new NodeRecord(2, false, false, -1, -1, 5)));
    CapturingInconsistenciesHandler handler = new CapturingInconsistenciesHandler();
    CheckTxLogs checker = new CheckTxLogs(System.out, fsRule.get());
    // When
    boolean success = checker.scan(new PhysicalLogFiles(storeDirectory, fsRule.get()), handler, NODE);
    // Then
    assertFalse(success);
    assertEquals(2, handler.recordInconsistencies.size());
    NodeRecord seenRecord1 = (NodeRecord) handler.recordInconsistencies.get(0).committed.record();
    NodeRecord currentRecord1 = (NodeRecord) handler.recordInconsistencies.get(0).current.record();
    assertEquals(42, seenRecord1.getId());
    assertFalse(seenRecord1.isDense());
    assertEquals(42, currentRecord1.getId());
    assertTrue(currentRecord1.isDense());
    NodeRecord seenRecord2 = (NodeRecord) handler.recordInconsistencies.get(1).committed.record();
    NodeRecord currentRecord2 = (NodeRecord) handler.recordInconsistencies.get(1).current.record();
    assertEquals(2, seenRecord2.getId());
    assertEquals(1, seenRecord2.getLabelField());
    assertEquals(2, currentRecord2.getId());
    assertEquals(5, currentRecord2.getLabelField());
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) Command(org.neo4j.kernel.impl.transaction.command.Command) File(java.io.File) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) Test(org.junit.Test)

Example 15 with PhysicalLogFiles

use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles in project neo4j by neo4j.

the class CheckTxLogsTest method shouldReportRelationshipInconsistenciesFromSingleLog.

@Test
public void shouldReportRelationshipInconsistenciesFromSingleLog() throws IOException {
    // Given
    File log = logFile(1);
    writeTxContent(log, 0, new Command.RelationshipCommand(new RelationshipRecord(42, false, -1, -1, -1, -1, -1, -1, -1, false, false), new RelationshipRecord(42, true, 1, 2, 3, 4, 5, 6, 7, true, true)), new Command.PropertyCommand(propertyRecord(5, false, -1, -1), propertyRecord(5, true, -1, -1, 777)), new Command.RelationshipCommand(new RelationshipRecord(21, true, 1, 2, 3, 4, 5, 6, 7, true, true), new RelationshipRecord(21, false, -1, -1, -1, -1, -1, -1, -1, false, false)));
    writeTxContent(log, 0, new Command.RelationshipCommand(new RelationshipRecord(53, true, 1, 2, 3, 4, 5, 6, 7, true, true), new RelationshipRecord(53, true, 1, 2, 30, 4, 14, 6, 7, true, true)), new Command.RelationshipCommand(new RelationshipRecord(42, true, 1, 2, 3, 9, 5, 6, 7, true, true), new RelationshipRecord(42, true, 1, 2, 3, 4, 5, 6, 7, true, true)));
    CapturingInconsistenciesHandler handler = new CapturingInconsistenciesHandler();
    CheckTxLogs checker = new CheckTxLogs(System.out, fsRule.get());
    // When
    checker.scan(new PhysicalLogFiles(storeDirectory, fsRule.get()), handler, RELATIONSHIP);
    // Then
    assertEquals(1, handler.recordInconsistencies.size());
    RelationshipRecord seenRecord = (RelationshipRecord) handler.recordInconsistencies.get(0).committed.record();
    RelationshipRecord currentRecord = (RelationshipRecord) handler.recordInconsistencies.get(0).current.record();
    assertEquals(42, seenRecord.getId());
    assertEquals(4, seenRecord.getFirstPrevRel());
    assertEquals(42, currentRecord.getId());
    assertEquals(9, currentRecord.getFirstPrevRel());
}
Also used : Command(org.neo4j.kernel.impl.transaction.command.Command) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) File(java.io.File) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) Test(org.junit.Test)

Aggregations

PhysicalLogFiles (org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)53 File (java.io.File)38 Test (org.junit.Test)29 PhysicalLogFile (org.neo4j.kernel.impl.transaction.log.PhysicalLogFile)29 Command (org.neo4j.kernel.impl.transaction.command.Command)15 IOException (java.io.IOException)14 LogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)12 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)11 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)9 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)8 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)8 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)7 LatestCheckPointFinder (org.neo4j.kernel.recovery.LatestCheckPointFinder)7 LogFile (org.neo4j.kernel.impl.transaction.log.LogFile)6 TransactionLogWriter (org.neo4j.kernel.impl.transaction.log.TransactionLogWriter)6 Function (java.util.function.Function)5 Assert.assertEquals (org.junit.Assert.assertEquals)5 Assert.assertTrue (org.junit.Assert.assertTrue)5 Rule (org.junit.Rule)5 StoreChannel (org.neo4j.io.fs.StoreChannel)5