mirror of https://github.com/tikv/client-java.git
parent
c95479e8ad
commit
d8841e7fed
|
|
@ -32,6 +32,7 @@ public class ConfigUtils {
|
|||
public static final String TIKV_GRPC_MAX_FRAME_SIZE = "tikv.grpc.max_frame_size";
|
||||
public static final String TIKV_GRPC_KEEPALIVE_TIME = "tikv.grpc.keepalive_time";
|
||||
public static final String TIKV_GRPC_KEEPALIVE_TIMEOUT = "tikv.grpc.keepalive_timeout";
|
||||
public static final String TIKV_GRPC_IDLE_TIMEOUT = "tikv.grpc.idle_timeout";
|
||||
|
||||
public static final String TIKV_INDEX_SCAN_BATCH_SIZE = "tikv.index.scan_batch_size";
|
||||
public static final String TIKV_INDEX_SCAN_CONCURRENCY = "tikv.index.scan_concurrency";
|
||||
|
|
@ -171,6 +172,7 @@ public class ConfigUtils {
|
|||
|
||||
public static final int DEF_TIKV_GRPC_KEEPALIVE_TIME = 10;
|
||||
public static final int DEF_TIKV_GRPC_KEEPALIVE_TIMEOUT = 3;
|
||||
public static final int DEF_TIKV_GRPC_IDLE_TIMEOUT = 60;
|
||||
public static final boolean DEF_TIKV_TLS_ENABLE = false;
|
||||
public static final boolean DEF_TIFLASH_ENABLE = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ public class TiConfiguration implements Serializable {
|
|||
setIfMissing(TIKV_RAWKV_DEFAULT_BACKOFF_IN_MS, DEF_TIKV_RAWKV_DEFAULT_BACKOFF_IN_MS);
|
||||
setIfMissing(TIKV_GRPC_KEEPALIVE_TIME, DEF_TIKV_GRPC_KEEPALIVE_TIME);
|
||||
setIfMissing(TIKV_GRPC_KEEPALIVE_TIMEOUT, DEF_TIKV_GRPC_KEEPALIVE_TIMEOUT);
|
||||
setIfMissing(TIKV_GRPC_IDLE_TIMEOUT, DEF_TIKV_GRPC_IDLE_TIMEOUT);
|
||||
setIfMissing(TIKV_TLS_ENABLE, DEF_TIKV_TLS_ENABLE);
|
||||
setIfMissing(TIFLASH_ENABLE, DEF_TIFLASH_ENABLE);
|
||||
setIfMissing(TIKV_RAWKV_READ_TIMEOUT_IN_MS, DEF_TIKV_RAWKV_READ_TIMEOUT_IN_MS);
|
||||
|
|
@ -373,6 +374,7 @@ public class TiConfiguration implements Serializable {
|
|||
|
||||
private int keepaliveTime = getInt(TIKV_GRPC_KEEPALIVE_TIME);
|
||||
private int keepaliveTimeout = getInt(TIKV_GRPC_KEEPALIVE_TIMEOUT);
|
||||
private int idleTimeout = getInt(TIKV_GRPC_IDLE_TIMEOUT);
|
||||
|
||||
private boolean circuitBreakEnable = getBoolean(TiKV_CIRCUIT_BREAK_ENABLE);
|
||||
private int circuitBreakAvailabilityWindowInSeconds =
|
||||
|
|
@ -782,6 +784,14 @@ public class TiConfiguration implements Serializable {
|
|||
this.keepaliveTimeout = timeout;
|
||||
}
|
||||
|
||||
public int getIdleTimeout() {
|
||||
return idleTimeout;
|
||||
}
|
||||
|
||||
public void setIdleTimeout(int timeout) {
|
||||
this.idleTimeout = timeout;
|
||||
}
|
||||
|
||||
public boolean isTiFlashEnabled() {
|
||||
return tiFlashEnable;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,11 +82,15 @@ public class TiSession implements AutoCloseable {
|
|||
conf.getMaxFrameSize(),
|
||||
conf.getKeepaliveTime(),
|
||||
conf.getKeepaliveTimeout(),
|
||||
conf.getIdleTimeout(),
|
||||
conf.getTrustCertCollectionFile(),
|
||||
conf.getKeyCertChainFile(),
|
||||
conf.getKeyFile())
|
||||
: new ChannelFactory(
|
||||
conf.getMaxFrameSize(), conf.getKeepaliveTime(), conf.getKeepaliveTimeout());
|
||||
conf.getMaxFrameSize(),
|
||||
conf.getKeepaliveTime(),
|
||||
conf.getKeepaliveTimeout(),
|
||||
conf.getIdleTimeout());
|
||||
|
||||
this.client = PDClient.createRaw(conf, channelFactory);
|
||||
this.enableGrpcForward = conf.getEnableGrpcForward();
|
||||
|
|
|
|||
|
|
@ -36,13 +36,16 @@ public class ChannelFactory implements AutoCloseable {
|
|||
private final int maxFrameSize;
|
||||
private final int keepaliveTime;
|
||||
private final int keepaliveTimeout;
|
||||
private final int idleTimeout;
|
||||
private final ConcurrentHashMap<String, ManagedChannel> connPool = new ConcurrentHashMap<>();
|
||||
private final SslContextBuilder sslContextBuilder;
|
||||
|
||||
public ChannelFactory(int maxFrameSize, int keepaliveTime, int keepaliveTimeout) {
|
||||
public ChannelFactory(
|
||||
int maxFrameSize, int keepaliveTime, int keepaliveTimeout, int idleTimeout) {
|
||||
this.maxFrameSize = maxFrameSize;
|
||||
this.keepaliveTime = keepaliveTime;
|
||||
this.keepaliveTimeout = keepaliveTimeout;
|
||||
this.idleTimeout = idleTimeout;
|
||||
this.sslContextBuilder = null;
|
||||
}
|
||||
|
||||
|
|
@ -50,12 +53,14 @@ public class ChannelFactory implements AutoCloseable {
|
|||
int maxFrameSize,
|
||||
int keepaliveTime,
|
||||
int keepaliveTimeout,
|
||||
int idleTimeout,
|
||||
String trustCertCollectionFilePath,
|
||||
String keyCertChainFilePath,
|
||||
String keyFilePath) {
|
||||
this.maxFrameSize = maxFrameSize;
|
||||
this.keepaliveTime = keepaliveTime;
|
||||
this.keepaliveTimeout = keepaliveTimeout;
|
||||
this.idleTimeout = idleTimeout;
|
||||
this.sslContextBuilder =
|
||||
getSslContextBuilder(trustCertCollectionFilePath, keyCertChainFilePath, keyFilePath);
|
||||
}
|
||||
|
|
@ -97,7 +102,7 @@ public class ChannelFactory implements AutoCloseable {
|
|||
.keepAliveTime(keepaliveTime, TimeUnit.SECONDS)
|
||||
.keepAliveTimeout(keepaliveTimeout, TimeUnit.SECONDS)
|
||||
.keepAliveWithoutCalls(true)
|
||||
.idleTimeout(60, TimeUnit.SECONDS);
|
||||
.idleTimeout(idleTimeout, TimeUnit.SECONDS);
|
||||
|
||||
if (sslContextBuilder == null) {
|
||||
return builder.usePlaintext().build();
|
||||
|
|
|
|||
|
|
@ -33,4 +33,15 @@ public class TiConfigurationTest {
|
|||
TiConfiguration conf = TiConfiguration.createRawDefault();
|
||||
assertFalse(conf.isTiFlashEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGrpcIdleTimeoutValue() {
|
||||
TiConfiguration conf = TiConfiguration.createDefault();
|
||||
// default value
|
||||
assertEquals(TiConfiguration.getInt(ConfigUtils.TIKV_GRPC_IDLE_TIMEOUT), conf.getIdleTimeout());
|
||||
// new value
|
||||
int newValue = 100000;
|
||||
conf.setIdleTimeout(newValue);
|
||||
assertEquals(newValue, conf.getIdleTimeout());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue