Search in sources :

Example 1 with SelectResponse

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

the class DAGIterator method processByStreaming.

private Iterator<SelectResponse> processByStreaming(RangeSplitter.RegionTask regionTask) {
    List<Coprocessor.KeyRange> ranges = regionTask.getRanges();
    TiRegion region = regionTask.getRegion();
    TiStore store = regionTask.getStore();
    RegionStoreClient client;
    try {
        client = session.getRegionStoreClientBuilder().build(region, store, storeType);
        Iterator<SelectResponse> responseIterator = client.coprocessStreaming(dagRequest, ranges, startTs);
        if (responseIterator == null) {
            eof = true;
            return null;
        }
        return responseIterator;
    } catch (Exception e) {
        // see:https://github.com/pingcap/tikv-client-lib-java/pull/149
        throw new TiClientInternalException("Error Closing Store client.", e);
    }
}
Also used : TiClientInternalException(org.tikv.common.exception.TiClientInternalException) TiRegion(org.tikv.common.region.TiRegion) TiStore(org.tikv.common.region.TiStore) SelectResponse(com.pingcap.tidb.tipb.SelectResponse) RegionStoreClient(org.tikv.common.region.RegionStoreClient) RegionTaskException(org.tikv.common.exception.RegionTaskException) TiClientInternalException(org.tikv.common.exception.TiClientInternalException)

Example 2 with SelectResponse

use of com.pingcap.tidb.tipb.SelectResponse 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 3 with SelectResponse

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

the class DAGIterator method processByStreaming.

private Iterator<SelectResponse> processByStreaming(RangeSplitter.RegionTask regionTask) {
    List<Coprocessor.KeyRange> ranges = regionTask.getRanges();
    TiRegion region = regionTask.getRegion();
    Metapb.Store store = regionTask.getStore();
    RegionStoreClient client;
    try {
        client = session.getRegionStoreClientBuilder().build(region, store, storeType);
        Iterator<SelectResponse> responseIterator = client.coprocessStreaming(dagRequest, ranges, startTs);
        if (responseIterator == null) {
            eof = true;
            return null;
        }
        return responseIterator;
    } catch (Exception e) {
        // see:https://github.com/pingcap/tikv-client-lib-java/pull/149
        throw new TiClientInternalException("Error Closing Store client.", e);
    }
}
Also used : TiClientInternalException(com.pingcap.tikv.exception.TiClientInternalException) TiRegion(com.pingcap.tikv.region.TiRegion) Metapb(org.tikv.kvproto.Metapb) SelectResponse(com.pingcap.tidb.tipb.SelectResponse) RegionStoreClient(com.pingcap.tikv.region.RegionStoreClient) TiClientInternalException(com.pingcap.tikv.exception.TiClientInternalException) RegionTaskException(com.pingcap.tikv.exception.RegionTaskException)

Example 4 with SelectResponse

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

the class DAGIterator method advanceNextResponse.

private boolean advanceNextResponse() {
    if (!hasMoreResponse()) {
        return false;
    }
    switch(pushDownType) {
        case STREAMING:
            SelectResponse resp = responseIterator.next();
            chunkList = resp.getChunksList();
            this.encodeType = resp.getEncodeType();
            break;
        case NORMAL:
            chunkList = response.getChunksList();
            this.encodeType = this.response.getEncodeType();
            break;
    }
    if (chunkList == null || chunkList.isEmpty()) {
        return false;
    }
    chunkIndex = 0;
    createDataInputReader();
    return true;
}
Also used : SelectResponse(com.pingcap.tidb.tipb.SelectResponse)

Example 5 with SelectResponse

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

the class RegionStoreClientTest method coprocess.

private SelectResponse coprocess(RegionStoreClient client, DAGRequest request, List<Coprocessor.KeyRange> ranges) {
    BackOffer backOffer = defaultBackOff();
    Queue<SelectResponse> responseQueue = new ArrayDeque<>();
    client.coprocess(backOffer, request, client.getRegion(), ranges, responseQueue, 1);
    List<Chunk> resultChunk = new ArrayList<>();
    while (!responseQueue.isEmpty()) {
        SelectResponse response = responseQueue.poll();
        if (response != null) {
            resultChunk.addAll(response.getChunksList());
        }
    }
    return SelectResponse.newBuilder().addAllChunks(resultChunk).build();
}
Also used : ArrayList(java.util.ArrayList) ConcreteBackOffer(com.pingcap.tikv.util.ConcreteBackOffer) BackOffer(com.pingcap.tikv.util.BackOffer) Chunk(com.pingcap.tidb.tipb.Chunk) SelectResponse(com.pingcap.tidb.tipb.SelectResponse) ArrayDeque(java.util.ArrayDeque)

Aggregations

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