Search in sources :

Example 1 with PropertyCommand

use of org.neo4j.internal.recordstorage.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, Values.of(123), null, null, true, NULL, INSTANCE);
    } 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.internal.recordstorage.Command.PropertyCommand)

Example 2 with PropertyCommand

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

the class EntityCommandGrouperTest method shouldSeeSingleGroupOfPropertiesWithoutEntity.

@ParameterizedTest
@EnumSource(Factory.class)
void shouldSeeSingleGroupOfPropertiesWithoutEntity(Factory factory) {
    // given
    EntityCommandGrouper grouper = new EntityCommandGrouper<>(factory.command(0).getClass(), 8);
    long entityId = 1;
    BaseCommand<? extends PrimitiveRecord> entity = factory.command(entityId);
    PropertyCommand property1 = property(entity.getAfter());
    PropertyCommand property2 = property(entity.getAfter());
    // intentionally DO NOT add the entity command
    grouper.add(property1);
    grouper.add(property2);
    EntityCommandGrouper.Cursor cursor = grouper.sortAndAccessGroups();
    // when/then
    assertGroups(cursor, group(entityId, null, property1, property2));
}
Also used : PropertyCommand(org.neo4j.internal.recordstorage.Command.PropertyCommand) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with PropertyCommand

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

the class EntityCommandGrouperTest method shouldSeeMultipleGroupsSomeOfThemWithEntity.

@ParameterizedTest
@EnumSource(Factory.class)
void shouldSeeMultipleGroupsSomeOfThemWithEntity(Factory factory) {
    // given
    EntityCommandGrouper grouper = new EntityCommandGrouper<>(factory.command(0).getClass(), 64);
    Group[] groups = new Group[random.nextInt(10, 30)];
    for (int entityId = 0; entityId < groups.length; entityId++) {
        BaseCommand entityCommand = random.nextBoolean() ? factory.command(entityId) : null;
        groups[entityId] = new Group(entityId, entityCommand);
        if (entityCommand != null) {
            // <-- storage transaction logs are sorted such that entity commands comes before property commands
            grouper.add(entityCommand);
        }
    }
    int totalNumberOfProperties = random.nextInt(10, 100);
    for (int i = 0; i < totalNumberOfProperties; i++) {
        int entityId = random.nextInt(groups.length);
        PropertyCommand property = property(factory.command(entityId).getAfter());
        groups[entityId].addProperty(property);
        grouper.add(property);
    }
    // ^^^ OK so we've generated property commands for random entities in random order, let's sort them
    EntityCommandGrouper.Cursor cursor = grouper.sortAndAccessGroups();
    // then
    assertGroups(cursor, groups);
}
Also used : BaseCommand(org.neo4j.internal.recordstorage.Command.BaseCommand) PropertyCommand(org.neo4j.internal.recordstorage.Command.PropertyCommand) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with PropertyCommand

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

the class EntityCommandGrouperTest method shouldSeeSingleGroupOfPropertiesWithEntity.

@ParameterizedTest
@EnumSource(Factory.class)
void shouldSeeSingleGroupOfPropertiesWithEntity(Factory factory) {
    // given
    EntityCommandGrouper grouper = new EntityCommandGrouper<>(factory.command(0).getClass(), 8);
    long entityId = 1;
    BaseCommand<? extends PrimitiveRecord> entity = factory.command(entityId);
    PropertyCommand property1 = property(entity.getAfter());
    PropertyCommand property2 = property(entity.getAfter());
    grouper.add(property1);
    grouper.add(property2);
    // <-- deliberately out-of-place
    grouper.add(entity);
    EntityCommandGrouper.Cursor cursor = grouper.sortAndAccessGroups();
    // when/then
    assertGroups(cursor, group(entityId, entity, property1, property2));
}
Also used : PropertyCommand(org.neo4j.internal.recordstorage.Command.PropertyCommand) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with PropertyCommand

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

the class TransactionRecordStateTest method settingIndexOwnerMustAlsoUpdateIndexRuleEvenIfIndexOwnerPropertyFitsInExistingPropertyChain.

/**
 * This is important because we have transaction appliers that look for the schema record changes and inspect the attached schema rule.
 * These appliers will not know what to do with the modified property record. Specifically, the index activator needs to observe the schema record
 * update when an index owner is attached to it.
 */
@Test
void settingIndexOwnerMustAlsoUpdateIndexRuleEvenIfIndexOwnerPropertyFitsInExistingPropertyChain() throws Exception {
    neoStores = createStores();
    TransactionRecordState state = newTransactionRecordState();
    long ruleId = neoStores.getSchemaStore().nextId(NULL);
    IndexDescriptor rule = IndexPrototype.uniqueForSchema(forLabel(0, 1)).withName("constraint_" + ruleId).materialise(ruleId);
    state.schemaRuleCreate(ruleId, false, rule);
    state.schemaRuleSetProperty(ruleId, 42, Values.booleanValue(true), rule);
    apply(state);
    state = newTransactionRecordState();
    state.schemaRuleSetIndexOwner(rule, 13, 56, 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(true);
    assertThat(propCmd.getAfter().inUse()).isEqualTo(true);
    assertThat(propCmd.getAfter().isCreated()).isEqualTo(false);
    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(propCmd.getKey());
    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)

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