Search in sources :

Example 11 with PropertyCommand

use of org.neo4j.internal.recordstorage.Command.PropertyCommand in project neo4j by neo4j.

the class OnlineIndexUpdatesTest method shouldContainFedNodeUpdate.

@Test
void shouldContainFedNodeUpdate() {
    OnlineIndexUpdates onlineIndexUpdates = new OnlineIndexUpdates(nodeStore, schemaCache, propertyPhysicalToLogicalConverter, new RecordStorageReader(neoStores), CursorContext.NULL, INSTANCE);
    int nodeId = 0;
    NodeRecord inUse = getNode(nodeId, true);
    Value propertyValue = Values.of("hej");
    long propertyId = createNodeProperty(inUse, propertyValue, 1);
    NodeRecord notInUse = getNode(nodeId, false);
    nodeStore.updateRecord(inUse, CursorContext.NULL);
    NodeCommand nodeCommand = new NodeCommand(inUse, notInUse);
    PropertyRecord propertyBlocks = new PropertyRecord(propertyId);
    propertyBlocks.setNodeId(nodeId);
    PropertyCommand propertyCommand = new PropertyCommand(recordAccess.getIfLoaded(propertyId).forReadingData(), propertyBlocks);
    IndexDescriptor indexDescriptor = IndexPrototype.forSchema(fulltext(NODE, ENTITY_TOKENS, new int[] { 1, 4, 6 })).withName("index").materialise(0);
    createIndexes(indexDescriptor);
    onlineIndexUpdates.feed(nodeGroup(nodeCommand, propertyCommand), relationshipGroup(null), -1);
    assertTrue(onlineIndexUpdates.hasUpdates());
    Iterator<IndexEntryUpdate<IndexDescriptor>> iterator = onlineIndexUpdates.iterator();
    assertEquals(iterator.next(), IndexEntryUpdate.remove(nodeId, indexDescriptor, propertyValue, null, null));
    assertFalse(iterator.hasNext());
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) Value(org.neo4j.values.storable.Value) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) PropertyCommand(org.neo4j.internal.recordstorage.Command.PropertyCommand) NodeCommand(org.neo4j.internal.recordstorage.Command.NodeCommand) Test(org.junit.jupiter.api.Test)

Example 12 with PropertyCommand

use of org.neo4j.internal.recordstorage.Command.PropertyCommand in project neo4j by neo4j.

the class TransactionRecordStateTest method shouldWriteProperPropertyRecordsWhenOnlyChangingLinkage.

@Test
void shouldWriteProperPropertyRecordsWhenOnlyChangingLinkage() throws Exception {
    neoStores = createStores();
    /* 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
    TransactionRecordState recordState = newTransactionRecordState();
    int nodeId = 0;
    recordState.nodeCreate(nodeId);
    int index = 0;
    // will require a block of size 1
    recordState.nodeAddProperty(nodeId, index, string(70));
    apply(recordState);
    // WHEN
    recordState = newTransactionRecordState();
    int index2 = 1;
    // will require a block of size 4
    recordState.nodeAddProperty(nodeId, index2, string(40));
    // THEN
    CommandsToApply representation = transaction(recordState);
    representation.accept(command -> ((Command) command).handle(new CommandVisitor.Adapter() {

        @Override
        public boolean visitPropertyCommand(PropertyCommand command) {
            // THEN
            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 : CommandsToApply(org.neo4j.storageengine.api.CommandsToApply) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) PropertyCommand(org.neo4j.internal.recordstorage.Command.PropertyCommand) Test(org.junit.jupiter.api.Test)

Example 13 with PropertyCommand

use of org.neo4j.internal.recordstorage.Command.PropertyCommand in project neo4j by neo4j.

the class TransactionRecordStateTest method deletingSchemaRuleMustAlsoDeletePropertyChain.

@Test
void deletingSchemaRuleMustAlsoDeletePropertyChain() throws Exception {
    neoStores = createStores();
    TransactionRecordState state = newTransactionRecordState();
    long ruleId = neoStores.getSchemaStore().nextId(NULL);
    IndexDescriptor rule = IndexPrototype.forSchema(forLabel(0, 1)).withName("index_" + ruleId).materialise(ruleId);
    state.schemaRuleCreate(ruleId, false, rule);
    state.schemaRuleSetProperty(ruleId, 42, Values.booleanValue(true), rule);
    apply(state);
    state = newTransactionRecordState();
    state.schemaRuleDelete(ruleId, rule);
    List<StorageCommand> commands = new ArrayList<>();
    state.extractCommands(commands, INSTANCE);
    assertThat(commands.size()).isEqualTo(2);
    // Order matters. Rule deletes before property deletes.
    SchemaRuleCommand schemaCmd = (SchemaRuleCommand) commands.get(0);
    assertThat(schemaCmd.getKey()).isEqualTo(ruleId);
    assertThat(schemaCmd.getBefore().inUse()).isEqualTo(true);
    assertThat(schemaCmd.getAfter().inUse()).isEqualTo(false);
    PropertyCommand propCmd = (PropertyCommand) commands.get(1);
    assertThat(propCmd.getKey()).isEqualTo(schemaCmd.getBefore().getNextProp());
    assertThat(propCmd.getBefore().inUse()).isEqualTo(true);
    assertThat(propCmd.getAfter().inUse()).isEqualTo(false);
}
Also used : SchemaRuleCommand(org.neo4j.internal.recordstorage.Command.SchemaRuleCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) PropertyCommand(org.neo4j.internal.recordstorage.Command.PropertyCommand) Test(org.junit.jupiter.api.Test)

Example 14 with PropertyCommand

use of org.neo4j.internal.recordstorage.Command.PropertyCommand in project neo4j by neo4j.

the class TransactionRecordStateTest method entityIds.

private LongIterable entityIds(EntityCommandGrouper.Cursor cursor) {
    LongArrayList list = new LongArrayList();
    if (cursor.nextEntity()) {
        PropertyCommand propertyCommand;
        do {
            // Just get any potential property commands out of the way
            propertyCommand = cursor.nextProperty();
        } while (propertyCommand != null);
        list.add(cursor.currentEntityId());
    }
    return list;
}
Also used : LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) PropertyCommand(org.neo4j.internal.recordstorage.Command.PropertyCommand)

Example 15 with PropertyCommand

use of org.neo4j.internal.recordstorage.Command.PropertyCommand in project neo4j by neo4j.

the class TransactionRecordStateTest method shouldCreateProperBeforeAndAfterPropertyCommandsWhenAddingProperty.

@Test
void shouldCreateProperBeforeAndAfterPropertyCommandsWhenAddingProperty() throws Exception {
    neoStores = createStores();
    // GIVEN
    TransactionRecordState recordState = newTransactionRecordState();
    int nodeId = 1;
    recordState.nodeCreate(nodeId);
    // WHEN
    recordState.nodeAddProperty(nodeId, propertyId1, value1);
    Collection<StorageCommand> commands = new ArrayList<>();
    recordState.extractCommands(commands, INSTANCE);
    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) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) PropertyCommand(org.neo4j.internal.recordstorage.Command.PropertyCommand) Test(org.junit.jupiter.api.Test)

Aggregations

PropertyCommand (org.neo4j.internal.recordstorage.Command.PropertyCommand)16 Test (org.junit.jupiter.api.Test)10 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)8 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)7 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)6 ArrayList (java.util.ArrayList)5 StorageCommand (org.neo4j.storageengine.api.StorageCommand)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 NodeCommand (org.neo4j.internal.recordstorage.Command.NodeCommand)4 SchemaRuleCommand (org.neo4j.internal.recordstorage.Command.SchemaRuleCommand)4 Value (org.neo4j.values.storable.Value)4 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)3 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)2 PropertyBlock (org.neo4j.kernel.impl.store.record.PropertyBlock)2 IndexEntryUpdate (org.neo4j.storageengine.api.IndexEntryUpdate)2 BaseCommand (org.neo4j.internal.recordstorage.Command.BaseCommand)1 FulltextSchemaDescriptor (org.neo4j.internal.schema.FulltextSchemaDescriptor)1 CommandsToApply (org.neo4j.storageengine.api.CommandsToApply)1