Search in sources :

Example 31 with PhysicalLogFiles

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

the class CheckTxLogsTest method shouldReportPropertyInconsistenciesFromSingleLog.

@Test
public void shouldReportPropertyInconsistenciesFromSingleLog() throws IOException {
    // Given
    File log = logFile(1);
    writeTxContent(log, 0, new Command.PropertyCommand(propertyRecord(42, false, -1, -1), propertyRecord(42, true, -1, -1, 10)), new Command.PropertyCommand(propertyRecord(42, true, -1, -1, 10), propertyRecord(42, true, 24, -1, 10)));
    writeTxContent(log, 0, new Command.NodeCommand(new NodeRecord(2, false, false, -1, -1, 1), new NodeRecord(2, true, false, -1, -1, 1)), new Command.PropertyCommand(propertyRecord(42, true, -1, -1, 10), propertyRecord(42, true, -1, -1, 10, 20)));
    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(1, handler.recordInconsistencies.size());
    PropertyRecord seenRecord = (PropertyRecord) handler.recordInconsistencies.get(0).committed.record();
    PropertyRecord currentRecord = (PropertyRecord) handler.recordInconsistencies.get(0).current.record();
    assertEquals(42, seenRecord.getId());
    assertEquals(24, seenRecord.getPrevProp());
    assertEquals(42, currentRecord.getId());
    assertEquals(-1, currentRecord.getPrevProp());
}
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 32 with PhysicalLogFiles

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

the class CheckTxLogsTest method shouldDetectAnInconsistentCheckPointPointingToALogFileGreaterThanMaxLogVersion.

@Test
public void shouldDetectAnInconsistentCheckPointPointingToALogFileGreaterThanMaxLogVersion() throws Exception {
    // given
    File log = logFile(1);
    writeCheckPoint(log, 2, 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
    assertEquals(1, handler.checkPointInconsistencies.size());
    assertEquals(1, handler.checkPointInconsistencies.get(0).logVersion);
    assertEquals(new LogPosition(2, LOG_HEADER_SIZE), handler.checkPointInconsistencies.get(0).logPosition);
    assertThat(handler.checkPointInconsistencies.get(0).size, lessThan(0L));
}
Also used : File(java.io.File) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.Test)

Example 33 with PhysicalLogFiles

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

the class CheckTxLogsTest method shouldReportRelationshipGroupInconsistenciesFromDifferentLogs.

@Test
public void shouldReportRelationshipGroupInconsistenciesFromDifferentLogs() throws IOException {
    // Given
    File log1 = logFile(1);
    File log2 = logFile(2);
    File log3 = logFile(3);
    writeTxContent(log1, 0, new Command.RelationshipGroupCommand(new RelationshipGroupRecord(42, -1, -1, -1, -1, -1, -1, false), new RelationshipGroupRecord(42, 1, 2, 3, 4, 5, 6, true)), new Command.PropertyCommand(propertyRecord(5, false, -1, -1), propertyRecord(5, true, -1, -1, 777)), new Command.RelationshipGroupCommand(new RelationshipGroupRecord(21, 1, 2, 3, 4, 5, 6, true), new RelationshipGroupRecord(21, -1, -1, -1, -1, -1, -1, false)));
    writeTxContent(log2, 0, new Command.RelationshipGroupCommand(new RelationshipGroupRecord(42, 1, 2, 3, 9, 5, 6, true), new RelationshipGroupRecord(42, 1, 2, 3, 4, 5, 6, true)));
    writeTxContent(log3, 0, new Command.RelationshipGroupCommand(new RelationshipGroupRecord(53, 1, 2, 3, 4, 5, 6, true), new RelationshipGroupRecord(53, 1, 2, 30, 4, 14, 6, true)), new Command.RelationshipGroupCommand(new RelationshipGroupRecord(42, 1, 2, 3, 4, 5, 6, false), new RelationshipGroupRecord(42, 1, 2, 3, 4, 5, 6, false)));
    CapturingInconsistenciesHandler handler = new CapturingInconsistenciesHandler();
    CheckTxLogs checker = new CheckTxLogs(System.out, fsRule.get());
    // When
    checker.scan(new PhysicalLogFiles(storeDirectory, fsRule.get()), handler, RELATIONSHIP_GROUP);
    // Then
    assertEquals(2, handler.recordInconsistencies.size());
    RelationshipGroupRecord seenRecord1 = (RelationshipGroupRecord) handler.recordInconsistencies.get(0).committed.record();
    RelationshipGroupRecord currentRecord1 = (RelationshipGroupRecord) handler.recordInconsistencies.get(0).current.record();
    assertEquals(42, seenRecord1.getId());
    assertEquals(4, seenRecord1.getFirstLoop());
    assertEquals(42, currentRecord1.getId());
    assertEquals(9, currentRecord1.getFirstLoop());
    RelationshipGroupRecord seenRecord2 = (RelationshipGroupRecord) handler.recordInconsistencies.get(1).committed.record();
    RelationshipGroupRecord currentRecord2 = (RelationshipGroupRecord) handler.recordInconsistencies.get(1).current.record();
    assertEquals(42, seenRecord2.getId());
    assertTrue(seenRecord2.inUse());
    assertEquals(42, currentRecord2.getId());
    assertFalse(currentRecord2.inUse());
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) 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 34 with PhysicalLogFiles

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

