use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldExtractDeleteCommandsInCorrectOrder.
@Test
public void shouldExtractDeleteCommandsInCorrectOrder() throws Exception {
// GIVEN
NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "1");
TransactionRecordState recordState = newTransactionRecordState(neoStores);
long nodeId1 = 0, nodeId2 = 1, relId1 = 1, relId2 = 2, relId4 = 10;
recordState.nodeCreate(nodeId1);
recordState.nodeCreate(nodeId2);
recordState.relCreate(relId1, 0, nodeId1, nodeId1);
recordState.relCreate(relId2, 0, nodeId1, nodeId1);
recordState.relCreate(relId4, 1, nodeId1, nodeId1);
recordState.nodeAddProperty(nodeId1, 0, 101);
BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
apply(applier, transaction(recordState));
recordState = newTransactionRecordState(neoStores);
recordState.relDelete(relId4);
recordState.nodeDelete(nodeId2);
recordState.nodeRemoveProperty(nodeId1, 0);
// WHEN
Collection<StorageCommand> commands = new ArrayList<>();
recordState.extractCommands(commands);
// THEN
Iterator<StorageCommand> commandIterator = commands.iterator();
// updated rel group to not point to the deleted one below
assertCommand(commandIterator.next(), Command.RelationshipGroupCommand.class);
// updated node to point to the group after the deleted one
assertCommand(commandIterator.next(), NodeCommand.class);
// rest is deletions below...
assertCommand(commandIterator.next(), PropertyCommand.class);
assertCommand(commandIterator.next(), RelationshipCommand.class);
assertCommand(commandIterator.next(), Command.RelationshipGroupCommand.class);
assertCommand(commandIterator.next(), NodeCommand.class);
assertFalse(commandIterator.hasNext());
}
use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldSortRelationshipGroups.
@Test
public void shouldSortRelationshipGroups() throws Throwable {
// GIVEN
int type5 = 5, type10 = 10, type15 = 15;
NeoStores neoStores = neoStoresRule.open(GraphDatabaseSettings.dense_node_threshold.name(), "1");
{
TransactionRecordState recordState = newTransactionRecordState(neoStores);
neoStores.getRelationshipTypeTokenStore().setHighId(16);
recordState.createRelationshipTypeToken("5", type5);
recordState.createRelationshipTypeToken("10", type10);
recordState.createRelationshipTypeToken("15", type15);
BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
apply(applier, transaction(recordState));
}
long nodeId = neoStores.getNodeStore().nextId();
{
long otherNode1Id = neoStores.getNodeStore().nextId();
long otherNode2Id = neoStores.getNodeStore().nextId();
TransactionRecordState recordState = newTransactionRecordState(neoStores);
recordState.nodeCreate(nodeId);
recordState.nodeCreate(otherNode1Id);
recordState.nodeCreate(otherNode2Id);
recordState.relCreate(neoStores.getRelationshipStore().nextId(), type10, nodeId, otherNode1Id);
// This relationship will cause the switch to dense
recordState.relCreate(neoStores.getRelationshipStore().nextId(), type10, nodeId, otherNode2Id);
BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
apply(applier, transaction(recordState));
// Just a little validation of assumptions
assertRelationshipGroupsInOrder(neoStores, nodeId, type10);
}
// WHEN inserting a relationship of type 5
{
TransactionRecordState recordState = newTransactionRecordState(neoStores);
long otherNodeId = neoStores.getNodeStore().nextId();
recordState.nodeCreate(otherNodeId);
recordState.relCreate(neoStores.getRelationshipStore().nextId(), type5, nodeId, otherNodeId);
BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
apply(applier, transaction(recordState));
// THEN that group should end up first in the chain
assertRelationshipGroupsInOrder(neoStores, nodeId, type5, type10);
}
// WHEN inserting a relationship of type 15
{
TransactionRecordState recordState = newTransactionRecordState(neoStores);
long otherNodeId = neoStores.getNodeStore().nextId();
recordState.nodeCreate(otherNodeId);
recordState.relCreate(neoStores.getRelationshipStore().nextId(), type15, nodeId, otherNodeId);
BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier(neoStores, mock(CacheAccessBackDoor.class), LockService.NO_LOCK_SERVICE);
apply(applier, transaction(recordState));
// THEN that group should end up last in the chain
assertRelationshipGroupsInOrder(neoStores, nodeId, type5, type10, type15);
}
}
use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class WriteTransactionCommandOrderingTest method injectAllPossibleCommands.
private TransactionRecordState injectAllPossibleCommands() {
RecordChangeSet recordChangeSet = mock(RecordChangeSet.class);
RecordChanges<Integer, LabelTokenRecord, Void> labelTokenChanges = mock(RecordChanges.class);
RecordChanges<Integer, RelationshipTypeTokenRecord, Void> relationshipTypeTokenChanges = mock(RecordChanges.class);
RecordChanges<Integer, PropertyKeyTokenRecord, Void> propertyKeyTokenChanges = mock(RecordChanges.class);
RecordChanges<Long, NodeRecord, Void> nodeRecordChanges = mock(RecordChanges.class);
RecordChanges<Long, RelationshipRecord, Void> relationshipRecordChanges = mock(RecordChanges.class);
RecordChanges<Long, PropertyRecord, PrimitiveRecord> propertyRecordChanges = mock(RecordChanges.class);
RecordChanges<Long, RelationshipGroupRecord, Integer> relationshipGroupChanges = mock(RecordChanges.class);
RecordChanges<Long, SchemaRecord, SchemaRule> schemaRuleChanges = mock(RecordChanges.class);
when(recordChangeSet.getLabelTokenChanges()).thenReturn(labelTokenChanges);
when(recordChangeSet.getRelationshipTypeTokenChanges()).thenReturn(relationshipTypeTokenChanges);
when(recordChangeSet.getPropertyKeyTokenChanges()).thenReturn(propertyKeyTokenChanges);
when(recordChangeSet.getNodeRecords()).thenReturn(nodeRecordChanges);
when(recordChangeSet.getRelRecords()).thenReturn(relationshipRecordChanges);
when(recordChangeSet.getPropertyRecords()).thenReturn(propertyRecordChanges);
when(recordChangeSet.getRelGroupRecords()).thenReturn(relationshipGroupChanges);
when(recordChangeSet.getSchemaRuleChanges()).thenReturn(schemaRuleChanges);
List<RecordProxy<Long, NodeRecord, Void>> nodeChanges = new LinkedList<>();
RecordChange<Long, NodeRecord, Void> deletedNode = mock(RecordChange.class);
when(deletedNode.getBefore()).thenReturn(inUseNode());
when(deletedNode.forReadingLinkage()).thenReturn(missingNode());
nodeChanges.add(deletedNode);
RecordChange<Long, NodeRecord, Void> createdNode = mock(RecordChange.class);
when(createdNode.getBefore()).thenReturn(missingNode());
when(createdNode.forReadingLinkage()).thenReturn(createdNode());
nodeChanges.add(createdNode);
RecordChange<Long, NodeRecord, Void> updatedNode = mock(RecordChange.class);
when(updatedNode.getBefore()).thenReturn(inUseNode());
when(updatedNode.forReadingLinkage()).thenReturn(inUseNode());
nodeChanges.add(updatedNode);
when(nodeRecordChanges.changes()).thenReturn(nodeChanges);
when(nodeRecordChanges.changeSize()).thenReturn(3);
when(recordChangeSet.changeSize()).thenReturn(3);
when(labelTokenChanges.changes()).thenReturn(Collections.<RecordProxy<Integer, LabelTokenRecord, Void>>emptyList());
when(relationshipTypeTokenChanges.changes()).thenReturn(Collections.<RecordProxy<Integer, RelationshipTypeTokenRecord, Void>>emptyList());
when(propertyKeyTokenChanges.changes()).thenReturn(Collections.<RecordProxy<Integer, PropertyKeyTokenRecord, Void>>emptyList());
when(relationshipRecordChanges.changes()).thenReturn(Collections.<RecordProxy<Long, RelationshipRecord, Void>>emptyList());
when(propertyRecordChanges.changes()).thenReturn(Collections.<RecordProxy<Long, PropertyRecord, PrimitiveRecord>>emptyList());
when(relationshipGroupChanges.changes()).thenReturn(Collections.<RecordProxy<Long, RelationshipGroupRecord, Integer>>emptyList());
when(schemaRuleChanges.changes()).thenReturn(Collections.<RecordProxy<Long, SchemaRecord, SchemaRule>>emptyList());
NeoStores neoStores = mock(NeoStores.class);
when(neoStores.getNodeStore()).thenReturn(mock(NodeStore.class));
when(neoStores.getRelationshipGroupStore()).thenReturn(mock(RelationshipGroupStore.class));
when(neoStores.getRelationshipStore()).thenReturn(mock(RelationshipStore.class));
return new TransactionRecordState(neoStores, mock(IntegrityValidator.class), recordChangeSet, 0, null, null, null, null, null);
}
use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class RelationshipCreatorTest method shouldOnlyChangeLockedRecordsWhenUpgradingToDenseNode.
@Test
public void shouldOnlyChangeLockedRecordsWhenUpgradingToDenseNode() throws Exception {
// GIVEN
long nodeId = createNodeWithRelationships(DENSE_NODE_THRESHOLD);
NeoStores neoStores = flipToNeoStores();
Tracker tracker = new Tracker(neoStores);
RelationshipGroupGetter groupGetter = new RelationshipGroupGetter(neoStores.getRelationshipGroupStore());
RelationshipCreator relationshipCreator = new RelationshipCreator(groupGetter, 5);
// WHEN
relationshipCreator.relationshipCreate(idGeneratorFactory.get(IdType.RELATIONSHIP).nextId(), 0, nodeId, nodeId, tracker, tracker);
// THEN
assertEquals(tracker.relationshipLocksAcquired.size(), tracker.changedRelationships.size());
assertFalse(tracker.relationshipLocksAcquired.isEmpty());
}
use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.
the class RelationshipGroupGetterTest method shouldAbortLoadingGroupChainIfComeTooFar.
@Test
public void shouldAbortLoadingGroupChainIfComeTooFar() throws Exception {
// GIVEN a node with relationship group chain 2-->4-->10-->23
File dir = new File("dir");
fs.get().mkdirs(dir);
LogProvider logProvider = NullLogProvider.getInstance();
StoreFactory storeFactory = new StoreFactory(dir, pageCache.getPageCache(fs.get()), fs.get(), logProvider);
try (NeoStores stores = storeFactory.openNeoStores(true, StoreType.RELATIONSHIP_GROUP)) {
RecordStore<RelationshipGroupRecord> store = spy(stores.getRelationshipGroupStore());
RelationshipGroupRecord group_2 = group(0, 2);
RelationshipGroupRecord group_4 = group(1, 4);
RelationshipGroupRecord group_10 = group(2, 10);
RelationshipGroupRecord group_23 = group(3, 23);
link(group_2, group_4, group_10, group_23);
store.updateRecord(group_2);
store.updateRecord(group_4);
store.updateRecord(group_10);
store.updateRecord(group_23);
RelationshipGroupGetter groupGetter = new RelationshipGroupGetter(store);
NodeRecord node = new NodeRecord(0, true, group_2.getId(), -1);
// WHEN trying to find relationship group 7
RecordAccess<Long, RelationshipGroupRecord, Integer> access = new DirectRecordAccess<>(store, Loaders.relationshipGroupLoader(store));
RelationshipGroupPosition result = groupGetter.getRelationshipGroup(node, 7, access);
// THEN only groups 2, 4 and 10 should have been loaded
InOrder verification = inOrder(store);
verification.verify(store).getRecord(eq(group_2.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
verification.verify(store).getRecord(eq(group_4.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
verification.verify(store).getRecord(eq(group_10.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
verification.verify(store, times(0)).getRecord(eq(group_23.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
// it should also be reported as not found
assertNull(result.group());
// with group 4 as closes previous one
assertEquals(group_4, result.closestPrevious().forReadingData());
}
}
Aggregations