Search in sources :

Example 16 with PhysicalLogFiles

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

the class CheckTxLogsTest method shouldDetectAnInconsistentCheckPointPointingToAByteOffsetNotInTheFile.

@Test
public void shouldDetectAnInconsistentCheckPointPointingToAByteOffsetNotInTheFile() throws Exception {
    // given
    ensureLogExists(logFile(1));
    writeCheckPoint(logFile(2), 1, 42);
    CapturingInconsistenciesHandler handler = new CapturingInconsistenciesHandler();
    CheckTxLogs checker = new CheckTxLogs(System.out, fsRule.get());
    // when
    checker.validateCheckPoints(new PhysicalLogFiles(storeDirectory, fsRule.get()), handler);
    // then
    assertEquals(1, handler.checkPointInconsistencies.size());
    assertEquals(2, handler.checkPointInconsistencies.get(0).logVersion);
    assertEquals(new LogPosition(1, 42), handler.checkPointInconsistencies.get(0).logPosition);
    assertEquals(LOG_HEADER_SIZE, handler.checkPointInconsistencies.get(0).size);
}
Also used : PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.Test)

Example 17 with PhysicalLogFiles

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

the class CheckTxLogsTest method shouldReportNeoStoreInconsistenciesFromSingleLog.

@Test
public void shouldReportNeoStoreInconsistenciesFromSingleLog() throws IOException {
    // Given
    File log = logFile(1);
    writeTxContent(log, 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(log, 0, new Command.NeoStoreCommand(createNeoStoreRecord(42), createNeoStoreRecord(33)));
    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(1, handler.recordInconsistencies.size());
    NeoStoreRecord seenRecord = (NeoStoreRecord) handler.recordInconsistencies.get(0).committed.record();
    NeoStoreRecord currentRecord = (NeoStoreRecord) handler.recordInconsistencies.get(0).current.record();
    assertEquals(21, seenRecord.getNextProp());
    assertEquals(42, currentRecord.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 18 with PhysicalLogFiles

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

the class CheckTxLogsTest method shouldNotReportInconsistencyIfTheCheckPointAreValidOrTheyReferToPrunedLogs.

@Test
public void shouldNotReportInconsistencyIfTheCheckPointAreValidOrTheyReferToPrunedLogs() throws Exception {
    // given
    writeCheckPoint(logFile(1), 0, LOG_HEADER_SIZE);
    writeCheckPoint(logFile(2), 1, LOG_HEADER_SIZE);
    writeCheckPoint(logFile(3), 3, LOG_HEADER_SIZE);
    CapturingInconsistenciesHandler handler = new CapturingInconsistenciesHandler();
    CheckTxLogs checker = new CheckTxLogs(System.out, fsRule.get());
    // when
    checker.validateCheckPoints(new PhysicalLogFiles(storeDirectory, fsRule.get()), handler);
    // then
    assertTrue(handler.checkPointInconsistencies.isEmpty());
}
Also used : PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) Test(org.junit.Test)

Example 19 with PhysicalLogFiles

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

the class CheckTxLogsTest method shouldReportTransactionIdAndInconsistencyCount.

@Test
public void shouldReportTransactionIdAndInconsistencyCount() throws IOException {
    // Given
    File log = logFile(1);
    writeTxContent(log, 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, false, -1, -1), propertyRecord(5, true, -1, -1, 777)), new Command.NodeCommand(new NodeRecord(1, true, true, 2, -1, 1), new NodeRecord(1, true, false, -1, -1, 1)), new Command.NodeCommand(new NodeRecord(5, true, true, 2, -1, 1), new NodeRecord(5, true, false, -1, -1, 1)));
    writeTxContent(log, 1, new Command.NodeCommand(new NodeRecord(2, false, false, -1, -1, 1), new NodeRecord(2, true, false, -1, -1, 1)), new Command.NodeCommand(// inconsistent
    new NodeRecord(5, true, true, 2, -1, 1), new NodeRecord(5, true, false, -1, -1, 1)), new Command.NodeCommand(new NodeRecord(1, true, false, -1, -1, 1), new NodeRecord(1, true, true, 2, 1, 1)), new Command.NodeCommand(// inconsistent
    new NodeRecord(42, true, false, 24, -1, 1), new NodeRecord(42, true, false, 24, 5, 1)));
    CapturingInconsistenciesHandler handler = new CapturingInconsistenciesHandler();
    CheckTxLogs checker = new CheckTxLogs(System.out, fsRule.get());
    // When
    checker.scan(new PhysicalLogFiles(storeDirectory, fsRule.get()), handler, NODE);
    // Then
    assertEquals(2, handler.recordInconsistencies.size());
    assertEquals(0, handler.recordInconsistencies.get(0).committed.txId());
    assertEquals(1, handler.recordInconsistencies.get(0).current.txId());
    assertEquals(0, handler.recordInconsistencies.get(1).committed.txId());
    assertEquals(1, handler.recordInconsistencies.get(1).current.txId());
}
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 20 with PhysicalLogFiles

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

the class BackupServiceIT method checkPreviousCommittedTxIdFromLog.

private void checkPreviousCommittedTxIdFromLog(long logVersion, long txId) throws IOException {
    // Assert header of specified log version containing correct txId
    PhysicalLogFiles logFiles = new PhysicalLogFiles(backupDir, fileSystem);
    LogHeader logHeader = LogHeaderReader.readLogHeader(fileSystem, logFiles.getLogFileForVersion(logVersion));
    assertEquals(txId, logHeader.lastCommittedTxId);
}
Also used : LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)

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