forked from tikv/client-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRawKVClient.java
More file actions
609 lines (545 loc) · 21.9 KB
/
Copy pathRawKVClient.java
File metadata and controls
609 lines (545 loc) · 21.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
/*
* Copyright 2018 PingCAP, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.tikv.raw;
import static org.tikv.common.util.ClientUtils.*;
import com.google.protobuf.ByteString;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.*;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tikv.common.TiConfiguration;
import org.tikv.common.TiSession;
import org.tikv.common.exception.GrpcException;
import org.tikv.common.exception.TiKVException;
import org.tikv.common.key.Key;
import org.tikv.common.operation.iterator.RawScanIterator;
import org.tikv.common.region.RegionStoreClient;
import org.tikv.common.region.RegionStoreClient.RegionStoreClientBuilder;
import org.tikv.common.region.TiRegion;
import org.tikv.common.util.*;
import org.tikv.kvproto.Kvrpcpb.KvPair;
public class RawKVClient implements AutoCloseable {
private final RegionStoreClientBuilder clientBuilder;
private final TiConfiguration conf;
private final ExecutorService batchGetThreadPool;
private final ExecutorService batchPutThreadPool;
private final ExecutorService batchScanThreadPool;
private final ExecutorService deleteRangeThreadPool;
private static final Logger logger = LoggerFactory.getLogger(RawKVClient.class);
private static final int MAX_RETRY_LIMIT = 20;
// https://www.github.com/pingcap/tidb/blob/master/store/tikv/rawkv.go
private static final int MAX_RAW_SCAN_LIMIT = 10240;
private static final int RAW_BATCH_PUT_SIZE = 1024 * 1024; // 1 MB
private static final int RAW_BATCH_GET_SIZE = 16 * 1024; // 16 K
private static final int RAW_BATCH_SCAN_SIZE = 16;
private static final int RAW_BATCH_PAIR_COUNT = 512;
private static final TiKVException ERR_RETRY_LIMIT_EXCEEDED =
new GrpcException("retry is exhausted. retry exceeds " + MAX_RETRY_LIMIT + "attempts");
private static final TiKVException ERR_MAX_SCAN_LIMIT_EXCEEDED =
new TiKVException("limit should be less than MAX_RAW_SCAN_LIMIT");
public RawKVClient(TiSession session, RegionStoreClientBuilder clientBuilder) {
Objects.requireNonNull(session, "session is null");
Objects.requireNonNull(clientBuilder, "clientBuilder is null");
this.conf = session.getConf();
this.clientBuilder = clientBuilder;
this.batchGetThreadPool = session.getThreadPoolForBatchGet();
this.batchPutThreadPool = session.getThreadPoolForBatchPut();
this.batchScanThreadPool = session.getThreadPoolForBatchScan();
this.deleteRangeThreadPool = session.getThreadPoolForDeleteRange();
}
@Override
public void close() {}
/**
* Put a raw key-value pair to TiKV
*
* @param key raw key
* @param value raw value
*/
public void put(ByteString key, ByteString value) {
put(key, value, 0);
}
/**
* Put a raw key-value pair to TiKV
*
* @param key raw key
* @param value raw value
* @param ttl the ttl of the key (in seconds), 0 means the key will never be outdated
*/
public void put(ByteString key, ByteString value, long ttl) {
BackOffer backOffer = defaultBackOff();
for (int i = 0; i < MAX_RETRY_LIMIT; i++) {
RegionStoreClient client = clientBuilder.build(key);
try {
client.rawPut(backOffer, key, value, ttl);
return;
} catch (final TiKVException e) {
backOffer.doBackOff(BackOffFunction.BackOffFuncType.BoRegionMiss, e);
}
}
throw ERR_RETRY_LIMIT_EXCEEDED;
}
/**
* Put a set of raw key-value pair to TiKV
*
* @param kvPairs kvPairs
*/
public void batchPut(Map<ByteString, ByteString> kvPairs) {
batchPut(kvPairs, 0);
}
/**
* Put a set of raw key-value pair to TiKV
*
* @param kvPairs kvPairs
* @param ttl the TTL of keys to be put (in seconds), 0 means the keys will never be outdated
*/
public void batchPut(Map<ByteString, ByteString> kvPairs, long ttl) {
doSendBatchPut(ConcreteBackOffer.newRawKVBackOff(), kvPairs, ttl);
}
private void batchPut(BackOffer backOffer, List<ByteString> keys, List<ByteString> values) {
batchPut(backOffer, keys, values, 0);
}
private void batchPut(
BackOffer backOffer, List<ByteString> keys, List<ByteString> values, long ttl) {
Map<ByteString, ByteString> keysToValues = mapKeysToValues(keys, values);
doSendBatchPut(backOffer, keysToValues, ttl);
}
/**
* Get a raw key-value pair from TiKV if key exists
*
* @param key raw key
* @return a ByteString value if key exists, ByteString.EMPTY if key does not exist
*/
public ByteString get(ByteString key) {
BackOffer backOffer = defaultBackOff();
for (int i = 0; i < MAX_RETRY_LIMIT; i++) {
RegionStoreClient client = clientBuilder.build(key);
try {
return client.rawGet(defaultBackOff(), key);
} catch (final TiKVException e) {
backOffer.doBackOff(BackOffFunction.BackOffFuncType.BoRegionMiss, e);
}
}
throw ERR_RETRY_LIMIT_EXCEEDED;
}
/**
* Get a list of raw key-value pair from TiKV if key exists
*
* @param keys list of raw key
* @return a ByteString value if key exists, ByteString.EMPTY if key does not exist
*/
public List<KvPair> batchGet(List<ByteString> keys) {
BackOffer backOffer = defaultBackOff();
return doSendBatchGet(backOffer, keys);
}
public List<List<KvPair>> batchScan(List<ScanOption> ranges) {
if (ranges.isEmpty()) {
return new ArrayList<>();
}
ExecutorCompletionService<Pair<Integer, List<KvPair>>> completionService =
new ExecutorCompletionService<>(batchScanThreadPool);
int num = 0;
for (ScanOption scanOption : ranges) {
int i = num;
completionService.submit(() -> Pair.create(i, scan(scanOption)));
++num;
}
List<List<KvPair>> scanResults = new ArrayList<>();
for (int i = 0; i < num; i++) {
scanResults.add(new ArrayList<>());
}
for (int i = 0; i < num; i++) {
try {
Pair<Integer, List<KvPair>> scanResult =
completionService.take().get(BackOffer.RAWKV_MAX_BACKOFF, TimeUnit.SECONDS);
scanResults.set(scanResult.first, scanResult.second);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new TiKVException("Current thread interrupted.", e);
} catch (TimeoutException e) {
throw new TiKVException("TimeOut Exceeded for current operation. ", e);
} catch (ExecutionException e) {
throw new TiKVException("Execution exception met.", e);
}
}
return scanResults;
}
/**
* Scan raw key-value pairs from TiKV in range [startKey, endKey)
*
* @param startKey raw start key, inclusive
* @param endKey raw end key, exclusive
* @param limit limit of key-value pairs scanned, should be less than {@link #MAX_RAW_SCAN_LIMIT}
* @return list of key-value pairs in range
*/
public List<KvPair> scan(ByteString startKey, ByteString endKey, int limit) {
return scan(startKey, endKey, limit, false);
}
/**
* Scan raw key-value pairs from TiKV in range [startKey, endKey)
*
* @param startKey raw start key, inclusive
* @param endKey raw end key, exclusive
* @param limit limit of key-value pairs scanned, should be less than {@link #MAX_RAW_SCAN_LIMIT}
* @param keyOnly whether to scan in key-only mode
* @return list of key-value pairs in range
*/
public List<KvPair> scan(ByteString startKey, ByteString endKey, int limit, boolean keyOnly) {
Iterator<KvPair> iterator =
rawScanIterator(conf, clientBuilder, startKey, endKey, limit, keyOnly);
List<KvPair> result = new ArrayList<>();
iterator.forEachRemaining(result::add);
return result;
}
/**
* Scan raw key-value pairs from TiKV in range [startKey, ♾)
*
* @param startKey raw start key, inclusive
* @param limit limit of key-value pairs scanned, should be less than {@link #MAX_RAW_SCAN_LIMIT}
* @return list of key-value pairs in range
*/
public List<KvPair> scan(ByteString startKey, int limit) {
return scan(startKey, limit, false);
}
/**
* Scan raw key-value pairs from TiKV in range [startKey, ♾)
*
* @param startKey raw start key, inclusive
* @param limit limit of key-value pairs scanned, should be less than {@link #MAX_RAW_SCAN_LIMIT}
* @param keyOnly whether to scan in key-only mode
* @return list of key-value pairs in range
*/
public List<KvPair> scan(ByteString startKey, int limit, boolean keyOnly) {
return scan(startKey, ByteString.EMPTY, limit, keyOnly);
}
/**
* Scan all raw key-value pairs from TiKV in range [startKey, endKey)
*
* @param startKey raw start key, inclusive
* @param endKey raw end key, exclusive
* @return list of key-value pairs in range
*/
public List<KvPair> scan(ByteString startKey, ByteString endKey) {
return scan(startKey, endKey, false);
}
/**
* Scan all raw key-value pairs from TiKV in range [startKey, endKey)
*
* @param startKey raw start key, inclusive
* @param endKey raw end key, exclusive
* @param keyOnly whether to scan in key-only mode
* @return list of key-value pairs in range
*/
public List<KvPair> scan(ByteString startKey, ByteString endKey, boolean keyOnly) {
List<KvPair> result = new ArrayList<>();
while (true) {
Iterator<KvPair> iterator =
rawScanIterator(conf, clientBuilder, startKey, endKey, conf.getScanBatchSize(), keyOnly);
if (!iterator.hasNext()) {
break;
}
iterator.forEachRemaining(result::add);
startKey = Key.toRawKey(result.get(result.size() - 1).getKey()).next().toByteString();
}
return result;
}
private List<KvPair> scan(ScanOption scanOption) {
ByteString startKey = scanOption.getStartKey();
ByteString endKey = scanOption.getEndKey();
int limit = scanOption.getLimit();
boolean keyOnly = scanOption.isKeyOnly();
return scan(startKey, endKey, limit, keyOnly);
}
/**
* Scan keys with prefix
*
* @param prefixKey prefix key
* @param limit limit of keys retrieved
* @param keyOnly whether to scan in keyOnly mode
* @return kvPairs with the specified prefix
*/
public List<KvPair> scanPrefix(ByteString prefixKey, int limit, boolean keyOnly) {
return scan(prefixKey, Key.toRawKey(prefixKey).nextPrefix().toByteString(), limit, keyOnly);
}
public List<KvPair> scanPrefix(ByteString prefixKey) {
return scan(prefixKey, Key.toRawKey(prefixKey).nextPrefix().toByteString());
}
public List<KvPair> scanPrefix(ByteString prefixKey, boolean keyOnly) {
return scan(prefixKey, Key.toRawKey(prefixKey).nextPrefix().toByteString(), keyOnly);
}
/**
* Delete a raw key-value pair from TiKV if key exists
*
* @param key raw key to be deleted
*/
public void delete(ByteString key) {
BackOffer backOffer = defaultBackOff();
while (true) {
RegionStoreClient client = clientBuilder.build(key);
try {
client.rawDelete(defaultBackOff(), key);
return;
} catch (final TiKVException e) {
backOffer.doBackOff(BackOffFunction.BackOffFuncType.BoRegionMiss, e);
}
}
}
/**
* Delete all raw key-value pairs in range [startKey, endKey) from TiKV
*
* <p>Cautious, this API cannot be used concurrently, if multiple clients write keys into this
* range along with deleteRange API, the result will be undefined.
*
* @param startKey raw start key to be deleted
* @param endKey raw start key to be deleted
*/
public synchronized void deleteRange(ByteString startKey, ByteString endKey) {
BackOffer backOffer = defaultBackOff();
doSendDeleteRange(backOffer, startKey, endKey);
}
/**
* Delete all raw key-value pairs with the prefix `key` from TiKV
*
* <p>Cautious, this API cannot be used concurrently, if multiple clients write keys into this
* range along with deleteRange API, the result will be undefined.
*
* @param key prefix of keys to be deleted
*/
public synchronized void deletePrefix(ByteString key) {
ByteString endKey = Key.toRawKey(key).nextPrefix().toByteString();
deleteRange(key, endKey);
}
private void doSendBatchPut(BackOffer backOffer, Map<ByteString, ByteString> kvPairs, long ttl) {
ExecutorCompletionService<Object> completionService =
new ExecutorCompletionService<>(batchPutThreadPool);
Map<TiRegion, List<ByteString>> groupKeys = groupKeysByRegion(kvPairs.keySet());
List<Batch> batches = new ArrayList<>();
for (Map.Entry<TiRegion, List<ByteString>> entry : groupKeys.entrySet()) {
appendBatches(
batches,
entry.getKey(),
entry.getValue(),
entry.getValue().stream().map(kvPairs::get).collect(Collectors.toList()),
RAW_BATCH_PUT_SIZE);
}
for (Batch batch : batches) {
BackOffer singleBatchBackOffer = ConcreteBackOffer.create(backOffer);
completionService.submit(
() -> doSendBatchPutInBatchesWithRetry(singleBatchBackOffer, batch, ttl));
}
getTasks(completionService, batches, BackOffer.RAWKV_MAX_BACKOFF);
}
private Object doSendBatchPutInBatchesWithRetry(BackOffer backOffer, Batch batch, long ttl) {
TiRegion oldRegion = batch.region;
TiRegion currentRegion =
clientBuilder.getRegionManager().getRegionByKey(oldRegion.getStartKey());
if (oldRegion.equals(currentRegion)) {
try (RegionStoreClient client = clientBuilder.build(batch.region); ) {
client.rawBatchPut(backOffer, batch, ttl);
return null;
} catch (final TiKVException e) {
// TODO: any elegant way to re-split the ranges if fails?
backOffer.doBackOff(BackOffFunction.BackOffFuncType.BoRegionMiss, e);
logger.warn("ReSplitting ranges for BatchPutRequest");
// retry
return doSendBatchPutWithRefetchRegion(backOffer, batch, ttl);
}
} else {
return doSendBatchPutWithRefetchRegion(backOffer, batch, ttl);
}
}
private Object doSendBatchPutWithRefetchRegion(BackOffer backOffer, Batch batch, long ttl) {
Map<TiRegion, List<ByteString>> groupKeys = groupKeysByRegion(batch.keys);
List<Batch> retryBatches = new ArrayList<>();
for (Map.Entry<TiRegion, List<ByteString>> entry : groupKeys.entrySet()) {
appendBatches(
retryBatches,
entry.getKey(),
entry.getValue(),
entry.getValue().stream().map(batch.map::get).collect(Collectors.toList()),
RAW_BATCH_PUT_SIZE);
}
for (Batch retryBatch : retryBatches) {
// recursive calls
doSendBatchPutInBatchesWithRetry(backOffer, retryBatch, ttl);
}
return null;
}
private List<KvPair> doSendBatchGet(BackOffer backOffer, List<ByteString> keys) {
ExecutorCompletionService<List<KvPair>> completionService =
new ExecutorCompletionService<>(batchGetThreadPool);
Map<TiRegion, List<ByteString>> groupKeys = groupKeysByRegion(keys);
List<Batch> batches = new ArrayList<>();
for (Map.Entry<TiRegion, List<ByteString>> entry : groupKeys.entrySet()) {
appendBatches(batches, entry.getKey(), entry.getValue(), RAW_BATCH_GET_SIZE);
}
for (Batch batch : batches) {
BackOffer singleBatchBackOffer = ConcreteBackOffer.create(backOffer);
completionService.submit(() -> doSendBatchGetInBatchesWithRetry(singleBatchBackOffer, batch));
}
return getKvPairs(completionService, batches, BackOffer.RAWKV_MAX_BACKOFF);
}
private List<KvPair> doSendBatchGetInBatchesWithRetry(BackOffer backOffer, Batch batch) {
TiRegion oldRegion = batch.region;
TiRegion currentRegion =
clientBuilder.getRegionManager().getRegionByKey(oldRegion.getStartKey());
if (oldRegion.equals(currentRegion)) {
RegionStoreClient client = clientBuilder.build(batch.region);
try {
return client.rawBatchGet(backOffer, batch.keys);
} catch (final TiKVException e) {
backOffer.doBackOff(BackOffFunction.BackOffFuncType.BoRegionMiss, e);
clientBuilder.getRegionManager().invalidateRegion(batch.region.getId());
logger.warn("ReSplitting ranges for BatchGetRequest", e);
// retry
return doSendBatchGetWithRefetchRegion(backOffer, batch);
}
} else {
return doSendBatchGetWithRefetchRegion(backOffer, batch);
}
}
private List<KvPair> doSendBatchGetWithRefetchRegion(BackOffer backOffer, Batch batch) {
Map<TiRegion, List<ByteString>> groupKeys = groupKeysByRegion(batch.keys);
List<Batch> retryBatches = new ArrayList<>();
for (Map.Entry<TiRegion, List<ByteString>> entry : groupKeys.entrySet()) {
appendBatches(retryBatches, entry.getKey(), entry.getValue(), RAW_BATCH_GET_SIZE);
}
ArrayList<KvPair> results = new ArrayList<>();
for (Batch retryBatch : retryBatches) {
// recursive calls
List<KvPair> batchResult = doSendBatchGetInBatchesWithRetry(backOffer, retryBatch);
results.addAll(batchResult);
}
return results;
}
private ByteString calcKeyByCondition(boolean condition, ByteString key1, ByteString key2) {
if (condition) {
return key1;
}
return key2;
}
private void doSendDeleteRange(BackOffer backOffer, ByteString startKey, ByteString endKey) {
ExecutorCompletionService<Object> completionService =
new ExecutorCompletionService<>(deleteRangeThreadPool);
List<TiRegion> regions = fetchRegionsFromRange(startKey, endKey);
for (int i = 0; i < regions.size(); i++) {
TiRegion region = regions.get(i);
BackOffer singleBatchBackOffer = ConcreteBackOffer.create(backOffer);
ByteString start = calcKeyByCondition(i == 0, startKey, region.getStartKey());
ByteString end = calcKeyByCondition(i == regions.size() - 1, endKey, region.getEndKey());
completionService.submit(
() -> doSendDeleteRangeWithRetry(singleBatchBackOffer, region, start, end));
}
for (int i = 0; i < regions.size(); i++) {
try {
completionService.take().get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new TiKVException("Current thread interrupted.", e);
} catch (ExecutionException e) {
throw new TiKVException("Execution exception met.", e);
}
}
}
private Object doSendDeleteRangeWithRetry(
BackOffer backOffer, TiRegion region, ByteString startKey, ByteString endKey) {
TiRegion currentRegion = clientBuilder.getRegionManager().getRegionByKey(region.getStartKey());
if (region.equals(currentRegion)) {
RegionStoreClient client = clientBuilder.build(region);
try {
client.rawDeleteRange(backOffer, startKey, endKey);
return null;
} catch (final TiKVException e) {
backOffer.doBackOff(BackOffFunction.BackOffFuncType.BoRegionMiss, e);
clientBuilder.getRegionManager().invalidateRegion(region.getId());
logger.warn("ReSplitting ranges for BatchDeleteRangeRequest", e);
// retry
return doSendDeleteRangeWithRefetchRegion(backOffer, startKey, endKey);
}
} else {
return doSendDeleteRangeWithRefetchRegion(backOffer, startKey, endKey);
}
}
private Object doSendDeleteRangeWithRefetchRegion(
BackOffer backOffer, ByteString startKey, ByteString endKey) {
List<TiRegion> regions = fetchRegionsFromRange(startKey, endKey);
for (int i = 0; i < regions.size(); i++) {
TiRegion region = regions.get(i);
ByteString start = calcKeyByCondition(i == 0, startKey, region.getStartKey());
ByteString end = calcKeyByCondition(i == regions.size() - 1, endKey, region.getEndKey());
doSendDeleteRangeWithRetry(backOffer, region, start, end);
}
return null;
}
/**
* Group by list of keys according to its region
*
* @param keys keys
* @return a mapping of keys and their region
*/
private Map<TiRegion, List<ByteString>> groupKeysByRegion(Set<ByteString> keys) {
Map<TiRegion, List<ByteString>> groups = new HashMap<>();
TiRegion lastRegion = null;
for (ByteString key : keys) {
if (lastRegion == null || !lastRegion.contains(key)) {
lastRegion = clientBuilder.getRegionManager().getRegionByKey(key);
}
groups.computeIfAbsent(lastRegion, k -> new ArrayList<>()).add(key);
}
return groups;
}
private Map<TiRegion, List<ByteString>> groupKeysByRegion(List<ByteString> keys) {
return keys.stream()
.collect(Collectors.groupingBy(clientBuilder.getRegionManager()::getRegionByKey));
}
private static Map<ByteString, ByteString> mapKeysToValues(
List<ByteString> keys, List<ByteString> values) {
Map<ByteString, ByteString> map = new HashMap<>();
for (int i = 0; i < keys.size(); i++) {
map.put(keys.get(i), values.get(i));
}
return map;
}
private List<TiRegion> fetchRegionsFromRange(ByteString startKey, ByteString endKey) {
List<TiRegion> regions = new ArrayList<>();
while (FastByteComparisons.compareTo(startKey.toByteArray(), endKey.toByteArray()) < 0) {
TiRegion currentRegion = clientBuilder.getRegionManager().getRegionByKey(startKey);
regions.add(currentRegion);
startKey = currentRegion.getEndKey();
}
return regions;
}
private Iterator<KvPair> rawScanIterator(
TiConfiguration conf,
RegionStoreClientBuilder builder,
ByteString startKey,
ByteString endKey,
int limit,
boolean keyOnly) {
if (limit > MAX_RAW_SCAN_LIMIT) {
throw ERR_MAX_SCAN_LIMIT_EXCEEDED;
}
return new RawScanIterator(conf, builder, startKey, endKey, limit, keyOnly);
}
private BackOffer defaultBackOff() {
return ConcreteBackOffer.newRawKVBackOff();
}
}