Search in sources :

Example 1 with SplitRegionRequest

use of org.tikv.kvproto.Kvrpcpb.SplitRegionRequest in project client-java by tikv.

the class RegionStoreClient method splitRegion.

/**
 * Send SplitRegion request to tikv split a region at splitKey. splitKey must between current
 * region's start key and end key.
 *
 * @param splitKeys is the split points for a specific region.
 * @return a split region info.
 */
public List<Metapb.Region> splitRegion(Iterable<ByteString> splitKeys) {
    Supplier<SplitRegionRequest> request = () -> SplitRegionRequest.newBuilder().setContext(makeContext(storeType, SlowLogEmptyImpl.INSTANCE)).addAllSplitKeys(splitKeys).setIsRawKv(conf.isRawKVMode()).build();
    KVErrorHandler<SplitRegionResponse> handler = new KVErrorHandler<>(regionManager, this, null, resp -> resp.hasRegionError() ? resp.getRegionError() : null, resp -> null, resolveLockResult -> null, 0L, false);
    SplitRegionResponse resp = callWithRetry(ConcreteBackOffer.newGetBackOff(pdClient.getClusterId()), TikvGrpc.getSplitRegionMethod(), request, handler);
    if (resp == null) {
        this.regionManager.onRequestFail(region);
        throw new TiClientInternalException("SplitRegion Response failed without a cause");
    }
    if (resp.hasRegionError()) {
        throw new TiClientInternalException(String.format("failed to split region %d because %s", region.getId(), resp.getRegionError().toString()));
    }
    return resp.getRegionsList();
}
Also used : SplitRegionResponse(org.tikv.kvproto.Kvrpcpb.SplitRegionResponse) TiClientInternalException(org.tikv.common.exception.TiClientInternalException) SplitRegionRequest(org.tikv.kvproto.Kvrpcpb.SplitRegionRequest) KVErrorHandler(org.tikv.common.operation.KVErrorHandler)

Example 2 with SplitRegionRequest

use of org.tikv.kvproto.Kvrpcpb.SplitRegionRequest in project tispark by pingcap.

the class RegionStoreClient method splitRegion.

/**
 * Send SplitRegion request to tikv split a region at splitKey. splitKey must between current
 * region's start key and end key.
 *
 * @param splitKeys is the split points for a specific region.
 * @return a split region info.
 */
