Skip to content

Commit 5afd1b9

Browse files
address code review
Signed-off-by: marsishandsome <marsishandsome@gmail.com>
1 parent 79d1324 commit 5afd1b9

4 files changed

Lines changed: 12 additions & 13 deletions

File tree

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,34 +161,31 @@ private static VersionInfo getVersionInfo() {
161161
}
162162

163163
private synchronized void warmUp() {
164-
long warmUpStartTime = System.currentTimeMillis();
164+
long warmUpStartTime = System.nanoTime();
165+
BackOffer backOffer = ConcreteBackOffer.newRawKVBackOff();
165166
try {
166167
this.client = getPDClient();
167168
this.regionManager = getRegionManager();
168-
List<Metapb.Store> stores = this.client.getAllStores(ConcreteBackOffer.newGetBackOff());
169+
List<Metapb.Store> stores = this.client.getAllStores(backOffer);
169170
// warm up store cache
170171
for (Metapb.Store store : stores) {
171172
this.regionManager.updateStore(
172-
null,
173-
new TiStore(this.client.getStore(ConcreteBackOffer.newGetBackOff(), store.getId())));
173+
null, new TiStore(this.client.getStore(backOffer, store.getId())));
174174
}
175175

176176
// use scan region to load region cache with limit
177177
ByteString startKey = ByteString.EMPTY;
178178
do {
179179
List<Pdpb.Region> regions =
180180
regionManager.scanRegions(
181-
ConcreteBackOffer.newGetBackOff(),
182-
startKey,
183-
ByteString.EMPTY,
184-
conf.getScanRegionsLimit());
181+
backOffer, startKey, ByteString.EMPTY, conf.getScanRegionsLimit());
185182
if (regions == null || regions.isEmpty()) {
186183
// something went wrong, but the warm-up process could continue
187184
break;
188185
}
189186
for (Pdpb.Region region : regions) {
190187
regionManager.insertRegionToCache(
191-
regionManager.createRegion(region.getRegion(), ConcreteBackOffer.newGetBackOff()));
188+
regionManager.createRegion(region.getRegion(), backOffer));
192189
}
193190
startKey = regions.get(regions.size() - 1).getRegion().getEndKey();
194191
} while (!startKey.isEmpty());
@@ -211,7 +208,8 @@ private synchronized void warmUp() {
211208
logger.info("warm up fails, ignored ", e);
212209
} finally {
213210
logger.info(
214-
String.format("warm up duration %d ms", System.currentTimeMillis() - warmUpStartTime));
211+
String.format(
212+
"warm up duration %d ms", (System.nanoTime() - warmUpStartTime) / 1000_000));
215213
}
216214
}
217215

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +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());
172-
Histogram.Timer backOffTimer = BACKOFF_DURATION.labels(funcType.name()).startTimer();
173171
BackOffFunction backOffFunction =
174172
backOffFunctionMap.computeIfAbsent(funcType, this::createBackOffFunc);
175173

@@ -185,6 +183,8 @@ public boolean canRetryAfterSleep(BackOffFunction.BackOffFuncType funcType, long
185183
}
186184
}
187185

186+
Histogram.Timer backOffTimer = BACKOFF_DURATION.labels(funcType.name()).startTimer();
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
@@ -14,6 +14,7 @@ protected TiConfiguration createTiConfiguration() {
1414
conf.setTest(true);
1515
conf.setEnableAtomicForCAS(true);
1616
conf.setEnableGrpcForward(false);
17+
conf.setEnableAtomicForCAS(true);
1718
return conf;
1819
}
1920
}

0 commit comments

Comments
 (0)