use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class TxStateIndexChanges method indexUpdatesForRangeSeekByPrefix.
// PREFIX
static AddedAndRemoved indexUpdatesForRangeSeekByPrefix(ReadableTransactionState txState, IndexDescriptor descriptor, Value[] equalityPrefix, TextValue prefix, IndexOrder indexOrder) {
NavigableMap<ValueTuple, ? extends LongDiffSets> sortedUpdates = txState.getSortedIndexUpdates(descriptor.schema());
if (sortedUpdates == null) {
return EMPTY_ADDED_AND_REMOVED;
}
int size = descriptor.schema().getPropertyIds().length;
ValueTuple floor = getCompositeValueTuple(size, equalityPrefix, prefix, true);
ValueTuple maxString = getCompositeValueTuple(size, equalityPrefix, Values.MAX_STRING, false);
MutableLongList added = LongLists.mutable.empty();
MutableLongSet removed = LongSets.mutable.empty();
for (Map.Entry<ValueTuple, ? extends LongDiffSets> entry : sortedUpdates.subMap(floor, maxString).entrySet()) {
Value key = entry.getKey().valueAt(equalityPrefix.length);
// Needs to check type since the subMap might include non-TextValue for composite index
if (key.valueGroup() == ValueGroup.TEXT && ((TextValue) key).startsWith(prefix)) {
LongDiffSets diffSets = entry.getValue();
added.addAll(diffSets.getAdded());
removed.addAll(diffSets.getRemoved());
} else {
break;
}
}
return new AddedAndRemoved(indexOrder == IndexOrder.DESCENDING ? added.asReversed() : added, removed);
}
use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class PropertyDeleter method deletePropertyChain.
public void deletePropertyChain(PrimitiveRecord primitive, RecordAccess<PropertyRecord, PrimitiveRecord> propertyRecords) {
long nextProp = primitive.getNextProp();
MutableLongSet seenPropertyIds = null;
int count = 0;
try {
while (nextProp != Record.NO_NEXT_PROPERTY.longValue()) {
RecordProxy<PropertyRecord, PrimitiveRecord> propertyChange = propertyRecords.getOrLoad(nextProp, primitive, cursorContext);
PropertyRecord propRecord = propertyChange.forChangingData();
deletePropertyRecordIncludingValueRecords(propRecord);
if (++count >= CYCLE_DETECTION_THRESHOLD) {
if (seenPropertyIds == null) {
seenPropertyIds = LongSets.mutable.empty();
}
if (!seenPropertyIds.add(nextProp)) {
throw new InconsistentDataReadException("Cycle detected in property chain for %s", primitive);
}
}
nextProp = propRecord.getNextProp();
propRecord.setChanged(primitive);
}
} catch (InvalidRecordException e) {
// This property chain, or a dynamic value record chain contains a record which is not in use, so it's somewhat broken.
// Abort reading the chain, but don't fail the deletion of this property record chain.
logInconsistentPropertyChain(primitive, "unused record", e);
} catch (InconsistentDataReadException e) {
// This property chain, or a dynamic value record chain contains a cycle.
// Abort reading the chain, but don't fail the deletion of this property record chain.
logInconsistentPropertyChain(primitive, "cycle", e);
}
primitive.setNextProp(Record.NO_NEXT_PROPERTY.intValue());
}
use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class RecordLoading method safeGetNodeLabels.
static long[] safeGetNodeLabels(CheckerContext context, long nodeId, long labelField, RecordReader<DynamicRecord> labelReader, CursorContext cursorContext) {
if (!NodeLabelsField.fieldPointsToDynamicRecordOfLabels(labelField)) {
return InlineNodeLabels.parseInlined(labelField);
}
// The idea here is that we don't pass in a lot of cursors and stuff because dynamic labels are so rare?
List<DynamicRecord> records = new ArrayList<>();
MutableLongSet seenRecordIds = new LongHashSet();
ConsistencyReport.Reporter reporter = context.reporter;
RecordLoading recordLoader = context.recordLoader;
int nodeLabelBlockSize = context.neoStores.getNodeStore().getDynamicLabelStore().getRecordDataSize();
if (safeLoadDynamicRecordChain(record -> records.add(record.copy()), labelReader, seenRecordIds, NodeLabelsField.firstDynamicLabelRecordId(labelField), nodeLabelBlockSize, (id, labelRecord) -> reporter.forNode(recordLoader.node(nodeId, cursorContext)).dynamicRecordChainCycle(labelRecord), (id, labelRecord) -> reporter.forNode(recordLoader.node(nodeId, cursorContext)).dynamicLabelRecordNotInUse(labelRecord), (id, labelRecord) -> reporter.forNode(recordLoader.node(nodeId, cursorContext)).dynamicLabelRecordNotInUse(labelRecord), (id, labelRecord) -> reporter.forDynamicBlock(RecordType.NODE_DYNAMIC_LABEL, labelRecord).emptyBlock(), labelRecord -> reporter.forDynamicBlock(RecordType.NODE_DYNAMIC_LABEL, labelRecord).recordNotFullReferencesNext(), labelRecord -> reporter.forDynamicBlock(RecordType.NODE_DYNAMIC_LABEL, labelRecord).invalidLength())) {
return DynamicNodeLabels.getDynamicLabelsArray(records, labelReader.store(), cursorContext);
}
return null;
}
use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class RecordLoading method safeLoadTokens.
static <RECORD extends TokenRecord> List<NamedToken> safeLoadTokens(TokenStore<RECORD> tokenStore, CursorContext cursorContext) {
long highId = tokenStore.getHighId();
List<NamedToken> tokens = new ArrayList<>();
DynamicStringStore nameStore = tokenStore.getNameStore();
List<DynamicRecord> nameRecords = new ArrayList<>();
MutableLongSet seenRecordIds = new LongHashSet();
int nameBlockSize = nameStore.getRecordDataSize();
try (RecordReader<RECORD> tokenReader = new RecordReader<>(tokenStore, true, cursorContext);
RecordReader<DynamicRecord> nameReader = new RecordReader<>(nameStore, false, cursorContext)) {
for (long id = 0; id < highId; id++) {
RECORD record = tokenReader.read(id);
nameRecords.clear();
if (record.inUse()) {
String name;
if (!NULL_REFERENCE.is(record.getNameId()) && safeLoadDynamicRecordChain(r -> nameRecords.add(r.copy()), nameReader, seenRecordIds, record.getNameId(), nameBlockSize)) {
record.addNameRecords(nameRecords);
name = tokenStore.getStringFor(record, cursorContext);
} else {
name = format("<name not loaded due to token(%d) referencing unused name record>", id);
}
tokens.add(new NamedToken(name, toIntExact(id), record.isInternal()));
}
}
}
return tokens;
}
use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class BlockStorageTest method shouldNoticeCancelRequest.
@Test
void shouldNoticeCancelRequest() throws IOException, ExecutionException, InterruptedException {
// given
Barrier.Control barrier = new Barrier.Control();
TrackingMonitor monitor = new TrackingMonitor() {
@Override
public void mergedBlocks(long resultingBlockSize, long resultingEntryCount, long numberOfBlocks) {
super.mergedBlocks(resultingBlockSize, resultingEntryCount, numberOfBlocks);
barrier.reached();
}
};
int blocks = 10;
int mergeFactor = 2;
MutableLongSet uniqueKeys = new LongHashSet();
AtomicBoolean cancelled = new AtomicBoolean();
try (BlockStorage<MutableLong, MutableLong> storage = new BlockStorage<>(layout, heapBufferFactory(100), fileSystem, file, monitor, INSTANCE);
OtherThreadExecutor t2 = new OtherThreadExecutor("T2")) {
while (monitor.blockFlushedCallCount < blocks) {
storage.add(uniqueKey(uniqueKeys), new MutableLong());
}
storage.doneAdding();
// when starting to merge
Future<Object> merge = t2.executeDontWait(command(() -> storage.merge(mergeFactor, cancelled::get)));
barrier.awaitUninterruptibly();
// one merge iteration have now been done, set the cancellation flag
cancelled.set(true);
barrier.release();
merge.get();
}
// then there should not be any more merge iterations done, i.e. merge was cancelled
assertEquals(1, monitor.mergeIterationCallCount);
}
Aggregations