the class CheckTxLogsTest method shouldReportAnInconsistencyIfTxIdSequenceIsNotStrictlyIncreasing.

@Test
public void shouldReportAnInconsistencyIfTxIdSequenceIsNotStrictlyIncreasing() 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), 42L, newNodeCommandFunction.apply(4L));
    writeTxContent(logFile(2), 43L, 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
    assertEquals(1, handler.txIdSequenceInconsistencies.size());
    assertEquals(42, handler.txIdSequenceInconsistencies.get(0).lastSeenTxId);
    assertEquals(42, 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 35 with PhysicalLogFiles

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

the class CheckTxLogsTest method shouldReportRelationshipGroupInconsistenciesFromSingleLog.

@Test
public void shouldReportRelationshipGroupInconsistenciesFromSingleLog() throws IOException {
    // Given
    File log = logFile(1);
    writeTxContent(log, 0, new Command.RelationshipGroupCommand(new RelationshipGroupRecord(42, -1, -1, -1, -1, -1, -1, false), new RelationshipGroupRecord(42, 1, 2, 3, 4, 5, 6, true)), new Command.PropertyCommand(propertyRecord(5, false, -1, -1), propertyRecord(5, true, -1, -1, 777)), new Command.RelationshipGroupCommand(new RelationshipGroupRecord(21, 1, 2, 3, 4, 5, 7, true), new RelationshipGroupRecord(21, -1, -1, -1, -1, -1, -1, false)));
    writeTxContent(log, 0, new Command.RelationshipGroupCommand(new RelationshipGroupRecord(53, 1, 2, 3, 4, 5, 6, true), new RelationshipGroupRecord(53, 1, 2, 30, 4, 14, 6, true)), new Command.RelationshipGroupCommand(new RelationshipGroupRecord(42, 1, 2, 3, 9, 5, 6, true), new RelationshipGroupRecord(42, 1, 2, 3, 4, 5, 6, true)));
    CapturingInconsistenciesHandler handler = new CapturingInconsistenciesHandler();
    CheckTxLogs checker = new CheckTxLogs(System.out, fsRule.get());
    // When
    checker.scan(new PhysicalLogFiles(storeDirectory, fsRule.get()), handler, RELATIONSHIP_GROUP);
    // Then
    assertEquals(1, handler.recordInconsistencies.size());
    RelationshipGroupRecord seenRecord = (RelationshipGroupRecord) handler.recordInconsistencies.get(0).committed.record();
    RelationshipGroupRecord currentRecord = (RelationshipGroupRecord) handler.recordInconsistencies.get(0).current.record();
    assertEquals(42, seenRecord.getId());
    assertEquals(4, seenRecord.getFirstLoop());
    assertEquals(42, currentRecord.getId());
    assertEquals(9, currentRecord.getFirstLoop());
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) 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