Search in sources :

Example 1 with AddRelationshipCommand

use of org.neo4j.internal.recordstorage.legacy.IndexCommand.AddRelationshipCommand in project neo4j by neo4j.

the class LogCommandSerializationV3_0_10 method readIndexAddRelationshipCommand.

@Override
protected Command readIndexAddRelationshipCommand(ReadableChannel channel) throws IOException {
    IndexCommandHeader header = readIndexCommandHeader(channel);
    Number entityId = header.entityIdNeedsLong ? channel.getLong() : channel.getInt();
    Object value = readIndexValue(header.valueType, channel);
    Number startNode = header.startNodeNeedsLong ? channel.getLong() : channel.getInt();
    Number endNode = header.endNodeNeedsLong ? channel.getLong() : channel.getInt();
    AddRelationshipCommand command = new AddRelationshipCommand();
    command.init(header.indexNameId, entityId.longValue(), header.keyId, value, startNode.longValue(), endNode.longValue());
    return command;
}
Also used : AddRelationshipCommand(org.neo4j.internal.recordstorage.legacy.IndexCommand.AddRelationshipCommand)

Example 2 with AddRelationshipCommand

use of org.neo4j.internal.recordstorage.legacy.IndexCommand.AddRelationshipCommand in project neo4j by neo4j.

the class PhysicalLogNeoCommandReaderTest method shouldProperlyMaskIndexIdFieldInIndexHeader.

@Test
void shouldProperlyMaskIndexIdFieldInIndexHeader() throws Exception {
    /* This is how the index command header is laid out
         * [x   ,    ] start node needs long
         * [ x  ,    ] end node needs long
         * [  xx,xxxx] index name id
         * This means that the index name id can be in the range of 0 to 63. This test verifies that
         * this constraint is actually respected
         */
    // GIVEN
    CommandReader reader = LogCommandSerializationV3_0_10.INSTANCE;
    InMemoryClosableChannel data = new InMemoryClosableChannel();
    // Here we take advantage of the fact that all index commands have the same header written out
    AddRelationshipCommand command = new AddRelationshipCommand();
    long entityId = 123;
    byte keyId = (byte) 1;
    Object value = "test value";
    long startNode = 14;
    long endNode = 15;
    for (byte indexByteId = 0; indexByteId < 63; indexByteId++) {
        // WHEN
        command.init(indexByteId, entityId, keyId, value, startNode, endNode);
        command.serialize(data);
        // THEN
        AddRelationshipCommand readCommand = (AddRelationshipCommand) reader.read(data);
        assertEquals(indexByteId, readCommand.getIndexNameId());
        assertEquals(entityId, readCommand.getEntityId());
        assertEquals(keyId, readCommand.getKeyId());
        assertEquals(value, readCommand.getValue());
        assertEquals(startNode, readCommand.getStartNode());
        assertEquals(endNode, readCommand.getEndNode());
        data.reset();
    }
}
Also used : CommandReader(org.neo4j.storageengine.api.CommandReader) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) AddRelationshipCommand(org.neo4j.internal.recordstorage.legacy.IndexCommand.AddRelationshipCommand) Test(org.junit.jupiter.api.Test)

Example 3 with AddRelationshipCommand

use of org.neo4j.internal.recordstorage.legacy.IndexCommand.AddRelationshipCommand in project neo4j by neo4j.

the class PhysicalLogNeoCommandReaderTest method shouldReadIndexCommandHeaderCorrectly.

@Test
void shouldReadIndexCommandHeaderCorrectly() throws Exception {
    // This bug manifested in header byte[1] {0,1,2}, which contains:
    // [x   ,    ] start node needs long
    // [ x  ,    ] end node needs long
    // [  xx,xxxx] index name id
    // would have the mask for reading "start node needs long" to 0x8, where it should have been 0x80.
    // So we need an index name id which has the 0x8 bit set to falsely read that value as "true".
    // Number 12 will do just fine.
    // GIVEN
    CommandReader reader = LogCommandSerializationV3_0_10.INSTANCE;
    InMemoryClosableChannel data = new InMemoryClosableChannel();
    AddRelationshipCommand command = new AddRelationshipCommand();
    byte indexNameId = (byte) 12;
    long entityId = 123;
    byte keyId = (byte) 1;
    Object value = "test value";
    long startNode = 14;
    long endNode = 15;
    // WHEN
    command.init(indexNameId, entityId, keyId, value, startNode, endNode);
    command.serialize(data);
    // THEN
    AddRelationshipCommand readCommand = (AddRelationshipCommand) reader.read(data);
    assertEquals(indexNameId, readCommand.getIndexNameId());
    assertEquals(entityId, readCommand.getEntityId());
    assertEquals(keyId, readCommand.getKeyId());
    assertEquals(value, readCommand.getValue());
    assertEquals(startNode, readCommand.getStartNode());
    assertEquals(endNode, readCommand.getEndNode());
}
Also used : CommandReader(org.neo4j.storageengine.api.CommandReader) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) AddRelationshipCommand(org.neo4j.internal.recordstorage.legacy.IndexCommand.AddRelationshipCommand) Test(org.junit.jupiter.api.Test)

Aggregations

AddRelationshipCommand (org.neo4j.internal.recordstorage.legacy.IndexCommand.AddRelationshipCommand)3 Test (org.junit.jupiter.api.Test)2 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)2 CommandReader (org.neo4j.storageengine.api.CommandReader)2