Search in sources :

Example 1 with Builder

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);
            }
        }
    });
}
Also used : Configs(com.alibaba.maxgraph.common.config.Configs) CommonConfig(com.alibaba.maxgraph.common.config.CommonConfig) LoggerFactory(org.slf4j.LoggerFactory) IngestorConfig(com.alibaba.maxgraph.common.config.IngestorConfig) OperationBatch(com.alibaba.graphscope.groot.operation.OperationBatch) StoreDataBatch(com.alibaba.graphscope.groot.operation.StoreDataBatch) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) MetricsCollector(com.alibaba.graphscope.groot.metrics.MetricsCollector) MetricsAgent(com.alibaba.graphscope.groot.metrics.MetricsAgent) Map(java.util.Map) Logger(org.slf4j.Logger) CompletionCallback(com.alibaba.graphscope.groot.CompletionCallback) BlockingQueue(java.util.concurrent.BlockingQueue) MetaService(com.alibaba.graphscope.groot.meta.MetaService) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) PartitionUtils(com.alibaba.maxgraph.sdkcommon.util.PartitionUtils) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) StoreConfig(com.alibaba.maxgraph.common.config.StoreConfig) List(java.util.List) AvgMetric(com.alibaba.graphscope.groot.metrics.AvgMetric) Builder(com.alibaba.graphscope.groot.operation.StoreDataBatch.Builder) OperationBlob(com.alibaba.graphscope.groot.operation.OperationBlob) Builder(com.alibaba.graphscope.groot.operation.StoreDataBatch.Builder) HashMap(java.util.HashMap) OperationBlob(com.alibaba.graphscope.groot.operation.OperationBlob) Builder(com.alibaba.graphscope.groot.operation.StoreDataBatch.Builder) StoreDataBatch(com.alibaba.graphscope.groot.operation.StoreDataBatch)

Aggregations

CompletionCallback (com.alibaba.graphscope.groot.CompletionCallback)1 MetaService (com.alibaba.graphscope.groot.meta.MetaService)1 AvgMetric (com.alibaba.graphscope.groot.metrics.AvgMetric)1 MetricsAgent (com.alibaba.graphscope.groot.metrics.MetricsAgent)1 MetricsCollector (com.alibaba.graphscope.groot.metrics.MetricsCollector)1 OperationBatch (com.alibaba.graphscope.groot.operation.OperationBatch)1 OperationBlob (com.alibaba.graphscope.groot.operation.OperationBlob)1 StoreDataBatch (com.alibaba.graphscope.groot.operation.StoreDataBatch)1 Builder (com.alibaba.graphscope.groot.operation.StoreDataBatch.Builder)1 CommonConfig (com.alibaba.maxgraph.common.config.CommonConfig)1 Configs (com.alibaba.maxgraph.common.config.Configs)1 IngestorConfig (com.alibaba.maxgraph.common.config.IngestorConfig)1 StoreConfig (com.alibaba.maxgraph.common.config.StoreConfig)1 PartitionUtils (com.alibaba.maxgraph.sdkcommon.util.PartitionUtils)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 BlockingQueue (java.util.concurrent.BlockingQueue)1