Search in sources :

Example 6 with Chunk

use of com.pingcap.tidb.tipb.Chunk 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)

Example 7 with Chunk

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

the class ChunkIteratorTest method setup.

@Before
public void setup() {
    // 8 2 2 2 a 8 4 2 2 b 8 6 2 2 c
    // 1 a 2 b 3 c
    String chunkStr = "\b\u0002\u0002\u0002a\b\u0004\u0002\u0002b\b\u0006\u0002\u0002c";
    Chunk chunk = Chunk.newBuilder().setRowsData(ByteString.copyFromUtf8(chunkStr)).addRowsMeta(0, RowMeta.newBuilder().setHandle(1).setLength(5)).addRowsMeta(1, RowMeta.newBuilder().setHandle(2).setLength(5)).addRowsMeta(2, RowMeta.newBuilder().setHandle(3).setLength(5)).build();
    chunks.add(chunk);
}
Also used : ByteString(com.google.protobuf.ByteString) Chunk(com.pingcap.tidb.tipb.Chunk) Before(org.junit.Before)

Example 8 with Chunk

use of com.pingcap.tidb.tipb.Chunk 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)

Example 9 with Chunk

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

the class ChunkIterator method getRawBytesChunkIterator.

public static ChunkIterator<ByteString> getRawBytesChunkIterator(List<Chunk> chunks) {
    return new ChunkIterator<ByteString>(chunks) {

        @Override
        public ByteString next() {
            Chunk c = chunks.get(chunkIndex);
            long endOffset = c.getRowsMeta(metaIndex).getLength() + bufOffset;
            if (endOffset > Integer.MAX_VALUE) {
                throw new TiClientInternalException("Offset exceeded MAX_INT.");
            }
            ByteString result = c.getRowsData().substring(bufOffset, (int) endOffset);
            advance();
            return result;
        }
    };
}
Also used : TiClientInternalException(org.tikv.common.exception.TiClientInternalException) ByteString(com.google.protobuf.ByteString) Chunk(com.pingcap.tidb.tipb.Chunk)

Example 10 with Chunk

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

the class ChunkIterator method getHandleChunkIterator.

public static ChunkIterator<Long> getHandleChunkIterator(List<Chunk> chunks) {
    return new ChunkIterator<Long>(chunks) {

        @Override
        public Long next() {
            Chunk c = chunks.get(chunkIndex);
            long result = c.getRowsMeta(metaIndex).getHandle();
            advance();
            return result;
        }
    };
}
Also used : Chunk(com.pingcap.tidb.tipb.Chunk)

Aggregations

Chunk (com.pingcap.tidb.tipb.Chunk)10 ByteString (com.google.protobuf.ByteString)3 SelectResponse (com.pingcap.tidb.tipb.SelectResponse)3 EncodeType (com.pingcap.tidb.tipb.EncodeType)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 (com.pingcap.tikv.exception.RegionTaskException)1 TiClientInternalException (com.pingcap.tikv.exception.TiClientInternalException)1 RegionStoreClient (com.pingcap.tikv.region.RegionStoreClient)1 TiRegion (com.pingcap.tikv.region.TiRegion)1 RangeSplitter (com.pingcap.tikv.util.RangeSplitter)1 HashSet (java.util.HashSet)1 Before (org.junit.Before)1 RegionTaskException (org.tikv.common.exception.RegionTaskException)1 TiClientInternalException (org.tikv.common.exception.TiClientInternalException)1 RegionStoreClient (org.tikv.common.region.RegionStoreClient)1 TiRegion (org.tikv.common.region.TiRegion)1 TiStore (org.tikv.common.region.TiStore)1