Search in sources :

Example 1 with EncodeType

use of com.pingcap.tidb.tipb.EncodeType in project tispark by pingcap.

the class DAGIterator method process.

private SelectResponse process(RangeSplitter.RegionTask regionTask) {
    Queue<RangeSplitter.RegionTask> remainTasks = new ArrayDeque<>();
    Queue<SelectResponse> responseQueue = new ArrayDeque<>();
    remainTasks.add(regionTask);
    BackOffer backOffer = ConcreteBackOffer.newCopNextMaxBackOff();
    HashSet<Long> resolvedLocks = new HashSet<>();
    // the remaining tasks.
    while (!remainTasks.isEmpty()) {
        RangeSplitter.RegionTask task = remainTasks.poll();
        if (task == null) {
            continue;
        }
        List<Coprocessor.KeyRange> ranges = task.getRanges();
        TiRegion region = task.getRegion();
        Metapb.Store store = task.getStore();
        try {
            RegionStoreClient client = session.getRegionStoreClientBuilder().build(region, store, storeType);
            client.addResolvedLocks(startTs, resolvedLocks);
            Collection<RangeSplitter.RegionTask> tasks = client.coprocess(backOffer, dagRequest, region, ranges, responseQueue, startTs);
            if (tasks != null) {
                remainTasks.addAll(tasks);
            }
            resolvedLocks.addAll(client.getResolvedLocks(startTs));
        } catch (Throwable e) {
            // Handle region task failed
            logger.error("Process region tasks failed, remain " + remainTasks.size() + " tasks not executed due to", e);
            // Rethrow to upper levels
            throw new RegionTaskException("Handle region task failed:", e);
        }
    }
    // Add all chunks to the final result
    List<Chunk> resultChunk = new ArrayList<>();
    EncodeType encodeType = null;
    while (!responseQueue.isEmpty()) {
        SelectResponse response = responseQueue.poll();
        if (response != null) {
            encodeType = response.getEncodeType();
            resultChunk.addAll(response.getChunksList());
        }
    }
    return SelectResponse.newBuilder().addAllChunks(resultChunk).setEncodeType(encodeType).build();
}
Also used : EncodeType(com.pingcap.tidb.tipb.EncodeType) ArrayList(java.util.ArrayList) ConcreteBackOffer(com.pingcap.tikv.util.ConcreteBackOffer) BackOffer(com.pingcap.tikv.util.BackOffer) Chunk(com.pingcap.tidb.tipb.Chunk) RegionTaskException(com.pingcap.tikv.exception.RegionTaskException) ArrayDeque(java.util.ArrayDeque) TiRegion(com.pingcap.tikv.region.TiRegion) RangeSplitter(com.pingcap.tikv.util.RangeSplitter) SelectResponse(com.pingcap.tidb.tipb.SelectResponse) Metapb(org.tikv.kvproto.Metapb) RegionStoreClient(com.pingcap.tikv.region.RegionStoreClient) HashSet(java.util.HashSet)

Example 2 with EncodeType

use of com.pingcap.tidb.tipb.EncodeType in project client-java by tikv.

the class DAGIterator method process.

private SelectResponse process(RangeSplitter.RegionTask regionTask) {
    Queue<RangeSplitter.RegionTask> remainTasks = new ArrayDeque<>();
    Queue<SelectResponse> responseQueue = new ArrayDeque<>();
    remainTasks.add(regionTask);
    BackOffer backOffer = ConcreteBackOffer.newCopNextMaxBackOff();
    HashSet<Long> resolvedLocks = new HashSet<>();
    // the remaining tasks.
    while (!remainTasks.isEmpty()) {
        RangeSplitter.RegionTask task = remainTasks.poll();
        if (task == null) {
            continue;
        }
        List<Coprocessor.KeyRange> ranges = task.getRanges();
        TiRegion region = task.getRegion();
        TiStore store = task.getStore();
        try {
            RegionStoreClient client = session.getRegionStoreClientBuilder().build(region, store, storeType);
            client.addResolvedLocks(startTs, resolvedLocks);
            Collection<RangeSplitter.RegionTask> tasks = client.coprocess(backOffer, dagRequest, ranges, responseQueue, startTs);
            if (tasks != null) {
                remainTasks.addAll(tasks);
            }
            resolvedLocks.addAll(client.getResolvedLocks(startTs));
        } catch (Throwable e) {
            // Handle region task failed
            logger.error("Process region tasks failed, remain " + remainTasks.size() + " tasks not executed due to", e);
            // Rethrow to upper levels
            throw new RegionTaskException("Handle region task failed:", e);
        }
    }
    // Add all chunks to the final result
    List<Chunk> resultChunk = new ArrayList<>();
    EncodeType encodeType = null;
    while (!responseQueue.isEmpty()) {
        SelectResponse response = responseQueue.poll();
        if (response != null) {
            encodeType = response.getEncodeType();
            resultChunk.addAll(response.getChunksList());
        }
    }
    return SelectResponse.newBuilder().addAllChunks(resultChunk).setEncodeType(encodeType).build();
}
Also used : EncodeType(com.pingcap.tidb.tipb.EncodeType) ConcreteBackOffer(org.tikv.common.util.ConcreteBackOffer) BackOffer(org.tikv.common.util.BackOffer) TiStore(org.tikv.common.region.TiStore) Chunk(com.pingcap.tidb.tipb.Chunk) RegionTaskException(org.tikv.common.exception.RegionTaskException) TiRegion(org.tikv.common.region.TiRegion) RangeSplitter(org.tikv.common.util.RangeSplitter) SelectResponse(com.pingcap.tidb.tipb.SelectResponse) RegionStoreClient(org.tikv.common.region.RegionStoreClient)

Aggregations

Chunk (com.pingcap.tidb.tipb.Chunk)2 EncodeType (com.pingcap.tidb.tipb.EncodeType)2 SelectResponse (com.pingcap.tidb.tipb.SelectResponse)2 RegionTaskException (com.pingcap.tikv.exception.RegionTaskException)1 RegionStoreClient (com.pingcap.tikv.region.RegionStoreClient)1 TiRegion (com.pingcap.tikv.region.TiRegion)1 BackOffer (com.pingcap.tikv.util.BackOffer)1 ConcreteBackOffer (com.pingcap.tikv.util.ConcreteBackOffer)1 RangeSplitter (com.pingcap.tikv.util.RangeSplitter)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 RegionTaskException (org.tikv.common.exception.RegionTaskException)1 RegionStoreClient (org.tikv.common.region.RegionStoreClient)1 TiRegion (org.tikv.common.region.TiRegion)1 TiStore (org.tikv.common.region.TiStore)1 BackOffer (org.tikv.common.util.BackOffer)1 ConcreteBackOffer (org.tikv.common.util.ConcreteBackOffer)1 RangeSplitter (org.tikv.common.util.RangeSplitter)1 Metapb (org.tikv.kvproto.Metapb)1