diff --git a/src/main/java/org/tikv/common/TiConfiguration.java b/src/main/java/org/tikv/common/TiConfiguration.java index 9d79e05964..22501ecc7b 100644 --- a/src/main/java/org/tikv/common/TiConfiguration.java +++ b/src/main/java/org/tikv/common/TiConfiguration.java @@ -360,12 +360,12 @@ public class TiConfiguration implements Serializable { private int rawKVBatchWriteTimeoutInMS = getInt(TIKV_RAWKV_BATCH_WRITE_TIMEOUT_IN_MS); private int rawKVScanTimeoutInMS = getInt(TIKV_RAWKV_SCAN_TIMEOUT_IN_MS); private int rawKVCleanTimeoutInMS = getInt(TIKV_RAWKV_CLEAN_TIMEOUT_IN_MS); - private Optional rawKVReadSlowLogInMS = getIntOption(TIKV_RAWKV_READ_SLOWLOG_IN_MS); - private Optional rawKVWriteSlowLogInMS = getIntOption(TIKV_RAWKV_WRITE_SLOWLOG_IN_MS); - private Optional rawKVBatchReadSlowLogInMS = - getIntOption(TIKV_RAWKV_BATCH_READ_SLOWLOG_IN_MS); - private Optional rawKVBatchWriteSlowLogInMS = - getIntOption(TIKV_RAWKV_BATCH_WRITE_SLOWLOG_IN_MS); + private Integer rawKVReadSlowLogInMS = getIntOption(TIKV_RAWKV_READ_SLOWLOG_IN_MS).orElse(null); + private Integer rawKVWriteSlowLogInMS = getIntOption(TIKV_RAWKV_WRITE_SLOWLOG_IN_MS).orElse(null); + private Integer rawKVBatchReadSlowLogInMS = + getIntOption(TIKV_RAWKV_BATCH_READ_SLOWLOG_IN_MS).orElse(null); + private Integer rawKVBatchWriteSlowLogInMS = + getIntOption(TIKV_RAWKV_BATCH_WRITE_SLOWLOG_IN_MS).orElse(null); private int rawKVScanSlowLogInMS = getInt(TIKV_RAWKV_SCAN_SLOWLOG_IN_MS); private boolean tlsEnable = getBoolean(TIKV_TLS_ENABLE); @@ -956,35 +956,35 @@ public class TiConfiguration implements Serializable { } public Integer getRawKVReadSlowLogInMS() { - return rawKVReadSlowLogInMS.orElse((int) (getTimeout() * 2)); + return Optional.ofNullable(rawKVReadSlowLogInMS).orElse((int) (getTimeout() * 2)); } public void setRawKVReadSlowLogInMS(Integer rawKVReadSlowLogInMS) { - this.rawKVReadSlowLogInMS = Optional.of(rawKVReadSlowLogInMS); + this.rawKVReadSlowLogInMS = rawKVReadSlowLogInMS; } public Integer getRawKVWriteSlowLogInMS() { - return rawKVWriteSlowLogInMS.orElse((int) (getTimeout() * 2)); + return Optional.ofNullable(rawKVWriteSlowLogInMS).orElse((int) (getTimeout() * 2)); } public void setRawKVWriteSlowLogInMS(Integer rawKVWriteSlowLogInMS) { - this.rawKVWriteSlowLogInMS = Optional.of(rawKVWriteSlowLogInMS); + this.rawKVWriteSlowLogInMS = rawKVWriteSlowLogInMS; } public Integer getRawKVBatchReadSlowLogInMS() { - return rawKVBatchReadSlowLogInMS.orElse((int) (getTimeout() * 2)); + return Optional.ofNullable(rawKVBatchReadSlowLogInMS).orElse((int) (getTimeout() * 2)); } public void setRawKVBatchReadSlowLogInMS(Integer rawKVBatchReadSlowLogInMS) { - this.rawKVBatchReadSlowLogInMS = Optional.of(rawKVBatchReadSlowLogInMS); + this.rawKVBatchReadSlowLogInMS = rawKVBatchReadSlowLogInMS; } public Integer getRawKVBatchWriteSlowLogInMS() { - return rawKVBatchWriteSlowLogInMS.orElse((int) (getTimeout() * 2)); + return Optional.ofNullable(rawKVBatchWriteSlowLogInMS).orElse((int) (getTimeout() * 2)); } public void setRawKVBatchWriteSlowLogInMS(Integer rawKVBatchWriteSlowLogInMS) { - this.rawKVBatchWriteSlowLogInMS = Optional.of(rawKVBatchWriteSlowLogInMS); + this.rawKVBatchWriteSlowLogInMS = rawKVBatchWriteSlowLogInMS; } public int getRawKVScanSlowLogInMS() { diff --git a/src/test/java/org/tikv/common/TiConfigurationTest.java b/src/test/java/org/tikv/common/TiConfigurationTest.java index ead6fe36ea..e266c6972c 100644 --- a/src/test/java/org/tikv/common/TiConfigurationTest.java +++ b/src/test/java/org/tikv/common/TiConfigurationTest.java @@ -20,6 +20,9 @@ import static org.junit.Assert.assertFalse; import static org.tikv.common.ConfigUtils.TIKV_GRPC_HEALTH_CHECK_TIMEOUT; import static org.tikv.common.ConfigUtils.TIKV_HEALTH_CHECK_PERIOD_DURATION; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectOutputStream; import org.junit.Assert; import org.junit.Test; @@ -78,4 +81,23 @@ public class TiConfigurationTest { TiConfiguration conf = TiConfiguration.createRawDefault(); assertFalse(conf.isJksEnable()); } + + @Test + public void slowLogDefaultValueTest() { + TiConfiguration conf = TiConfiguration.createRawDefault(); + assertEquals(conf.getTimeout() * 2, conf.getRawKVReadSlowLogInMS().longValue()); + assertEquals(conf.getTimeout() * 2, conf.getRawKVWriteSlowLogInMS().longValue()); + assertEquals(conf.getTimeout() * 2, conf.getRawKVBatchReadSlowLogInMS().longValue()); + assertEquals(conf.getTimeout() * 2, conf.getRawKVBatchWriteSlowLogInMS().longValue()); + } + + @Test + public void serializeTest() throws IOException { + TiConfiguration conf = TiConfiguration.createDefault(); + try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(conf); + oos.flush(); + } + } }