Add a flag to determine if TiFlash is enabled (#351)

Signed-off-by: Ankita Wagh <awagh@pinterest.com>
This commit is contained in:
Ankita Wagh 2021-11-30 00:35:41 -08:00 committed by GitHub
parent 093fd5988e
commit e2f10aa2ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 8 deletions

View File

@ -76,6 +76,7 @@ public class ConfigUtils {
public static final String TIKV_KEY_CERT_CHAIN = "tikv.key_cert_chain";
public static final String TIKV_KEY_FILE = "tikv.key_file";
public static final String TIFLASH_ENABLE = "tiflash.enable";
public static final String DEF_PD_ADDRESSES = "127.0.0.1:2379";
public static final String DEF_TIMEOUT = "200ms";
public static final String DEF_TIKV_GRPC_INGEST_TIMEOUT = "200s";
@ -133,4 +134,5 @@ 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 boolean DEF_TIKV_TLS_ENABLE = false;
public static final boolean DEF_TIFLASH_ENABLE = false;
}

View File

@ -692,14 +692,16 @@ public class PDClient extends AbstractGRPCClient<PDBlockingStub, PDStub>
10,
10,
TimeUnit.SECONDS);
tiflashReplicaService =
Executors.newSingleThreadScheduledExecutor(
new ThreadFactoryBuilder()
.setNameFormat("PDClient-tiflash-replica-pool-%d")
.setDaemon(true)
.build());
tiflashReplicaService.scheduleAtFixedRate(
this::updateTiFlashReplicaStatus, 10, 10, TimeUnit.SECONDS);
if (conf.isTiFlashEnabled()) {
tiflashReplicaService =
Executors.newSingleThreadScheduledExecutor(
new ThreadFactoryBuilder()
.setNameFormat("PDClient-tiflash-replica-pool-%d")
.setDaemon(true)
.build());
tiflashReplicaService.scheduleAtFixedRate(
this::updateTiFlashReplicaStatus, 10, 10, TimeUnit.SECONDS);
}
}
static class PDClientWrapper {

View File

@ -121,6 +121,7 @@ public class TiConfiguration implements Serializable {
setIfMissing(TIKV_GRPC_KEEPALIVE_TIME, DEF_TIKV_GRPC_KEEPALIVE_TIME);
setIfMissing(TIKV_GRPC_KEEPALIVE_TIMEOUT, DEF_TIKV_GRPC_KEEPALIVE_TIMEOUT);
setIfMissing(TIKV_TLS_ENABLE, DEF_TIKV_TLS_ENABLE);
setIfMissing(TIFLASH_ENABLE, DEF_TIFLASH_ENABLE);
}
public static void listAll() {
@ -327,6 +328,8 @@ public class TiConfiguration implements Serializable {
private String keyCertChainFile = getOption(TIKV_KEY_CERT_CHAIN).orElse(null);
private String keyFile = getOption(TIKV_KEY_FILE).orElse(null);
private boolean tiFlashEnable = getBoolean(TIFLASH_ENABLE);
private boolean isTest = false;
private int keepaliveTime = getInt(TIKV_GRPC_KEEPALIVE_TIME);
@ -730,6 +733,10 @@ public class TiConfiguration implements Serializable {
this.keepaliveTimeout = timeout;
}
public boolean isTiFlashEnabled() {
return tiFlashEnable;
}
public boolean isTlsEnable() {
return tlsEnable;
}

View File

@ -16,6 +16,7 @@
package org.tikv.common;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.junit.Test;
@ -26,4 +27,10 @@ public class TiConfigurationTest {
TiConfiguration conf = TiConfiguration.createRawDefault();
assertEquals("configFileTest", conf.getDBPrefix());
}
@Test
public void tiFlashDefaultValueTest() {
TiConfiguration conf = TiConfiguration.createRawDefault();
assertFalse(conf.isTiFlashEnabled());
}
}