Search in sources :

Example 21 with NodeRecord

use of org.neo4j.kernel.impl.store.record.NodeRecord in project neo4j by neo4j.

the class InconsistencyReportReaderTest method shouldReadBasicEntities.

@Test
public void shouldReadBasicEntities() throws Exception {
    // GIVEN
    ByteArrayOutputStream out = new ByteArrayOutputStream(1_000);
    FormattedLog log = FormattedLog.toOutputStream(out);
    InconsistencyMessageLogger logger = new InconsistencyMessageLogger(log);
    long nodeId = 5;
    long relationshipGroupId = 10;
    long relationshipId = 15;
    long propertyId = 20;
    logger.error(RecordType.NODE, new NodeRecord(nodeId), "Some error", "something");
    logger.error(RecordType.RELATIONSHIP, new RelationshipRecord(relationshipId), "Some error", "something");
    logger.error(RecordType.RELATIONSHIP_GROUP, new RelationshipGroupRecord(relationshipGroupId), "Some error", "something");
    logger.error(RecordType.PROPERTY, new PropertyRecord(propertyId), "Some error", "something");
    String text = out.toString();
    PrimitiveLongSet nodes = Primitive.longSet();
    PrimitiveLongSet relationships = Primitive.longSet();
    PrimitiveLongSet relationshipGroups = Primitive.longSet();
    PrimitiveLongSet properties = Primitive.longSet();
    // WHEN
    InconsistencyReportReader reader = new InconsistencyReportReader(new Inconsistencies() {

        @Override
        public void relationshipGroup(long id) {
            relationshipGroups.add(id);
        }

        @Override
        public void relationship(long id) {
            relationships.add(id);
        }

        @Override
        public void property(long id) {
            properties.add(id);
        }

        @Override
        public void node(long id) {
            nodes.add(id);
        }
    });
    reader.read(new StringReader(text));
    // THEN
    assertEquals(asSet(iterator(nodeId)), nodes);
    assertEquals(asSet(iterator(relationshipId)), relationships);
    assertEquals(asSet(iterator(relationshipGroupId)), relationshipGroups);
    assertEquals(asSet(iterator(propertyId)), properties);
}
Also used : FormattedLog(org.neo4j.logging.FormattedLog) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) Inconsistencies(org.neo4j.tools.dump.InconsistencyReportReader.Inconsistencies) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) StringReader(java.io.StringReader) InconsistencyMessageLogger(org.neo4j.consistency.report.InconsistencyMessageLogger) Test(org.junit.Test)

Example 22 with NodeRecord

use of org.neo4j.kernel.impl.store.record.NodeRecord 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 23 with NodeRecord

use of org.neo4j.kernel.impl.store.record.NodeRecord 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 24 with NodeRecord

use of org.neo4j.kernel.impl.store.record.NodeRecord 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 25 with NodeRecord

use of org.neo4j.kernel.impl.store.record.NodeRecord in project neo4j by neo4j.

the class NodeCheckTypeTest method notInUseRecordEquality.

@Test
public void notInUseRecordEquality() {
    NodeRecord record1 = new NodeRecord(1);
    record1.initialize(false, 1, true, 2, 3);
    record1.setSecondaryUnitId(42);
    NodeRecord record2 = new NodeRecord(1);
    record2.initialize(false, 11, true, 22, 33);
    record2.setSecondaryUnitId(24);
    NodeCheckType check = new NodeCheckType();
    assertTrue(check.equal(record1, record2));
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) Test(org.junit.Test)

Aggregations

NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)257 Test (org.junit.Test)190 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)62 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)51 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)38 Command (org.neo4j.kernel.impl.transaction.command.Command)29 RelationshipTypeTokenRecord (org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord)28 RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)27 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)26 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)23 NodeLabels (org.neo4j.kernel.impl.store.NodeLabels)23 GraphStoreFixture (org.neo4j.consistency.checking.GraphStoreFixture)22 IdGenerator (org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator)22 TransactionDataBuilder (org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder)22 ArrayList (java.util.ArrayList)19 DynamicNodeLabels (org.neo4j.kernel.impl.store.DynamicNodeLabels)19 File (java.io.File)15 RecordAccessStub (org.neo4j.consistency.store.RecordAccessStub)13 NodeStore (org.neo4j.kernel.impl.store.NodeStore)11 ReusableRecordsAllocator (org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator)10