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