refactor TiSession.getSwitchTiKVModeClient (#240)

Signed-off-by: marsishandsome <marsishandsome@gmail.com>
This commit is contained in:
Liangliang Gu 2021-07-29 19:52:24 +08:00 committed by GitHub
parent 5545270f15
commit 7ecacd7b20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 1 deletions

View File

@ -71,6 +71,7 @@ public class TiSession implements AutoCloseable {
private volatile RegionStoreClient.RegionStoreClientBuilder clientBuilder;
private volatile ImporterStoreClient.ImporterStoreClientBuilder importerClientBuilder;
private volatile boolean isClosed = false;
private volatile SwitchTiKVModeClient switchTiKVModeClient;
private MetricsServer metricsServer;
private static final int MAX_SPLIT_REGION_STACK_DEPTH = 6;
@ -387,7 +388,16 @@ public class TiSession implements AutoCloseable {
public SwitchTiKVModeClient getSwitchTiKVModeClient() {
checkIsClosed();
return new SwitchTiKVModeClient(getPDClient(), getImporterRegionStoreClientBuilder());
SwitchTiKVModeClient res = switchTiKVModeClient;
if (res == null) {
synchronized (this) {
if (switchTiKVModeClient == null) {
switchTiKVModeClient = new SwitchTiKVModeClient(getPDClient(), getImporterRegionStoreClientBuilder());
}
res = switchTiKVModeClient;
}
}
return res;
}
/**
@ -578,6 +588,10 @@ public class TiSession implements AutoCloseable {
if (catalog != null) {
catalog.close();
}
if(switchTiKVModeClient != null) {
switchTiKVModeClient.stopKeepTiKVToImportMode();
}
}
private List<ExecutorService> getExecutorServices() {