Skip to content

Commit b757b2b

Browse files
continue fix
Signed-off-by: marsishandsome <marsishandsome@gmail.com>
1 parent 087d635 commit b757b2b

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

src/main/java/org/tikv/common/TiSession.java

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,23 +159,46 @@ private static VersionInfo getVersionInfo() {
159159

160160
private synchronized void warmUp() {
161161
long warmUpStartTime = System.currentTimeMillis();
162+
warmUpStore();
163+
warmUpRegion();
164+
warmUpGrpc();
165+
logger.info(
166+
String.format("warm up duration %d ms", System.currentTimeMillis() - warmUpStartTime));
167+
}
168+
169+
private void warmUpStore() {
162170
try {
171+
BackOffer backOffer = ConcreteBackOffer.newRawKVBackOff();
163172
this.client = getPDClient();
164173
this.regionManager = getRegionManager();
165-
List<Metapb.Store> stores = this.client.getAllStores(ConcreteBackOffer.newGetBackOff());
174+
List<Metapb.Store> stores = this.client.getAllStores(backOffer);
166175
// warm up store cache
167176
for (Metapb.Store store : stores) {
168177
this.regionManager.updateStore(
169-
null,
170-
new TiStore(this.client.getStore(ConcreteBackOffer.newGetBackOff(), store.getId())));
178+
null, new TiStore(this.client.getStore(backOffer, store.getId())));
171179
}
172-
ByteString startKey = ByteString.EMPTY;
180+
} catch (Exception e) {
181+
// ignore error
182+
logger.info("warm up store fails, ignored ", e);
183+
}
184+
}
173185

186+
private void warmUpRegion() {
187+
try {
188+
BackOffer backOffer = ConcreteBackOffer.newRawKVBackOff();
189+
ByteString startKey = ByteString.EMPTY;
174190
do {
175-
TiRegion region = regionManager.getRegionByKey(startKey);
191+
TiRegion region = regionManager.getRegionByKey(startKey, backOffer);
176192
startKey = region.getEndKey();
177193
} while (!startKey.isEmpty());
194+
} catch (Exception e) {
195+
// ignore error
196+
logger.info("warm up region fails, ignored ", e);
197+
}
198+
}
178199

200+
private void warmUpGrpc() {
201+
try {
179202
RawKVClient rawKVClient = createRawClient();
180203
ByteString exampleKey = ByteString.EMPTY;
181204
Optional<ByteString> prev = rawKVClient.get(exampleKey);
@@ -190,10 +213,7 @@ private synchronized void warmUp() {
190213
}
191214
} catch (Exception e) {
192215
// ignore error
193-
logger.info("warm up fails, ignored ", e);
194-
} finally {
195-
logger.info(
196-
String.format("warm up duration %d ms", System.currentTimeMillis() - warmUpStartTime));
216+
logger.info("warm up grpc fails, ignored ", e);
197217
}
198218
}
199219

src/main/java/org/tikv/common/region/RegionStoreClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public List<KvPair> scan(
274274
boolean forWrite = false;
275275
while (true) {
276276
// we should refresh region
277-
region = regionManager.getRegionByKey(startKey);
277+
region = regionManager.getRegionByKey(startKey, backOffer);
278278

279279
Supplier<ScanRequest> request =
280280
() ->

src/main/java/org/tikv/common/util/ConcreteBackOffer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ public boolean canRetryAfterSleep(BackOffFunction.BackOffFuncType funcType) {
168168
}
169169

170170
public boolean canRetryAfterSleep(BackOffFunction.BackOffFuncType funcType, long maxSleepMs) {
171-
SlowLogSpan slowLogSpan = getSlowLog().start("backoff " + funcType.name());
172171
Histogram.Timer backOffTimer = BACKOFF_DURATION.labels(funcType.name()).startTimer();
173172
BackOffFunction backOffFunction =
174173
backOffFunctionMap.computeIfAbsent(funcType, this::createBackOffFunc);
@@ -185,6 +184,7 @@ public boolean canRetryAfterSleep(BackOffFunction.BackOffFuncType funcType, long
185184
}
186185
}
187186

187+
SlowLogSpan slowLogSpan = getSlowLog().start("backoff " + funcType.name());
188188
try {
189189
Thread.sleep(sleep);
190190
} catch (InterruptedException e) {

src/test/java/org/tikv/BaseRawKVTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ protected TiConfiguration createTiConfiguration() {
1313
: TiConfiguration.createRawDefault(pdAddrsStr);
1414
conf.setTest(true);
1515
conf.setEnableGrpcForward(false);
16+
conf.setEnableAtomicForCAS(true);
1617
return conf;
1718
}
1819
}

0 commit comments

Comments
 (0)