use of org.neo4j.internal.counts.CountsKey in project neo4j by neo4j.
the class CountsState method checker.
CountsChecker checker(ConsistencyReporter reporter) {
return new CountsChecker() {
final RelationshipCounter relationshipCounter = instantiateRelationshipCounter();
@Override
public void visitNodeCount(int labelId, long count) {
if (isValidLabelId(labelId)) {
long pos = labelIdArrayPos(labelId);
long expected = unmarkCountVisited(nodeCounts.get(pos));
if (expected != count) {
reporter.forCounts(new CountsEntry(nodeKey(labelId), count)).inconsistentNodeCount(expected);
}
nodeCounts.set(pos, markCountVisited(expected));
} else {
AtomicLong expected = nodeCountsStray.remove(nodeKey(labelId));
if (expected != null) {
if (expected.longValue() != count) {
reporter.forCounts(new CountsEntry(nodeKey(labelId), count)).inconsistentNodeCount(expected.longValue());
}
} else {
reporter.forCounts(new CountsEntry(nodeKey(labelId), count)).inconsistentNodeCount(0);
}
}
}
@Override
public void visitRelationshipCount(int startLabelId, int relTypeId, int endLabelId, long count) {
CountsKey countsKey = relationshipKey(startLabelId, relTypeId, endLabelId);
if (relationshipCounter.isValid(startLabelId, relTypeId, endLabelId)) {
long expected = unmarkCountVisited(relationshipCounter.get(startLabelId, relTypeId, endLabelId));
if (expected != count) {
reporter.forCounts(new CountsEntry(countsKey, count)).inconsistentRelationshipCount(expected);
}
relationshipCounter.set(startLabelId, relTypeId, endLabelId, markCountVisited(expected));
} else {
AtomicLong expected = relationshipCountsStray.remove(countsKey);
if (expected != null) {
if (expected.longValue() != count) {
reporter.forCounts(new CountsEntry(countsKey, count)).inconsistentRelationshipCount(expected.longValue());
}
} else {
reporter.forCounts(new CountsEntry(countsKey, count)).inconsistentRelationshipCount(0);
}
}
}
@Override
public void close() {
// Report counts that have been collected in this consistency check, but aren't in the existing store
for (int labelId = 0; labelId < highLabelId; labelId++) {
long count = nodeCounts.get(labelId);
if (!hasVisitedCountMark(count) && count > 0) {
reporter.forCounts(new CountsEntry(nodeKey(labelId), 0)).inconsistentNodeCount(count);
}
}
for (int start = ANY_LABEL; start < highLabelId; start++) {
for (int end = ANY_LABEL; end < highLabelId; end++) {
for (int type = ANY_RELATIONSHIP_TYPE; type < highRelationshipTypeId; type++) {
if (// we only keep counts for where at least one of start/end is ANY
start == ANY_LABEL || end == ANY_LABEL) {
long count = relationshipCounter.get(start, type, end);
if (!hasVisitedCountMark(count) && count > 0) {
reporter.forCounts(new CountsEntry(relationshipKey(start, type, end), 0)).inconsistentRelationshipCount(count);
}
}
}
}
}
nodeCountsStray.forEach((countsKey, count) -> reporter.forCounts(new CountsEntry(countsKey, count.get())));
relationshipCountsStray.forEach((countsKey, count) -> reporter.forCounts(new CountsEntry(countsKey, count.get())));
}
};
}
Aggregations