public List<TiRegion> splitRegion(Iterable<ByteString> splitKeys) {
    Supplier<SplitRegionRequest> request = () -> SplitRegionRequest.newBuilder().setContext(region.getContext()).addAllSplitKeys(splitKeys).build();
    KVErrorHandler<SplitRegionResponse> handler = new KVErrorHandler<>(regionManager, this, null, resp -> resp.hasRegionError() ? resp.getRegionError() : null, resp -> null, resolveLockResult -> null, 0L, false);
    SplitRegionResponse resp = callWithRetry(ConcreteBackOffer.newGetBackOff(), TikvGrpc.getSplitRegionMethod(), request, handler);
    if (resp == null) {
        this.regionManager.onRequestFail(region);
        throw new TiClientInternalException("SplitRegion Response failed without a cause");
    }
    if (resp.hasRegionError()) {
        throw new TiClientInternalException(String.format("failed to split region %d because %s", region.getId(), resp.getRegionError().toString()));
    }
    return resp.getRegionsList().stream().map(region -> new TiRegion(region, null, conf.getIsolationLevel(), conf.getCommandPriority())).collect(Collectors.toList());
}
Also used : Batch(com.pingcap.tikv.util.Batch) CommitResponse(org.tikv.kvproto.Kvrpcpb.CommitResponse) RawPutRequest(org.tikv.kvproto.Kvrpcpb.RawPutRequest) ScanRequest(org.tikv.kvproto.Kvrpcpb.ScanRequest) ChannelFactory(com.pingcap.tikv.util.ChannelFactory) SelectResponse(com.pingcap.tidb.tipb.SelectResponse) ManagedChannel(io.grpc.ManagedChannel) RawScanRequest(org.tikv.kvproto.Kvrpcpb.RawScanRequest) Errorpb(org.tikv.kvproto.Errorpb) RawBatchGetRequest(org.tikv.kvproto.Kvrpcpb.RawBatchGetRequest) ConcreteBackOffer(com.pingcap.tikv.util.ConcreteBackOffer) RawGetKeyTTLRequest(org.tikv.kvproto.Kvrpcpb.RawGetKeyTTLRequest) LoggerFactory(org.slf4j.LoggerFactory) PDClient(com.pingcap.tikv.PDClient) RawBatchGetResponse(org.tikv.kvproto.Kvrpcpb.RawBatchGetResponse) RegionException(com.pingcap.tikv.exception.RegionException) Pair(com.pingcap.tikv.util.Pair) REQ_TYPE_DAG(com.pingcap.tikv.region.RegionStoreClient.RequestTypes.REQ_TYPE_DAG) RawDeleteRangeResponse(org.tikv.kvproto.Kvrpcpb.RawDeleteRangeResponse) Map(java.util.Map) TiClientInternalException(com.pingcap.tikv.exception.TiClientInternalException) StreamingResponse(com.pingcap.tikv.streaming.StreamingResponse) BackOffer(com.pingcap.tikv.util.BackOffer) Coprocessor(org.tikv.kvproto.Coprocessor) TxnHeartBeatResponse(org.tikv.kvproto.Kvrpcpb.TxnHeartBeatResponse) TikvBlockingStub(org.tikv.kvproto.TikvGrpc.TikvBlockingStub) RawDeleteRangeRequest(org.tikv.kvproto.Kvrpcpb.RawDeleteRangeRequest) TikvStub(org.tikv.kvproto.TikvGrpc.TikvStub) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) RawBatchPutResponse(org.tikv.kvproto.Kvrpcpb.RawBatchPutResponse) RawDeleteRequest(org.tikv.kvproto.Kvrpcpb.RawDeleteRequest) BackOffFunction(com.pingcap.tikv.util.BackOffFunction) BoRegionMiss(com.pingcap.tikv.util.BackOffFunction.BackOffFuncType.BoRegionMiss) RawCASResponse(org.tikv.kvproto.Kvrpcpb.RawCASResponse) RangeSplitter(com.pingcap.tikv.util.RangeSplitter) Set(java.util.Set) SelectException(com.pingcap.tikv.exception.SelectException) Collectors(java.util.stream.Collectors) RawGetKeyTTLResponse(org.tikv.kvproto.Kvrpcpb.RawGetKeyTTLResponse) ByteString(com.google.protobuf.ByteString) Objects(java.util.Objects) List(java.util.List) TiKVException(com.pingcap.tikv.exception.TiKVException) Lock(com.pingcap.tikv.txn.Lock) GetRequest(org.tikv.kvproto.Kvrpcpb.GetRequest) TiConfiguration(com.pingcap.tikv.TiConfiguration) ResolveLockResult(com.pingcap.tikv.txn.ResolveLockResult) Queue(java.util.Queue) Mutation(org.tikv.kvproto.Kvrpcpb.Mutation) KvPair(org.tikv.kvproto.Kvrpcpb.KvPair) RawPutResponse(org.tikv.kvproto.Kvrpcpb.RawPutResponse) LockException(com.pingcap.tikv.exception.LockException) BatchGetResponse(org.tikv.kvproto.Kvrpcpb.BatchGetResponse) RawBatchDeleteRequest(org.tikv.kvproto.Kvrpcpb.RawBatchDeleteRequest) Store(org.tikv.kvproto.Metapb.Store) Version(com.pingcap.tikv.Version) HashMap(java.util.HashMap) RawDeleteResponse(org.tikv.kvproto.Kvrpcpb.RawDeleteResponse) PrewriteResponse(org.tikv.kvproto.Kvrpcpb.PrewriteResponse) SplitRegionResponse(org.tikv.kvproto.Kvrpcpb.SplitRegionResponse) Supplier(java.util.function.Supplier) ScanResponse(org.tikv.kvproto.Kvrpcpb.ScanResponse) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BoTxnLockFast(com.pingcap.tikv.util.BackOffFunction.BackOffFuncType.BoTxnLockFast) GrpcException(com.pingcap.tikv.exception.GrpcException) GetResponse(org.tikv.kvproto.Kvrpcpb.GetResponse) KVErrorHandler(com.pingcap.tikv.operation.KVErrorHandler) KeyError(org.tikv.kvproto.Kvrpcpb.KeyError) TxnHeartBeatRequest(org.tikv.kvproto.Kvrpcpb.TxnHeartBeatRequest) BoTxnLock(com.pingcap.tikv.util.BackOffFunction.BackOffFuncType.BoTxnLock) RawGetResponse(org.tikv.kvproto.Kvrpcpb.RawGetResponse) KeyException(com.pingcap.tikv.exception.KeyException) RawGetRequest(org.tikv.kvproto.Kvrpcpb.RawGetRequest) RawCASRequest(org.tikv.kvproto.Kvrpcpb.RawCASRequest) Logger(org.slf4j.Logger) PrewriteRequest(org.tikv.kvproto.Kvrpcpb.PrewriteRequest) StoreVersion(com.pingcap.tikv.StoreVersion) Iterator(java.util.Iterator) CommitRequest(org.tikv.kvproto.Kvrpcpb.CommitRequest) TikvGrpc(org.tikv.kvproto.TikvGrpc) BatchGetRequest(org.tikv.kvproto.Kvrpcpb.BatchGetRequest) DAGRequest(com.pingcap.tidb.tipb.DAGRequest) RawScanResponse(org.tikv.kvproto.Kvrpcpb.RawScanResponse) RawBatchPutRequest(org.tikv.kvproto.Kvrpcpb.RawBatchPutRequest) RawBatchDeleteResponse(org.tikv.kvproto.Kvrpcpb.RawBatchDeleteResponse) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AbstractLockResolverClient(com.pingcap.tikv.txn.AbstractLockResolverClient) Collections(java.util.Collections) SplitRegionRequest(org.tikv.kvproto.Kvrpcpb.SplitRegionRequest) SplitRegionResponse(org.tikv.kvproto.Kvrpcpb.SplitRegionResponse) TiClientInternalException(com.pingcap.tikv.exception.TiClientInternalException) SplitRegionRequest(org.tikv.kvproto.Kvrpcpb.SplitRegionRequest) KVErrorHandler(com.pingcap.tikv.operation.KVErrorHandler)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ByteString (com.google.protobuf.ByteString)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 DAGRequest (com.pingcap.tidb.tipb.DAGRequest)1 SelectResponse (com.pingcap.tidb.tipb.SelectResponse)1 PDClient (com.pingcap.tikv.PDClient)1 StoreVersion (com.pingcap.tikv.StoreVersion)1 TiConfiguration (com.pingcap.tikv.TiConfiguration)1 Version (com.pingcap.tikv.Version)1 GrpcException (com.pingcap.tikv.exception.GrpcException)1 KeyException (com.pingcap.tikv.exception.KeyException)1 LockException (com.pingcap.tikv.exception.LockException)1 RegionException (com.pingcap.tikv.exception.RegionException)1 SelectException (com.pingcap.tikv.exception.SelectException)1 TiClientInternalException (com.pingcap.tikv.exception.TiClientInternalException)1 TiKVException (com.pingcap.tikv.exception.TiKVException)1 KVErrorHandler (com.pingcap.tikv.operation.KVErrorHandler)1 REQ_TYPE_DAG (com.pingcap.tikv.region.RegionStoreClient.RequestTypes.REQ_TYPE_DAG)1 StreamingResponse (com.pingcap.tikv.streaming.StreamingResponse)1 AbstractLockResolverClient (com.pingcap.tikv.txn.AbstractLockResolverClient)1