Search in sources :

Example 31 with LoadException

use of com.baidu.hugegraph.loader.exception.LoadException in project incubator-hugegraph-toolchain by apache.

the class TaskManager method submitInSingle.

private void submitInSingle(InputStruct struct, ElementMapping mapping, List<Record> batch) {
    long start = System.currentTimeMillis();
    try {
        this.singleSemaphore.acquire();
    } catch (InterruptedException e) {
        throw new LoadException("Interrupted while waiting to submit %s " + "batch in single mode", e, mapping.type());
    }
    LoadSummary summary = this.context.summary();
    InsertTask task = new SingleInsertTask(this.context, struct, mapping, batch);
    CompletableFuture.runAsync(task, this.singleService).whenComplete((r, e) -> {
        summary.metrics(struct).minusFlighting(batch.size());
        this.singleSemaphore.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)

Example 32 with LoadException

use of com.baidu.hugegraph.loader.exception.LoadException 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

LoadException (com.baidu.hugegraph.loader.exception.LoadException)32 IOException (java.io.IOException)18 File (java.io.File)10 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 FileFilter (com.baidu.hugegraph.loader.source.file.FileFilter)3 Path (org.apache.hadoop.fs.Path)3 ServerException (com.baidu.hugegraph.exception.ServerException)2 InitException (com.baidu.hugegraph.loader.exception.InitException)2 LoadOptions (com.baidu.hugegraph.loader.executor.LoadOptions)2 LoadSummary (com.baidu.hugegraph.loader.metrics.LoadSummary)2 Readable (com.baidu.hugegraph.loader.reader.Readable)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 CompressorInputStream (org.apache.commons.compress.compressors.CompressorInputStream)2 CompressionInputStream (org.apache.hadoop.io.compress.CompressionInputStream)2 HugeClient (com.baidu.hugegraph.driver.HugeClient)1 HugeClientBuilder (com.baidu.hugegraph.driver.HugeClientBuilder)1 GroovyExecutor (com.baidu.hugegraph.loader.executor.GroovyExecutor)1 InputStruct (com.baidu.hugegraph.loader.mapping.InputStruct)1