Skip to content

Commit

Permalink
Merge pull request #8324 from soerenreichardt/fix-long-int-token-compat
Browse files Browse the repository at this point in the history
Deal with long/int token compat issue
  • Loading branch information
soerenreichardt authored Nov 2, 2023
2 parents 54e63a9 + 01b0ee3 commit 5a0e175
Show file tree
Hide file tree
Showing 28 changed files with 293 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,14 @@ public boolean allowsReadNodeProperty(Supplier<TokenSet> labels, int propertyKey
public boolean allowsReadRelationshipProperty(RelTypeSupplier relType, int propertyKey) {
return custom.allowsReadRelationshipProperty(propertyKey);
}

@Override
public boolean allowsTraverseAllNodesWithLabel(long label) {
return custom.allowTraverseAllNodesWithLabel(label);
}

@Override
public boolean allowsTraverseNode(long... labels) {
return custom.allowsTraverseNode(labels);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ public void relationshipsTo(
public void degrees(RelationshipSelection selection, Degrees.Mutator mutator) {
}

@Override
public long[] labels() {
return longLabels();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.neo4j.internal.kernel.api.RelTypeSupplier;
import org.neo4j.internal.kernel.api.TokenSet;

import java.util.Arrays;
import java.util.function.Supplier;

public class CompatAccessModeImpl extends CompatAccessMode {
Expand All @@ -41,4 +42,20 @@ public boolean allowsReadNodeProperty(Supplier<TokenSet> labels, int propertyKey
public boolean allowsReadRelationshipProperty(RelTypeSupplier relType, int propertyKey) {
return custom.allowsReadRelationshipProperty(propertyKey);
}

public boolean allowsTraverseAllNodesWithLabel(long label) {
return custom.allowTraverseAllNodesWithLabel(label);
}

public boolean allowsTraverseNode(long... labels) {
return custom.allowsTraverseNode(labels);
}

public boolean allowsTraverseAllNodesWithLabel(int label) {
return custom.allowTraverseAllNodesWithLabel(label);
}

public boolean allowsTraverseNode(int... labels) {
return custom.allowsTraverseNode(Arrays.stream(labels).mapToLong(l -> l).toArray());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ public void degrees(RelationshipSelection selection, Degrees.Mutator mutator) {
public boolean scanBatch(AllNodeScan allNodeScan, long sizeHint) {
return super.scanBatch(allNodeScan, (int) sizeHint);
}

@Override
public long[] labels() {
return longLabels();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ public void degrees(RelationshipSelection selection, Degrees.Mutator mutator) {
public boolean scanBatch(AllNodeScan allNodeScan, long sizeHint) {
return super.scanBatch(allNodeScan, (int) sizeHint);
}

@Override
public long[] labels() {
return longLabels();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ public void degrees(RelationshipSelection selection, Degrees.Mutator mutator) {
public boolean scanBatch(AllNodeScan allNodeScan, long sizeHint) {
return super.scanBatch(allNodeScan, (int) sizeHint);
}

@Override
public long[] labels() {
return longLabels();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ public void degrees(RelationshipSelection selection, Degrees.Mutator mutator) {
public boolean scanBatch(AllNodeScan allNodeScan, long sizeHint) {
return super.scanBatch(allNodeScan, (int) sizeHint);
}

@Override
public long[] labels() {
return longLabels();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ public void degrees(RelationshipSelection selection, Degrees.Mutator mutator) {
public boolean scanBatch(AllNodeScan allNodeScan, long sizeHint) {
return super.scanBatch(allNodeScan, (int) sizeHint);
}

@Override
public long[] labels() {
return longLabels();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ public void degrees(RelationshipSelection selection, Degrees.Mutator mutator) {
public boolean scanBatch(AllNodeScan allNodeScan, long sizeHint) {
return super.scanBatch(allNodeScan, (int) sizeHint);
}

@Override
public long[] labels() {
return longLabels();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ public void degrees(RelationshipSelection selection, Degrees.Mutator mutator) {
public boolean scanBatch(AllNodeScan allNodeScan, long sizeHint) {
return super.scanBatch(allNodeScan, (int) sizeHint);
}

@Override
public long[] labels() {
return longLabels();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ public void degrees(RelationshipSelection selection, Degrees.Mutator mutator) {
public boolean scanBatch(AllNodeScan allNodeScan, long sizeHint) {
return super.scanBatch(allNodeScan, (int) sizeHint);
}

@Override
public long[] labels() {
return longLabels();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,6 @@ public boolean allowsTraverseAllLabels() {
return custom.allowsTraverseAllLabels();
}

@Override
public boolean allowsTraverseAllNodesWithLabel(long label) {
return custom.allowTraverseAllNodesWithLabel(label);
}

@Override
public boolean allowsTraverseNode(long... labels) {
return custom.allowsTraverseNode(labels);
}

@Override
public boolean allowsTraverseRelType(int relType) {
return custom.allowsTraverseRelType(relType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,46 @@ public abstract class AbstractInMemoryNodeCursor extends NodeRecord implements S
private final GraphStore graphStore;
private final TokenHolders tokenHolders;
private final boolean hasProperties;
private final long[] nodeLabelReadBuffer;
private final long[] longNodeLabelReadBuffer;
private final int[] intNodeLabelReadBuffer;
private final MutableInt nodeLabelCounter;

public AbstractInMemoryNodeCursor(GraphStore graphStore, TokenHolders tokenHolders) {
super(NO_ID);
this.graphStore = graphStore;
this.tokenHolders = tokenHolders;
this.hasProperties = !graphStore.nodePropertyKeys().isEmpty();
nodeLabelReadBuffer = new long[graphStore.nodeLabels().size()];
nodeLabelCounter = new MutableInt();
this.longNodeLabelReadBuffer = new long[graphStore.nodeLabels().size()];
this.intNodeLabelReadBuffer = new int[graphStore.nodeLabels().size()];
this.nodeLabelCounter = new MutableInt();
}

public abstract void properties(StoragePropertyCursor propertyCursor);

@Override
public long[] labels() {
protected long[] longLabels() {
nodeLabelCounter.setValue(0);

graphStore.nodes().forEachNodeLabel(getId(), nodeLabel -> {
longNodeLabelReadBuffer[nodeLabelCounter.getAndIncrement()] = tokenHolders
.labelTokens()
.getIdByName(nodeLabel.name());
return true;
});

return Arrays.copyOf(longNodeLabelReadBuffer, nodeLabelCounter.getValue());
}

protected int[] intLabels() {
nodeLabelCounter.setValue(0);

graphStore.nodes().forEachNodeLabel(getId(), nodeLabel -> {
nodeLabelReadBuffer[nodeLabelCounter.getAndIncrement()] = tokenHolders
intNodeLabelReadBuffer[nodeLabelCounter.getAndIncrement()] = tokenHolders
.labelTokens()
.getIdByName(nodeLabel.name());
return true;
});

return Arrays.copyOf(nodeLabelReadBuffer, nodeLabelCounter.getValue());
return Arrays.copyOf(intNodeLabelReadBuffer, nodeLabelCounter.getValue());
}

public boolean hasAtLeastOneLabelForCurrentNode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.neo4j.configuration.Config;
import org.neo4j.configuration.connectors.ConnectorPortRegister;
import org.neo4j.dbms.api.DatabaseManagementService;
import org.neo4j.exceptions.KernelException;
import org.neo4j.gds.annotation.SuppressForbidden;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
Expand All @@ -44,10 +43,8 @@
import org.neo4j.internal.batchimport.staging.ExecutionMonitor;
import org.neo4j.internal.helpers.HostnamePort;
import org.neo4j.internal.id.IdGeneratorFactory;
import org.neo4j.internal.kernel.api.IndexReadSession;
import org.neo4j.internal.kernel.api.NodeCursor;
import org.neo4j.internal.kernel.api.NodeLabelIndexCursor;
import org.neo4j.internal.kernel.api.NodeValueIndexCursor;
import org.neo4j.internal.kernel.api.PropertyCursor;
import org.neo4j.internal.kernel.api.Read;
import org.neo4j.internal.kernel.api.RelationshipScanCursor;
Expand All @@ -61,7 +58,6 @@
import org.neo4j.internal.kernel.api.security.AuthSubject;
import org.neo4j.internal.kernel.api.security.SecurityContext;
import org.neo4j.internal.schema.IndexCapability;
import org.neo4j.internal.schema.IndexOrder;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.layout.DatabaseLayout;
import org.neo4j.io.layout.Neo4jLayout;
Expand All @@ -77,9 +73,7 @@
import org.neo4j.kernel.impl.coreapi.InternalTransaction;
import org.neo4j.kernel.impl.query.TransactionalContext;
import org.neo4j.kernel.impl.query.TransactionalContextFactory;
import org.neo4j.kernel.impl.store.RecordStore;
import org.neo4j.kernel.impl.store.format.RecordFormats;
import org.neo4j.kernel.impl.store.record.AbstractBaseRecord;
import org.neo4j.logging.Log;
import org.neo4j.logging.internal.LogService;
import org.neo4j.procedure.Mode;
Expand Down Expand Up @@ -127,10 +121,6 @@ public static SecurityContext securityContext(
return IMPL.securityContext(username, authSubject, mode, databaseName);
}

public static long getHighId(RecordStore<? extends AbstractBaseRecord> recordStore) {
return IMPL.getHighId(recordStore);
}

public static List<StoreScan<NodeLabelIndexCursor>> entityCursorScan(
KernelTransaction transaction,
int[] labelIds,
Expand Down Expand Up @@ -186,10 +176,6 @@ public static NodeLabelIndexCursor allocateNodeLabelIndexCursor(KernelTransactio
return IMPL.allocateNodeLabelIndexCursor(kernelTransaction);
}

public static NodeValueIndexCursor allocateNodeValueIndexCursor(KernelTransaction kernelTransaction) {
return IMPL.allocateNodeValueIndexCursor(kernelTransaction);
}

public static boolean hasNodeLabelIndex(KernelTransaction kernelTransaction) {
return IMPL.hasNodeLabelIndex(kernelTransaction);
}
Expand Down Expand Up @@ -219,31 +205,6 @@ public static CompatExecutionContext executionContext(KernelTransaction ktx) {
return IMPL.executionContext(ktx);
}

public static CompatIndexQuery rangeIndexQuery(
int propertyKeyId,
double from,
boolean fromInclusive,
double to,
boolean toInclusive
) {
return IMPL.rangeIndexQuery(propertyKeyId, from, fromInclusive, to, toInclusive);
}

public static CompatIndexQuery rangeAllIndexQuery(int propertyKeyId) {
return IMPL.rangeAllIndexQuery(propertyKeyId);
}

public static void nodeIndexSeek(
Read dataRead,
IndexReadSession index,
NodeValueIndexCursor cursor,
IndexOrder indexOrder,
boolean needsValues,
CompatIndexQuery query
) throws KernelException {
IMPL.nodeIndexSeek(dataRead, index, cursor, indexOrder, needsValues, query);
}

public static CompositeNodeCursor compositeNodeCursor(List<NodeLabelIndexCursor> cursors, int[] labelIds) {
return IMPL.compositeNodeCursor(cursors, labelIds);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public long nodeId() {
}

@Override
public long[] labels() {
return compositeNodeCursor.currentLabels();
public NodeLabelTokenSet labels() {
return NodeLabelTokenSet.from(compositeNodeCursor.currentLabels());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ private NativeNodePropertyImporter(

public int importProperties(
long neoNodeId,
long[] labelIds,
NodeLabelTokenSet labelTokens,
PropertyReference propertiesReference,
KernelTransaction kernelTransaction
) {
try (PropertyCursor pc = Neo4jProxy.allocatePropertyCursor(kernelTransaction)) {
Neo4jProxy.nodeProperties(kernelTransaction, neoNodeId, propertiesReference, pc);
int nodePropertiesRead = 0;
while (pc.next()) {
nodePropertiesRead += importProperty(neoNodeId, labelIds, pc);
nodePropertiesRead += importProperty(neoNodeId, labelTokens, pc);
}
return nodePropertiesRead;
}
Expand All @@ -88,11 +88,12 @@ public Map<PropertyMapping, NodePropertyValues> result(IdMap idMap) {
return buildersByLabel.build(idMap);
}

private int importProperty(long neoNodeId, long[] labelIds, PropertyCursor propertyCursor) {
private int importProperty(long neoNodeId, NodeLabelTokenSet labelTokens, PropertyCursor propertyCursor) {
int propertiesImported = 0;
int propertyKey = propertyCursor.propertyKey();

for (long labelId : labelIds) {
for (int i = 0; i < labelTokens.length(); i++) {
var labelId = labelTokens.get(i);
if (labelId == IGNORE || labelId == ANY_LABEL) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public long nodeId() {
}

@Override
public long[] labels() {
return nodeCursor.labels().all();
public NodeLabelTokenSet labels() {
return NodeLabelTokenSet.from(nodeCursor.labels().all());
}

@Override
Expand Down
Loading

0 comments on commit 5a0e175

Please sign in to comment.