use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.
the class StartOldDbOnCurrentVersionAndCreateFusionIndexIT method countIndexedNodes.
private static int countIndexedNodes(GraphDatabaseAPI db, Label label, String... keys) throws Exception {
try (InternalTransaction tx = (InternalTransaction) db.beginTx()) {
KernelTransaction ktx = tx.kernelTransaction();
TokenRead tokenRead = ktx.tokenRead();
int labelId = tokenRead.nodeLabel(label.name());
int[] propertyKeyIds = new int[keys.length];
for (int i = 0; i < propertyKeyIds.length; i++) {
propertyKeyIds[i] = tokenRead.propertyKey(keys[i]);
}
PropertyIndexQuery[] predicates = new PropertyIndexQuery[propertyKeyIds.length];
for (int i = 0; i < propertyKeyIds.length; i++) {
predicates[i] = PropertyIndexQuery.exists(propertyKeyIds[i]);
}
IndexDescriptor index = single(ktx.schemaRead().index(SchemaDescriptor.forLabel(labelId, propertyKeyIds)));
IndexReadSession indexSession = ktx.dataRead().indexReadSession(index);
int count = 0;
try (NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
ktx.dataRead().nodeIndexSeek(indexSession, cursor, unconstrained(), predicates);
while (cursor.next()) {
count++;
}
}
tx.commit();
return count;
}
}
use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.
the class LockingNodeUniqueIndexSeekTest method shouldHoldSharedIndexLockIfNodeIsExists.
@Test
void shouldHoldSharedIndexLockIfNodeIsExists() throws Exception {
// given
NodeValueIndexCursor cursor = mock(NodeValueIndexCursor.class);
when(cursor.next()).thenReturn(true);
when(cursor.nodeReference()).thenReturn(42L);
// when
long nodeId = LockingNodeUniqueIndexSeek.apply(locks, LockTracer.NONE, cursor, uniqueNodeIndexSeeker, read, index, predicate);
// then
assertEquals(42L, nodeId);
verify(locks).acquireShared(LockTracer.NONE, INDEX_ENTRY, resourceId);
verifyNoMoreInteractions(locks);
}
use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.
the class LockingNodeUniqueIndexSeekTest method shouldHoldSharedIndexLockIfNodeIsConcurrentlyCreated.
@Test
void shouldHoldSharedIndexLockIfNodeIsConcurrentlyCreated() throws Exception {
// given
NodeValueIndexCursor cursor = mock(NodeValueIndexCursor.class);
when(cursor.next()).thenReturn(false, true);
when(cursor.nodeReference()).thenReturn(42L);
// when
long nodeId = LockingNodeUniqueIndexSeek.apply(locks, LockTracer.NONE, cursor, uniqueNodeIndexSeeker, read, index, predicate);
// then
assertEquals(42L, nodeId);
order.verify(locks).acquireShared(LockTracer.NONE, INDEX_ENTRY, resourceId);
order.verify(locks).releaseShared(INDEX_ENTRY, resourceId);
order.verify(locks).acquireExclusive(LockTracer.NONE, INDEX_ENTRY, resourceId);
order.verify(locks).acquireShared(LockTracer.NONE, INDEX_ENTRY, resourceId);
order.verify(locks).releaseExclusive(INDEX_ENTRY, resourceId);
verifyNoMoreInteractions(locks);
}
use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.
the class LockingNodeUniqueIndexSeekTest method shouldHoldExclusiveIndexLockIfNodeDoesNotExist.
@Test
void shouldHoldExclusiveIndexLockIfNodeDoesNotExist() throws Exception {
// given
NodeValueIndexCursor cursor = mock(NodeValueIndexCursor.class);
when(cursor.next()).thenReturn(false, false);
when(cursor.nodeReference()).thenReturn(-1L);
// when
long nodeId = LockingNodeUniqueIndexSeek.apply(locks, LockTracer.NONE, cursor, uniqueNodeIndexSeeker, read, index, predicate);
// then
assertEquals(-1L, nodeId);
order.verify(locks).acquireShared(LockTracer.NONE, INDEX_ENTRY, resourceId);
order.verify(locks).releaseShared(INDEX_ENTRY, resourceId);
order.verify(locks).acquireExclusive(LockTracer.NONE, INDEX_ENTRY, resourceId);
verifyNoMoreInteractions(locks);
}
use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.
the class CompositeStringLengthValidationIT method shouldHandleCompositeSizesCloseToTheLimit.
@Test
void shouldHandleCompositeSizesCloseToTheLimit() throws KernelException {
String firstSlot = random.nextAlphaNumericString(firstSlotLength, firstSlotLength);
String secondSlot = random.nextAlphaNumericString(secondSlotLength, secondSlotLength);
// given
IndexDescriptor index = createIndex(KEY, KEY2);
Node node;
try (Transaction tx = db.beginTx()) {
node = tx.createNode(LABEL);
node.setProperty(KEY, firstSlot);
node.setProperty(KEY2, secondSlot);
tx.commit();
}
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
int propertyKeyId1 = ktx.tokenRead().propertyKey(KEY);
int propertyKeyId2 = ktx.tokenRead().propertyKey(KEY2);
try (NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
IndexReadSession indexReadSession = ktx.dataRead().indexReadSession(index);
ktx.dataRead().nodeIndexSeek(indexReadSession, cursor, unconstrained(), PropertyIndexQuery.exact(propertyKeyId1, firstSlot), PropertyIndexQuery.exact(propertyKeyId2, secondSlot));
assertTrue(cursor.next());
assertEquals(node.getId(), cursor.nodeReference());
assertFalse(cursor.next());
}
tx.commit();
}
}
Aggregations