Search in sources :

Example 6 with LoadSummary

use of com.baidu.hugegraph.loader.metrics.LoadSummary in project incubator-hugegraph-toolchain by apache.

the class TaskManager method submitBatch.

public void submitBatch(InputStruct struct, ElementMapping mapping, List<Record> batch) {
    long start = System.currentTimeMillis();
    try {
        this.batchSemaphore.acquire();
    } catch (InterruptedException e) {
        throw new LoadException("Interrupted while waiting to submit %s " + "batch in batch mode", e, mapping.type());
    }
    LoadSummary summary = this.context.summary();
    summary.metrics(struct).plusFlighting(batch.size());
    InsertTask task = new BatchInsertTask(this.context, struct, mapping, batch);
    CompletableFuture.runAsync(task, this.batchService).whenComplete((r, e) -> {
        if (e != null) {
            LOG.warn("Batch insert {} error, try single insert", mapping.type(), e);
            // The time of single insert is counted separately
            this.submitInSingle(struct, mapping, batch);
        } else {
            summary.metrics(struct).minusFlighting(batch.size());
        }
        this.batchSemaphore.release();
        long end = System.currentTimeMillis();
        this.context.summary().addTimeRange(mapping.type(), start, end);
    });
}
Also used : LoadException(com.baidu.hugegraph.loader.exception.LoadException) LoadSummary(com.baidu.hugegraph.loader.metrics.LoadSummary)

Aggregations

LoadSummary (com.baidu.hugegraph.loader.metrics.LoadSummary)6 LoadException (com.baidu.hugegraph.loader.exception.LoadException)2 LoadOptions (com.baidu.hugegraph.loader.executor.LoadOptions)2