@@ -114,8 +114,37 @@ public List<Kvrpcpb.KvPair> batchGet(BackOffer backOffer, List<ByteString> keys,
114
114
*/
115
115
public List <Kvrpcpb .KvPair > scan (ByteString startKey , ByteString endKey , long version )
116
116
throws GrpcException {
117
+ return scan (startKey , endKey , version , false );
118
+ }
119
+ /**
120
+ * Scan key-value pairs from TiKV reversely in range (startKey, endKey]
121
+ *
122
+ * @param startKey start key, inclusive
123
+ * @param endKey end key, exclusive
124
+ * @return list of key-value pairs in range
125
+ */
126
+ public List <Kvrpcpb .KvPair > reverseScan (ByteString startKey , ByteString endKey , long version )
127
+ throws GrpcException {
128
+ return scan (endKey , startKey , version , true );
129
+ }
130
+
131
+ public List <Kvrpcpb .KvPair > scan (
132
+ ByteString startKey , ByteString endKey , long version , boolean reverse ) throws GrpcException {
133
+ Iterator <Kvrpcpb .KvPair > iterator ;
134
+ if (reverse ) {
135
+ iterator = scanIterator (conf , clientBuilder , endKey , startKey , version , reverse );
136
+ } else {
137
+ iterator = scanIterator (conf , clientBuilder , startKey , endKey , version , reverse );
138
+ }
139
+ List <Kvrpcpb .KvPair > result = new ArrayList <>();
140
+ iterator .forEachRemaining (result ::add );
141
+ return result ;
142
+ }
143
+
144
+ public List <Kvrpcpb .KvPair > scan (ByteString startKey , long version , int limit , boolean reverse )
145
+ throws GrpcException {
117
146
Iterator <Kvrpcpb .KvPair > iterator =
118
- scanIterator (conf , clientBuilder , startKey , endKey , version );
147
+ scanIterator (conf , clientBuilder , startKey , version , limit , reverse );
119
148
List <Kvrpcpb .KvPair > result = new ArrayList <>();
120
149
iterator .forEachRemaining (result ::add );
121
150
return result ;
@@ -130,14 +159,27 @@ public List<Kvrpcpb.KvPair> scan(ByteString startKey, ByteString endKey, long ve
130
159
*/
131
160
public List <Kvrpcpb .KvPair > scan (ByteString startKey , long version , int limit )
132
161
throws GrpcException {
133
- Iterator <Kvrpcpb .KvPair > iterator = scanIterator (conf , clientBuilder , startKey , version , limit );
134
- List <Kvrpcpb .KvPair > result = new ArrayList <>();
135
- iterator .forEachRemaining (result ::add );
136
- return result ;
162
+ return scan (startKey , version , limit , false );
163
+ }
164
+
165
+ /**
166
+ * Scan key-value pairs reversively from TiKV in range ('', endKey], maximum to `limit` pairs
167
+ *
168
+ * @param endKey start key, inclusive
169
+ * @param limit limit of kv pairs
170
+ * @return list of key-value pairs in range
171
+ */
172
+ public List <Kvrpcpb .KvPair > reverseScan (ByteString endKey , long version , int limit )
173
+ throws GrpcException {
174
+ return scan (endKey , version , limit , true );
137
175
}
138
176
139
177
public List <Kvrpcpb .KvPair > scan (ByteString startKey , long version ) throws GrpcException {
140
- return scan (startKey , version , Integer .MAX_VALUE );
178
+ return scan (startKey , version , Integer .MAX_VALUE , false );
179
+ }
180
+
181
+ public List <Kvrpcpb .KvPair > reverseScan (ByteString endKey , long version ) throws GrpcException {
182
+ return scan (endKey , version , Integer .MAX_VALUE , true );
141
183
}
142
184
143
185
public synchronized void ingest (List <Pair <ByteString , ByteString >> list ) throws GrpcException {
@@ -264,17 +306,19 @@ private Iterator<Kvrpcpb.KvPair> scanIterator(
264
306
RegionStoreClientBuilder builder ,
265
307
ByteString startKey ,
266
308
ByteString endKey ,
267
- long version ) {
268
- return new ConcreteScanIterator (conf , builder , startKey , endKey , version );
309
+ long version ,
310
+ boolean reverse ) {
311
+ return new ConcreteScanIterator (conf , builder , startKey , endKey , version , reverse );
269
312
}
270
313
271
314
private Iterator <Kvrpcpb .KvPair > scanIterator (
272
315
TiConfiguration conf ,
273
316
RegionStoreClientBuilder builder ,
274
317
ByteString startKey ,
275
318
long version ,
276
- int limit ) {
277
- return new ConcreteScanIterator (conf , builder , startKey , version , limit );
319
+ int limit ,
320
+ boolean reverse ) {
321
+ return new ConcreteScanIterator (conf , builder , startKey , version , limit , reverse );
278
322
}
279
323
280
324
private void doIngest (TiRegion region , List <Pair <ByteString , ByteString >> sortedList )
0 commit comments