Search in sources :

Example 26 with PhysicalLogFiles

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

the class TransactionLogCatchUpWriterTest method verifyCheckpointInLog.

private void verifyCheckpointInLog() throws IOException {
    LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>(new RecordStorageCommandReaderFactory());
    PhysicalLogFiles logFiles = new PhysicalLogFiles(storeDir, fs);
    final LatestCheckPointFinder checkPointFinder = new LatestCheckPointFinder(logFiles, fs, logEntryReader);
    LatestCheckPointFinder.LatestCheckPoint checkPoint = checkPointFinder.find(0);
    assertNotNull(checkPoint.checkPoint);
    assertTrue(checkPoint.commitsAfterCheckPoint);
}
Also used : RecordStorageCommandReaderFactory(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageCommandReaderFactory) LatestCheckPointFinder(org.neo4j.kernel.recovery.LatestCheckPointFinder) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)

Example 27 with PhysicalLogFiles

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

the class CheckTxLogsTest method shouldReportAnInconsistencyIfTxIdSequenceHasGaps.

@Test
public void shouldReportAnInconsistencyIfTxIdSequenceHasGaps() 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), 44L, newNodeCommandFunction.apply(4L));
    writeTxContent(logFile(2), 45L, newNodeCommandFunction.apply(5L));
    CapturingInconsistenciesHandler handler = new CapturingInconsistenciesHandler();
    CheckTxLogs checker = new CheckTxLogs(System.out, fsRule.get());
    // when
    checker.scan(new PhysicalLogFiles(storeDirectory, fsRule.get()), handler, CHECK_TYPES);
    // then
    System.out.println(handler.txIdSequenceInconsistencies);
    assertEquals(1, handler.txIdSequenceInconsistencies.size());
    assertEquals(42, handler.txIdSequenceInconsistencies.get(0).lastSeenTxId);
    assertEquals(44, handler.txIdSequenceInconsistencies.get(0).currentTxId);
}
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 28 with PhysicalLogFiles

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

the class CheckTxLogsTest method shouldReportNoInconsistenciesFromValidLog.

@Test
public void shouldReportNoInconsistenciesFromValidLog() throws Exception {
    // Given
    File log = logFile(1);
    writeTxContent(log, 1, 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)));
    writeTxContent(log, 2, new Command.NodeCommand(new NodeRecord(2, false, false, -1, -1, 1), new NodeRecord(2, true, false, -1, -1, 1)), new Command.NodeCommand(new NodeRecord(42, true, false, 42, -1, 1), new NodeRecord(42, true, false, 24, 5, 1)));
    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
    assertTrue(success);
    assertEquals(0, handler.recordInconsistencies.size());
}
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 29 with PhysicalLogFiles

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

the class CheckTxLogsTest method shouldReportPropertyInconsistenciesFromDifferentLogs.

@Test
public void shouldReportPropertyInconsistenciesFromDifferentLogs() 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)), new Command.NodeCommand(new NodeRecord(1, true, true, 2, -1, 1), new NodeRecord(1, true, false, -1, -1, 1)));
    writeTxContent(log2, 0, new Command.PropertyCommand(propertyRecord(24, false, -1, -1), propertyRecord(24, true, -1, -1, 777)));
    writeTxContent(log3, 0, new Command.PropertyCommand(propertyRecord(24, false, -1, -1), propertyRecord(24, true, -1, -1, 777)), new Command.NodeCommand(new NodeRecord(42, true, true, 42, -1, 1), new NodeRecord(42, true, true, 42, 10, 1)), new Command.PropertyCommand(propertyRecord(5, true, -1, -1, 777, 888), propertyRecord(5, true, -1, 9, 777, 888, 999)));
    CapturingInconsistenciesHandler handler = new CapturingInconsistenciesHandler();
    CheckTxLogs checker = new CheckTxLogs(System.out, fsRule.get());
    // When
    boolean success = checker.scan(new PhysicalLogFiles(storeDirectory, fsRule.get()), handler, PROPERTY);
    // Then
    assertFalse(success);
    assertEquals(2, handler.recordInconsistencies.size());
    RecordInconsistency inconsistency1 = handler.recordInconsistencies.get(0);
    PropertyRecord seenRecord1 = (PropertyRecord) inconsistency1.committed.record();
    PropertyRecord currentRecord1 = (PropertyRecord) inconsistency1.current.record();
    assertEquals(24, seenRecord1.getId());
    assertTrue(seenRecord1.inUse());
    assertEquals(24, currentRecord1.getId());
    assertFalse(currentRecord1.inUse());
    assertEquals(2, inconsistency1.committed.logVersion());
    assertEquals(3, inconsistency1.current.logVersion());
    RecordInconsistency inconsistency2 = handler.recordInconsistencies.get(1);
    PropertyRecord seenRecord2 = (PropertyRecord) inconsistency2.committed.record();
    PropertyRecord currentRecord2 = (PropertyRecord) inconsistency2.current.record();
    assertEquals(5, seenRecord2.getId());
    assertEquals(777, seenRecord2.getPropertyBlock(0).getSingleValueInt());
    assertEquals(5, currentRecord2.getId());
    assertEquals(777, currentRecord2.getPropertyBlock(0).getSingleValueInt());
    assertEquals(888, currentRecord2.getPropertyBlock(1).getSingleValueInt());
    assertEquals(1, inconsistency2.committed.logVersion());
    assertEquals(3, inconsistency2.current.logVersion());
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) 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 30 with PhysicalLogFiles

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

the class CheckTxLogsTest method shouldReportNodeInconsistenciesFromSingleLog.

@Test
public void shouldReportNodeInconsistenciesFromSingleLog() 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)));
    writeTxContent(log, 0, new Command.NodeCommand(new NodeRecord(2, false, false, -1, -1, 1), new NodeRecord(2, true, false, -1, -1, 1)), new Command.NodeCommand(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
    boolean success = checker.scan(new PhysicalLogFiles(storeDirectory, fsRule.get()), handler, NODE);
    // Then
    assertFalse(success);
    assertEquals(1, handler.recordInconsistencies.size());
    NodeRecord seenRecord = (NodeRecord) handler.recordInconsistencies.get(0).committed.record();
    NodeRecord currentRecord = (NodeRecord) handler.recordInconsistencies.get(0).current.record();
    assertEquals(42, seenRecord.getId());
    assertEquals(42, seenRecord.getNextRel());
    assertEquals(42, currentRecord.getId());
    assertEquals(24, currentRecord.getNextRel());
}
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)

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