in graphjet-core/src/main/java/com/twitter/graphjet/bipartite/segment/RightNodeMetadataLeftIndexedBipartiteGraphSegment.java [114:153]
public void addEdge(
long leftNode,
long rightNode,
byte edgeType,
int[][] rightNodeMetadata
) {
// We need to the nodes to the map at the very top since once we write an edge, we need to be
// able to find it's corresponding external id. On the other hand, if a reader finds an id in
// the map it still won't be able to get to the edges till the edge is written so this is safe.
// The following gets the internal id's and add the nodes if they're not already in there.
int leftNodeInternalId = readerAccessibleInfoProvider
.getReaderAccessibleInfo().addLeftNode(leftNode);
int rightNodeInternalId = readerAccessibleInfoProvider
.getReaderAccessibleInfo().addRightNode(rightNode);
// Update RightNodesToMetadataMap, which has its own memory barrier internally.
if (rightNodeMetadata != null) {
for (int i = 0; i < rightNodeMetadata.length; i++) {
IntToIntArrayMap metadataMap = readerAccessibleInfoProvider.getReaderAccessibleInfo().
getRightNodesToMetadataMap(i);
metadataMap.put(rightNodeInternalId, rightNodeMetadata[i]);
metadataMap.incrementFeatureValue(rightNodeInternalId, edgeType);
}
}
// At this point there is an internal memory barrier deep inside LeftIndexedReaderAccessibleInfo
// so that node mappings are visible if the edge is visible
// Now we can add the edge
// First we add the edges to the left pool so that it is ready to be accessed
readerAccessibleInfoProvider
.getLeftIndexedReaderAccessibleInfo().getLeftNodeEdgePool().addEdge(
leftNodeInternalId, edgeTypeMask.encode(rightNodeInternalId, edgeType));
// Finally, explicitly flush the edge write so that the edge is visible to the readers
currentNumEdges++;
numEdgesCounter.incr();
}