use of com.alibaba.graphscope.groot.operation.StoreDataBatch.Builder in project GraphScope by alibaba.
the class BatchSender method asyncSendWithRetry.
public void asyncSendWithRetry(String requestId, int queueId, long snapshotId, long offset, OperationBatch operationBatch) {
int partitionCount = metaService.getPartitionCount();
Map<Integer, Builder> storeToBatchBuilder = new HashMap<>();
Function<Integer, Builder> storeDataBatchBuilderFunc = k -> StoreDataBatch.newBuilder().requestId(requestId).queueId(queueId).snapshotId(snapshotId).offset(offset);
for (OperationBlob operationBlob : operationBatch) {
long partitionKey = operationBlob.getPartitionKey();
if (partitionKey == -1L) {
// replicate to all store node
for (int i = 0; i < this.storeCount; i++) {
StoreDataBatch.Builder batchBuilder = storeToBatchBuilder.computeIfAbsent(i, storeDataBatchBuilderFunc);
batchBuilder.addOperation(-1, operationBlob);
}
} else {
int partitionId = PartitionUtils.getPartitionIdFromKey(partitionKey, partitionCount);
int storeId = metaService.getStoreIdByPartition(partitionId);
StoreDataBatch.Builder batchBuilder = storeToBatchBuilder.computeIfAbsent(storeId, storeDataBatchBuilderFunc);
batchBuilder.addOperation(partitionId, operationBlob);
}
}
storeToBatchBuilder.forEach((storeId, batchBuilder) -> {
while (!shouldStop) {
try {
storeSendBuffer.get(storeId).put(batchBuilder.build());
break;
} catch (InterruptedException e) {
logger.warn("send buffer interrupted", e);
}
}
});
}
Aggregations