Search in sources :

Example 1 with PropertyCommand

use of org.neo4j.kernel.impl.transaction.command.Command.PropertyCommand in project neo4j by neo4j.

the class TransactionRecordStateTest method shouldCreateProperBeforeAndAfterPropertyCommandsWhenAddingProperty.

@Test
public void shouldCreateProperBeforeAndAfterPropertyCommandsWhenAddingProperty() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    int nodeId = 1;
    recordState.nodeCreate(nodeId);
    int propertyKey = 1;
    Object value = 5;
    // WHEN
    recordState.nodeAddProperty(nodeId, propertyKey, value);
    Collection<StorageCommand> commands = new ArrayList<>();
    recordState.extractCommands(commands);
    PropertyCommand propertyCommand = singlePropertyCommand(commands);
    // THEN
    PropertyRecord before = propertyCommand.getBefore();
    assertFalse(before.inUse());
    assertFalse(before.iterator().hasNext());
    PropertyRecord after = propertyCommand.getAfter();
    assertTrue(after.inUse());
    assertEquals(1, count(after));
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) NeoStores(org.neo4j.kernel.impl.store.NeoStores) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) PropertyCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyCommand) Test(org.junit.Test)

Example 2 with PropertyCommand

use of org.neo4j.kernel.impl.transaction.command.Command.PropertyCommand in project neo4j by neo4j.

the class PhysicalLogCommandReaderV2_1Test method shouldReadPropertyCommandWithDeletedDynamicRecords.

@Test
public void shouldReadPropertyCommandWithDeletedDynamicRecords() throws Exception {
    // GIVEN
    PhysicalLogCommandReaderV2_1 reader = new PhysicalLogCommandReaderV2_1();
    InMemoryClosableChannel data = new InMemoryClosableChannel();
    long id = 5;
    int keyId = 6;
    byte[] data1 = new byte[] { 1, 2, 3, 4, 5 };
    byte[] data2 = new byte[] { 6, 7, 8, 9, 10 };
    long value = 1234;
    PropertyRecord property = new PropertyRecord(id);
    property.setInUse(true);
    property.addPropertyBlock(propertyBlockWithSomeDynamicRecords(keyId, STRING, value, data1, data2));
    property.addDeletedRecord(dynamicRecord(false, null, STRING.intValue()));
    property.addDeletedRecord(dynamicRecord(false, null, STRING.intValue()));
    // WHEN
    new PropertyCommand(new PropertyRecord(id), property).serialize(data);
    // THEN
    PropertyCommand readCommand = (PropertyCommand) reader.read(data);
    PropertyRecord readRecord = readCommand.getAfter();
    assertEquals(id, readRecord.getId());
    PropertyBlock readBlock = Iterables.single((Iterable<PropertyBlock>) readRecord);
    assertArrayEquals(data1, readBlock.getValueRecords().get(0).getData());
    assertArrayEquals(data2, readBlock.getValueRecords().get(1).getData());
    assertEquals(2, readRecord.getDeletedRecords().size());
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) PropertyCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyCommand) Test(org.junit.Test)

Example 3 with PropertyCommand

use of org.neo4j.kernel.impl.transaction.command.Command.PropertyCommand in project neo4j by neo4j.

the class Commands method createProperty.

public static PropertyCommand createProperty(long id, PropertyType type, int key, long... valueRecordIds) {
    PropertyRecord record = new PropertyRecord(id);
    record.setInUse(true);
    record.setCreated();
    PropertyBlock block = new PropertyBlock();
    if (valueRecordIds.length == 0) {
        PropertyStore.encodeValue(block, key, 123, /*value*/
        null, null);
    } else {
        PropertyStore.setSingleBlockValue(block, key, type, valueRecordIds[0]);
        block.setValueRecords(dynamicRecords(valueRecordIds));
    }
    record.addPropertyBlock(block);
    return new PropertyCommand(new PropertyRecord(id), record);
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) PropertyCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyCommand)

Example 4 with PropertyCommand

use of org.neo4j.kernel.impl.transaction.command.Command.PropertyCommand in project neo4j by neo4j.

the class TransactionRecordStateTest method shouldWriteProperPropertyRecordsWhenOnlyChangingLinkage.

@Test
public void shouldWriteProperPropertyRecordsWhenOnlyChangingLinkage() throws Exception {
    /* There was an issue where GIVEN:
         *
         *   Legend: () = node, [] = property record
         *
         *   ()-->[0:block{size:1}]
         *
         * WHEN adding a new property record in front of if, not changing any data in that record i.e:
         *
         *   ()-->[1:block{size:4}]-->[0:block{size:1}]
         *
         * The state of property record 0 would be that it had loaded value records for that block,
         * but those value records weren't heavy, so writing that record to the log would fail
         * w/ an assertion data != null.
         */
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    int nodeId = 0;
    recordState.nodeCreate(nodeId);
    int index = 0;
    // will require a block of size 1
    recordState.nodeAddProperty(nodeId, index, string(70));
    apply(neoStores, recordState);
    // WHEN
    recordState = newTransactionRecordState(neoStores);
    int index2 = 1;
    // will require a block of size 4
    recordState.nodeAddProperty(nodeId, index2, string(40));
    // THEN
    PhysicalTransactionRepresentation representation = transactionRepresentationOf(recordState);
    representation.accept(command -> ((Command) command).handle(new CommandVisitor.Adapter() {

        @Override
        public boolean visitPropertyCommand(PropertyCommand command) throws IOException {
            verifyPropertyRecord(command.getBefore());
            verifyPropertyRecord(command.getAfter());
            return false;
        }

        private void verifyPropertyRecord(PropertyRecord record) {
            if (record.getPrevProp() != Record.NO_NEXT_PROPERTY.intValue()) {
                for (PropertyBlock block : record) {
                    assertTrue(block.isLight());
                }
            }
        }
    }));
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) NeoStores(org.neo4j.kernel.impl.store.NeoStores) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) PropertyCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyCommand) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.Test)

Aggregations

PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)4 PropertyCommand (org.neo4j.kernel.impl.transaction.command.Command.PropertyCommand)4 Test (org.junit.Test)3 PropertyBlock (org.neo4j.kernel.impl.store.record.PropertyBlock)3 NeoStores (org.neo4j.kernel.impl.store.NeoStores)2 ArrayList (java.util.ArrayList)1 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)1 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)1 StorageCommand (org.neo4j.storageengine.api.StorageCommand)1