1 /*
2 * Copyright 2021 TiKV Project Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18 package org.tikv.common;
19
20 import com.google.protobuf.ByteString;
21 import java.util.List;
22 import org.tikv.common.apiversion.RequestKeyCodec;
23 import org.tikv.common.meta.TiTimestamp;
24 import org.tikv.common.util.BackOffer;
25 import org.tikv.common.util.Pair;
26 import org.tikv.kvproto.Metapb;
27 import org.tikv.kvproto.Metapb.Store;
28 import org.tikv.kvproto.Pdpb;
29
30 /** Readonly PD client including only reading related interface Supposed for TiDB-like use cases */
31 public interface ReadOnlyPDClient {
32 /**
33 * Get Timestamp from Placement Driver
34 *
35 * @return a timestamp object
36 */
37 TiTimestamp getTimestamp(BackOffer backOffer);
38
39 /**
40 * Get Region from PD by key specified
41 *
42 * @param key key in bytes for locating a region
43 * @return the region whose startKey and endKey range covers the given key
44 */
45 Pair<Metapb.Region, Metapb.Peer> getRegionByKey(BackOffer backOffer, ByteString key);
46
47 /**
48 * Get Region by Region Id
49 *
50 * @param id Region Id
51 * @return the region corresponding to the given Id
52 */
53 Pair<Metapb.Region, Metapb.Peer> getRegionByID(BackOffer backOffer, long id);
54
55 List<Pdpb.Region> scanRegions(
56 BackOffer backOffer, ByteString startKey, ByteString endKey, int limit);
57
58 HostMapping getHostMapping();
59
60 /**
61 * Get Store by StoreId
62 *
63 * @param storeId StoreId
64 * @return the Store corresponding to the given Id
65 */
66 Store getStore(BackOffer backOffer, long storeId);
67
68 List<Store> getAllStores(BackOffer backOffer);
69
70 TiConfiguration.ReplicaRead getReplicaRead();
71
72 Long getClusterId();
73
74 RequestKeyCodec getCodec();
75
76 /**
77 * Update ServiceGCSafePoint
78 *
79 * @param serviceId ServiceId
80 * @param ttl TTL in seconds
81 * @param safePoint The TiTimestamp you want to set. Set to start_ts.getPrevious() is a good
82 * practice
83 * @return the MinSafePoint of all services. If this value is greater than safePoint, it means
84 * update failed
85 */
86 Long updateServiceGCSafePoint(String serviceId, long ttl, long safePoint, BackOffer backOffer);
87 }