use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class GenerateIndexUpdatesStepTest method shouldGenerateEntityPropertyUpdatesForRelevantEntityTokens.
@Test
void shouldGenerateEntityPropertyUpdatesForRelevantEntityTokens() throws Exception {
// given
StubStorageCursors data = new StubStorageCursors();
int numNodes = 10;
MutableLongSet relevantNodeIds = LongSets.mutable.empty();
for (int i = 0; i < numNodes; i++) {
int labelId = i % 2 == 0 ? LABEL : OTHER_LABEL;
data.withNode(i).labels(labelId).properties(KEY, stringValue("name_" + i));
if (labelId == LABEL) {
relevantNodeIds.add(i);
}
}
TestPropertyScanConsumer scanConsumer = new TestPropertyScanConsumer();
GenerateIndexUpdatesStep<StorageNodeCursor> step = new GenerateIndexUpdatesStep<>(new SimpleStageControl(), DEFAULT, data, alwaysTrue(), new NodeCursorBehaviour(data), new int[] { LABEL }, scanConsumer, null, NO_LOCKING, 1, mebiBytes(1), false, PageCacheTracer.NULL, INSTANCE);
// when
CapturingBatchSender<GeneratedIndexUpdates> sender = new CapturingBatchSender<>();
step.process(allNodeIds(data), sender, NULL);
// then
GeneratedIndexUpdates updates = sender.batches.get(0);
updates.completeBatch();
for (TestPropertyScanConsumer.Record update : scanConsumer.batches.get(0)) {
assertThat(relevantNodeIds.remove(update.getEntityId())).isTrue();
}
assertThat(relevantNodeIds.isEmpty()).isTrue();
}
use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class GBPTreeGenericCountsStore method readTxIdInformation.
private TxIdInformation readTxIdInformation(long highestGapFreeTxId, CursorContext cursorContext) throws IOException {
MutableLongSet strayTxIds = new LongHashSet();
visitStrayTxIdsInTree(strayTxIds::add, cursorContext);
return new TxIdInformation(highestGapFreeTxId, strayTxIds);
}
use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldCreateEqualEntityPropertyUpdatesOnRecoveryOfCreatedEntities.
@Test
void shouldCreateEqualEntityPropertyUpdatesOnRecoveryOfCreatedEntities() throws Exception {
neoStores = createStores();
/* There was an issue where recovering a tx where a node with a label and a property
* was created resulted in two exact copies of NodePropertyUpdates. */
// GIVEN
long nodeId = 0;
long relId = 1;
int labelId = 5;
int relTypeId = 4;
int propertyKeyId = 7;
// -- indexes
long nodeRuleId = 0;
TransactionRecordState recordState = newTransactionRecordState();
SchemaRule nodeRule = IndexPrototype.forSchema(forLabel(labelId, propertyKeyId)).withName("index_" + nodeRuleId).materialise(nodeRuleId);
recordState.schemaRuleCreate(nodeRuleId, false, nodeRule);
long relRuleId = 1;
SchemaRule relRule = IndexPrototype.forSchema(forRelType(relTypeId, propertyKeyId)).withName("index_" + relRuleId).materialise(relRuleId);
recordState.schemaRuleCreate(relRuleId, false, relRule);
apply(recordState);
// -- and a tx creating a node and a rel for those indexes
recordState = newTransactionRecordState();
recordState.nodeCreate(nodeId);
recordState.addLabelToNode(labelId, nodeId);
recordState.nodeAddProperty(nodeId, propertyKeyId, Values.of("Neo"));
recordState.relModify(singleCreate(relId, relTypeId, nodeId, nodeId));
recordState.relAddProperty(relId, propertyKeyId, Values.of("Oen"));
// WHEN
CommandsToApply transaction = transaction(recordState);
IndexUpdatesExtractor extractor = new IndexUpdatesExtractor();
transaction.accept(extractor);
// THEN
// -- later recovering that tx, there should be only one update for each type
assertTrue(extractor.containsAnyEntityOrPropertyUpdate());
MutableLongSet recoveredNodeIds = new LongHashSet();
recoveredNodeIds.addAll(entityIds(extractor.getNodeCommands()));
assertEquals(1, recoveredNodeIds.size());
assertEquals(nodeId, recoveredNodeIds.longIterator().next());
MutableLongSet recoveredRelIds = new LongHashSet();
recoveredRelIds.addAll(entityIds(extractor.getRelationshipCommands()));
assertEquals(1, recoveredRelIds.size());
assertEquals(relId, recoveredRelIds.longIterator().next());
}
use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class RelationshipLockHelperTest method avoidTakingDuplicateLocks.
@Test
void avoidTakingDuplicateLocks() {
MutableLongObjectMap<RecordAccess.RecordProxy<RelationshipRecord, Void>> proxies = LongObjectMaps.mutable.empty();
MutableLongSet idsToDelete = LongSets.mutable.empty();
MutableLongBag expectedLocks = LongBags.mutable.empty();
idsToDelete.add(1);
RelationshipRecord record = new RelationshipRecord(1);
record.initialize(true, 1, 2, 3, 4, 5, 7, 7, 5, false, false);
var proxy = mock(RecordAccess.RecordProxy.class);
when(proxy.forReadingLinkage()).thenAnswer(invocation -> record);
proxies.put(1, proxy);
RecordAccess<RelationshipRecord, Void> relRecords = mock(RecordAccess.class);
when(relRecords.getOrLoad(Mockito.anyLong(), Mockito.any(), Mockito.any())).thenAnswer(invocation -> proxies.get(invocation.getArgument(0)));
TrackingResourceLocker locks = new TrackingResourceLocker(random, NO_MONITOR).withStrictAssertionsOn(ResourceTypes.RELATIONSHIP);
RelationshipLockHelper.lockRelationshipsInOrder(idsAsBatch(idsToDelete), 2, relRecords, locks, CursorContext.NULL, EmptyMemoryTracker.INSTANCE);
List<ActiveLock> activeLocks = locks.activeLocks().collect(Collectors.toList());
assertThat(activeLocks).hasSize(4).contains(new ActiveLock(ResourceTypes.RELATIONSHIP, LockType.EXCLUSIVE, -1, 1)).contains(new ActiveLock(ResourceTypes.RELATIONSHIP, LockType.EXCLUSIVE, -1, 2)).contains(new ActiveLock(ResourceTypes.RELATIONSHIP, LockType.EXCLUSIVE, -1, 5)).contains(new ActiveLock(ResourceTypes.RELATIONSHIP, LockType.EXCLUSIVE, -1, 7));
}
use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class RelationshipLockHelperTest method shouldTakeAllRelevantLocksForDeletion.
@ParameterizedTest
@ValueSource(ints = { 1, 10, 100, 1000 })
void shouldTakeAllRelevantLocksForDeletion(int numNodes) {
// Given
MutableLongObjectMap<RecordAccess.RecordProxy<RelationshipRecord, Void>> proxies = LongObjectMaps.mutable.empty();
MutableLongBag expectedLocks = LongBags.mutable.empty();
MutableLongSet idsToDelete = LongSets.mutable.empty();
int maxId = numNodes * 10;
for (int i = 0; i < numNodes; i++) {
long id = random.nextInt(maxId);
if (idsToDelete.add(id)) {
VolatileRelationshipRecord record = new VolatileRelationshipRecord(id, expectedLocks, maxId);
var proxy = mock(RecordAccess.RecordProxy.class);
when(proxy.forReadingLinkage()).thenAnswer(invocation -> new RelationshipRecord(record.maybeChange()));
proxies.put(id, proxy);
}
}
RecordAccess<RelationshipRecord, Void> relRecords = mock(RecordAccess.class);
when(relRecords.getOrLoad(Mockito.anyLong(), Mockito.any(), Mockito.any())).thenAnswer(invocation -> proxies.get(invocation.getArgument(0)));
TrackingResourceLocker locks = new TrackingResourceLocker(random, NO_MONITOR).withStrictAssertionsOn(ResourceTypes.RELATIONSHIP);
// When
RelationshipLockHelper.lockRelationshipsInOrder(idsAsBatch(idsToDelete), NULL_REFERENCE.longValue(), relRecords, locks, CursorContext.NULL, EmptyMemoryTracker.INSTANCE);
// Then
assertThat(locks.getExclusiveLocks(ResourceTypes.RELATIONSHIP).toSortedArray()).containsExactly(expectedLocks.toSet().toSortedArray());
}
Aggregations