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);
}
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));
}
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);
}
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));
}
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());
}
Aggregations