mirror of https://github.com/tikv/client-java.git
Signed-off-by: ti-srebot <ti-srebot@pingcap.com> Co-authored-by: Liangliang Gu <marsishandsome@gmail.com>
This commit is contained in:
parent
52a101f2e2
commit
b697cef74c
15
README.md
15
README.md
|
|
@ -86,21 +86,6 @@ public class Main {
|
||||||
|
|
||||||
The following includes JVM related parameters.
|
The following includes JVM related parameters.
|
||||||
|
|
||||||
#### tikv.configuration_file
|
|
||||||
- tikv java client configuration file
|
|
||||||
- default: null
|
|
||||||
|
|
||||||
This parameter can be passed by `-Dtikv.configuration_file=/path/to/tikv_client_config.properties`.
|
|
||||||
|
|
||||||
Here is an example of `tikv_client_config.properties`.
|
|
||||||
|
|
||||||
```
|
|
||||||
tikv.grpc.timeout_in_ms=150ms
|
|
||||||
tikv.grpc.forward_timeout_in_ms=200ms
|
|
||||||
tikv.metrics.enable=true
|
|
||||||
tikv.metrics.port=3140
|
|
||||||
```
|
|
||||||
|
|
||||||
#### tikv.pd.addresses
|
#### tikv.pd.addresses
|
||||||
- pd addresses, separated by comma
|
- pd addresses, separated by comma
|
||||||
- default: 127.0.0.1:2379
|
- default: 127.0.0.1:2379
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ import org.tikv.common.util.BackOffer;
|
||||||
import org.tikv.kvproto.Kvrpcpb;
|
import org.tikv.kvproto.Kvrpcpb;
|
||||||
|
|
||||||
public class ConfigUtils {
|
public class ConfigUtils {
|
||||||
public static final String TIKV_CONFIGURATION_FILE = "tikv.configuration_file";
|
public static final String TIKV_CONFIGURATION_FILENAME = "tikv.properties";
|
||||||
|
|
||||||
public static final String TIKV_PD_ADDRESSES = "tikv.pd.addresses";
|
public static final String TIKV_PD_ADDRESSES = "tikv.pd.addresses";
|
||||||
public static final String TIKV_GRPC_TIMEOUT = "tikv.grpc.timeout_in_ms";
|
public static final String TIKV_GRPC_TIMEOUT = "tikv.grpc.timeout_in_ms";
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ package org.tikv.common;
|
||||||
import static org.tikv.common.ConfigUtils.*;
|
import static org.tikv.common.ConfigUtils.*;
|
||||||
|
|
||||||
import io.grpc.Metadata;
|
import io.grpc.Metadata;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
@ -57,20 +57,27 @@ public class TiConfiguration implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadFromConfigurationFile() {
|
private static void loadFromConfigurationFile() {
|
||||||
Optional<String> file = getOption(TIKV_CONFIGURATION_FILE);
|
try (InputStream input =
|
||||||
if (file.isPresent()) {
|
TiConfiguration.class
|
||||||
|
.getClassLoader()
|
||||||
|
.getResourceAsStream(ConfigUtils.TIKV_CONFIGURATION_FILENAME)) {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
try {
|
|
||||||
properties.load(new FileInputStream(file.get()));
|
if (input == null) {
|
||||||
} catch (IOException e) {
|
logger.warn("Unable to find " + ConfigUtils.TIKV_CONFIGURATION_FILENAME);
|
||||||
logger.error("load config file error, path = " + file.get(), e);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info("loading " + ConfigUtils.TIKV_CONFIGURATION_FILENAME);
|
||||||
|
properties.load(input);
|
||||||
for (String key : properties.stringPropertyNames()) {
|
for (String key : properties.stringPropertyNames()) {
|
||||||
if (key.startsWith("tikv.")) {
|
if (key.startsWith("tikv.")) {
|
||||||
String value = properties.getProperty(key);
|
String value = properties.getProperty(key);
|
||||||
setIfMissing(key, value);
|
setIfMissing(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("load config file error", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,7 +121,7 @@ public class TiConfiguration implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void listAll() {
|
public static void listAll() {
|
||||||
logger.warn("static configurations are:" + new ArrayList<>(settings.entrySet()).toString());
|
logger.info("static configurations are:" + new ArrayList<>(settings.entrySet()).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void set(String key, String value) {
|
private static void set(String key, String value) {
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,11 @@ package org.tikv.common;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class TiConfigurationTest {
|
public class TiConfigurationTest {
|
||||||
|
|
||||||
// Set `-Dtikv.configuration_file=src/test/resources/tikv_client_config.properties` to test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void configFileTest() {
|
public void configFileTest() {
|
||||||
TiConfiguration conf = TiConfiguration.createRawDefault();
|
TiConfiguration conf = TiConfiguration.createRawDefault();
|
||||||
assertEquals("configFileTest", conf.getDBPrefix());
|
assertEquals("configFileTest", conf.getDBPrefix());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue