Search in sources :

Example 6 with PropertyCommand

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

the class TransactionRecordStateTest method settingIndexOwnerMustAlsoUpdateIndexRule.

@Test
void settingIndexOwnerMustAlsoUpdateIndexRule() throws Exception {
    neoStores = createStores();
    TransactionRecordState state = newTransactionRecordState();
    long ruleId = neoStores.getSchemaStore().nextId(NULL);
    IndexDescriptor rule = IndexPrototype.uniqueForSchema(forLabel(0, 1)).withName("index_" + ruleId).materialise(ruleId);
    state.schemaRuleCreate(ruleId, false, rule);
    apply(state);
    state = newTransactionRecordState();
    state.schemaRuleSetIndexOwner(rule, 13, 42, Values.longValue(13));
    List<StorageCommand> commands = new ArrayList<>();
    state.extractCommands(commands, INSTANCE);
    assertThat(commands.size()).isEqualTo(2);
    // Order matters. Props added before schema.
    PropertyCommand propCmd = (PropertyCommand) commands.get(0);
    assertThat(propCmd.getSchemaRuleId()).isEqualTo(ruleId);
    assertThat(propCmd.getBefore().inUse()).isEqualTo(false);
    assertThat(propCmd.getAfter().inUse()).isEqualTo(true);
    assertThat(propCmd.getAfter().isCreated()).isEqualTo(true);
    assertThat(propCmd.getAfter().getSchemaRuleId()).isEqualTo(ruleId);
    SchemaRuleCommand schemaCmd = (SchemaRuleCommand) commands.get(1);
    assertThat(schemaCmd.getSchemaRule()).isEqualTo(rule);
    assertThat(schemaCmd.getBefore().inUse()).isEqualTo(true);
    assertThat(schemaCmd.getBefore().getNextProp()).isEqualTo(Record.NO_NEXT_PROPERTY.longValue());
    assertThat(schemaCmd.getAfter().inUse()).isEqualTo(true);
    assertThat(schemaCmd.getAfter().isCreated()).isEqualTo(false);
    assertThat(schemaCmd.getAfter().getNextProp()).isEqualTo(propCmd.getKey());
}
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 7 with PropertyCommand

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

the class OnlineIndexUpdatesTest method shouldContainFedRelationshipUpdate.

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

Example 8 with PropertyCommand

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

the class OnlineIndexUpdatesTest method shouldUpdateCorrectIndexes.

@Test
void shouldUpdateCorrectIndexes() {
    OnlineIndexUpdates onlineIndexUpdates = new OnlineIndexUpdates(nodeStore, schemaCache, propertyPhysicalToLogicalConverter, new RecordStorageReader(neoStores), CursorContext.NULL, INSTANCE);
    long relId = 0;
    RelationshipRecord inUse = getRelationship(relId, true, ENTITY_TOKEN);
    Value propertyValue = Values.of("hej");
    Value propertyValue2 = Values.of("da");
    long propertyId = createRelationshipProperty(inUse, propertyValue, 1);
    long propertyId2 = createRelationshipProperty(inUse, propertyValue2, 4);
    RelationshipRecord notInUse = getRelationship(relId, false, ENTITY_TOKEN);
    relationshipStore.updateRecord(inUse, CursorContext.NULL);
    Command.RelationshipCommand relationshipCommand = new Command.RelationshipCommand(inUse, notInUse);
    PropertyRecord propertyBlocks = new PropertyRecord(propertyId);
    propertyBlocks.setRelId(relId);
    PropertyCommand propertyCommand = new PropertyCommand(recordAccess.getIfLoaded(propertyId).forReadingData(), propertyBlocks);
    PropertyRecord propertyBlocks2 = new PropertyRecord(propertyId2);
    propertyBlocks2.setRelId(relId);
    PropertyCommand propertyCommand2 = new PropertyCommand(recordAccess.getIfLoaded(propertyId2).forReadingData(), propertyBlocks2);
    IndexDescriptor indexDescriptor0 = IndexPrototype.forSchema(fulltext(RELATIONSHIP, ENTITY_TOKENS, new int[] { 1, 4, 6 })).withName("index_0").materialise(0);
    IndexDescriptor indexDescriptor1 = IndexPrototype.forSchema(fulltext(RELATIONSHIP, ENTITY_TOKENS, new int[] { 2, 4, 6 })).withName("index_1").materialise(1);
    IndexDescriptor indexDescriptor = IndexPrototype.forSchema(fulltext(RELATIONSHIP, new int[] { ENTITY_TOKEN, OTHER_ENTITY_TOKEN }, new int[] { 1 })).withName("index_2").materialise(2);
    createIndexes(indexDescriptor0, indexDescriptor1, indexDescriptor);
    onlineIndexUpdates.feed(nodeGroup(null), relationshipGroup(relationshipCommand, propertyCommand, propertyCommand2), -1);
    assertTrue(onlineIndexUpdates.hasUpdates());
    assertThat(onlineIndexUpdates).contains(IndexEntryUpdate.remove(relId, indexDescriptor0, propertyValue, propertyValue2, null), IndexEntryUpdate.remove(relId, indexDescriptor1, null, propertyValue2, null), IndexEntryUpdate.remove(relId, indexDescriptor, propertyValue));
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) NodeCommand(org.neo4j.internal.recordstorage.Command.NodeCommand) PropertyCommand(org.neo4j.internal.recordstorage.Command.PropertyCommand) Value(org.neo4j.values.storable.Value) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) PropertyCommand(org.neo4j.internal.recordstorage.Command.PropertyCommand) Test(org.junit.jupiter.api.Test)

Example 9 with PropertyCommand

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

the class OnlineIndexUpdatesTest method shouldDifferentiateNodesAndRelationships.

@Test
void shouldDifferentiateNodesAndRelationships() {
    OnlineIndexUpdates onlineIndexUpdates = new OnlineIndexUpdates(nodeStore, schemaCache, propertyPhysicalToLogicalConverter, new RecordStorageReader(neoStores), CursorContext.NULL, INSTANCE);
    int nodeId = 0;
    NodeRecord inUseNode = getNode(nodeId, true);
    Value nodePropertyValue = Values.of("hej");
    long nodePropertyId = createNodeProperty(inUseNode, nodePropertyValue, 1);
    NodeRecord notInUseNode = getNode(nodeId, false);
    nodeStore.updateRecord(inUseNode, CursorContext.NULL);
    NodeCommand nodeCommand = new NodeCommand(inUseNode, notInUseNode);
    PropertyRecord nodePropertyBlocks = new PropertyRecord(nodePropertyId);
    nodePropertyBlocks.setNodeId(nodeId);
    PropertyCommand nodePropertyCommand = new PropertyCommand(recordAccess.getIfLoaded(nodePropertyId).forReadingData(), nodePropertyBlocks);
    IndexDescriptor nodeIndexDescriptor = IndexPrototype.forSchema(fulltext(NODE, ENTITY_TOKENS, new int[] { 1, 4, 6 })).withName("index").materialise(0);
    createIndexes(nodeIndexDescriptor);
    long relId = 0;
    RelationshipRecord inUse = getRelationship(relId, true, ENTITY_TOKEN);
    Value relationshipPropertyValue = Values.of("da");
    long propertyId = createRelationshipProperty(inUse, relationshipPropertyValue, 1);
    RelationshipRecord notInUse = getRelationship(relId, false, ENTITY_TOKEN);
    relationshipStore.updateRecord(inUse, CursorContext.NULL);
    Command.RelationshipCommand relationshipCommand = new Command.RelationshipCommand(inUse, notInUse);
    PropertyRecord relationshipPropertyBlocks = new PropertyRecord(propertyId);
    relationshipPropertyBlocks.setRelId(relId);
    PropertyCommand relationshipPropertyCommand = new PropertyCommand(recordAccess.getIfLoaded(propertyId).forReadingData(), relationshipPropertyBlocks);
    FulltextSchemaDescriptor schema = fulltext(RELATIONSHIP, ENTITY_TOKENS, new int[] { 1, 4, 6 });
    IndexDescriptor relationshipIndexDescriptor = IndexPrototype.forSchema(schema).withName("index").materialise(1);
    createIndexes(relationshipIndexDescriptor);
    onlineIndexUpdates.feed(nodeGroup(nodeCommand, nodePropertyCommand), relationshipGroup(relationshipCommand, relationshipPropertyCommand), -1);
    assertTrue(onlineIndexUpdates.hasUpdates());
    assertThat(onlineIndexUpdates).contains(IndexEntryUpdate.remove(relId, relationshipIndexDescriptor, relationshipPropertyValue, null, null), IndexEntryUpdate.remove(nodeId, nodeIndexDescriptor, nodePropertyValue, null, null));
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) FulltextSchemaDescriptor(org.neo4j.internal.schema.FulltextSchemaDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) PropertyCommand(org.neo4j.internal.recordstorage.Command.PropertyCommand) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) NodeCommand(org.neo4j.internal.recordstorage.Command.NodeCommand) PropertyCommand(org.neo4j.internal.recordstorage.Command.PropertyCommand) Value(org.neo4j.values.storable.Value) NodeCommand(org.neo4j.internal.recordstorage.Command.NodeCommand) Test(org.junit.jupiter.api.Test)

Example 10 with PropertyCommand

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

the class EntityCommandGrouperTest method shouldWorkOnADifferentSetOfCommandsAfterClear.

@ParameterizedTest
@EnumSource(Factory.class)
void shouldWorkOnADifferentSetOfCommandsAfterClear(Factory factory) {
    // given
    EntityCommandGrouper grouper = new EntityCommandGrouper<>(factory.command(0).getClass(), 16);
    BaseCommand<? extends PrimitiveRecord> entity0 = factory.command(0);
    BaseCommand<? extends PrimitiveRecord> entity1 = factory.command(1);
    grouper.add(entity0);
    grouper.add(entity1);
    grouper.add(property(entity0.getAfter()));
    grouper.add(property(entity1.getAfter()));
    grouper.clear();
    // when
    BaseCommand<? extends PrimitiveRecord> entity2 = factory.command(2);
    PropertyCommand entityProperty = property(entity2.getAfter());
    BaseCommand<? extends PrimitiveRecord> entity3 = factory.command(3);
    grouper.add(entity2);
    grouper.add(entityProperty);
    grouper.add(entity3);
    // then
    assertGroups(grouper.sortAndAccessGroups(), group(entity2.getKey(), entity2, entityProperty), group(entity3.getKey(), entity3));
}
Also used : PropertyCommand(org.neo4j.internal.recordstorage.Command.PropertyCommand) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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