Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/main/java/org/tikv/common/TiSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -387,7 +388,16 @@ public ChannelFactory getChannelFactory() {
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;
}

/**
Expand Down Expand Up @@ -578,6 +588,10 @@ private synchronized void cleanAfterTerminated() throws InterruptedException {
if (catalog != null) {
catalog.close();
}

if(switchTiKVModeClient != null) {
switchTiKVModeClient.stopKeepTiKVToImportMode();
}
}

private List<ExecutorService> getExecutorServices() {
Expand Down