From 4fa729a537df3f49278aef58fa919315ad6a7f88 Mon Sep 17 00:00:00 2001 From: tison Date: Tue, 19 Mar 2024 17:52:02 +0800 Subject: [PATCH] build: format pom and code (#39) Signed-off-by: tison Co-authored-by: JeremyHi --- .github/workflows/build.yml | 58 +-- .github/workflows/mvn_publish.yml | 24 +- .gitignore | 1 + ingester-all/pom.xml | 25 +- ingester-common/pom.xml | 24 +- .../com/google/protobuf/ByteStringHelper.java | 3 +- .../java/io/greptime/common/Copiable.java | 1 + .../main/java/io/greptime/common/Display.java | 3 +- .../java/io/greptime/common/Endpoint.java | 3 +- .../main/java/io/greptime/common/Into.java | 3 +- .../main/java/io/greptime/common/Keys.java | 3 +- .../java/io/greptime/common/Lifecycle.java | 3 +- .../src/main/java/io/greptime/common/SPI.java | 3 +- .../common/signal/FileOutputHelper.java | 3 +- .../io/greptime/common/signal/FileSignal.java | 7 +- .../common/signal/FileSignalHelper.java | 7 +- .../io/greptime/common/signal/Signal.java | 3 +- .../greptime/common/signal/SignalHandler.java | 3 +- .../common/signal/SignalHandlersLoader.java | 13 +- .../greptime/common/signal/SignalHelper.java | 5 +- .../java/io/greptime/common/util/Clock.java | 3 +- .../java/io/greptime/common/util/Cpus.java | 7 +- .../greptime/common/util/DirectExecutor.java | 3 +- .../java/io/greptime/common/util/Ensures.java | 3 +- .../common/util/ExecutorServiceHelper.java | 7 +- .../java/io/greptime/common/util/Files.java | 6 +- .../util/LogScheduledThreadPoolExecutor.java | 21 +- .../common/util/LogThreadPoolExecutor.java | 32 +- .../greptime/common/util/MetricExecutor.java | 8 +- .../greptime/common/util/MetricReporter.java | 239 +++++++++---- .../MetricScheduledThreadPoolExecutor.java | 13 +- .../common/util/MetricThreadPoolExecutor.java | 22 +- .../io/greptime/common/util/MetricsUtil.java | 27 +- .../common/util/NamedThreadFactory.java | 7 +- .../io/greptime/common/util/ObjectPool.java | 3 +- .../io/greptime/common/util/Platform.java | 9 +- .../io/greptime/common/util/RcObjectPool.java | 3 +- .../common/util/RcResourceHolder.java | 20 +- .../java/io/greptime/common/util/RefCell.java | 3 +- .../common/util/SerializingExecutor.java | 5 +- .../greptime/common/util/ServiceLoader.java | 20 +- .../common/util/SharedScheduledPool.java | 3 +- .../common/util/SharedThreadPool.java | 3 +- .../common/util/StringBuilderHelper.java | 3 +- .../java/io/greptime/common/util/Strings.java | 3 +- .../common/util/SystemPropertyUtil.java | 10 +- .../common/util/ThreadPoolMetricRegistry.java | 6 +- .../greptime/common/util/ThreadPoolUtil.java | 64 ++-- .../src/test/java/common/EndpointTest.java | 3 +- .../util/ExecutorServiceHelperTest.java | 22 +- .../java/common/util/RcObjectPoolTest.java | 3 +- .../test/java/common/util/StringsTest.java | 3 +- ingester-example/pom.xml | 25 +- .../src/main/java/io/greptime/Cpu.java | 4 +- .../HighLevelApiStreamWriteQuickStart.java | 7 +- .../greptime/HighLevelApiWriteQuickStart.java | 15 +- .../LowLevelApiStreamWriteQuickStart.java | 25 +- .../greptime/LowLevelApiWriteQuickStart.java | 33 +- .../src/main/java/io/greptime/Memory.java | 3 +- .../src/main/java/io/greptime/QueryJDBC.java | 29 +- .../main/java/io/greptime/TestConnector.java | 14 +- .../main/resources/db-connection.properties | 14 + .../src/main/resources/log4j2.xml | 17 + ingester-grpc/pom.xml | 27 +- .../main/java/io/greptime/rpc/GrpcClient.java | 299 ++++++++-------- .../java/io/greptime/rpc/GrpcFactory.java | 14 +- .../main/java/io/greptime/rpc/IdChannel.java | 8 +- .../io/greptime/rpc/ManagedChannelHelper.java | 5 +- .../io/greptime/rpc/MarshallerRegistry.java | 45 +-- .../ClientRequestLimitInterceptor.java | 78 ++-- .../ContextToHeadersInterceptor.java | 20 +- .../rpc/interceptors/MetricInterceptor.java | 35 +- .../io/greptime/rpc/limit/Gradient2Limit.java | 12 +- .../rpc/limit/LimitMetricRegistry.java | 3 +- .../greptime/rpc/limit/RequestLimitCtx.java | 3 +- .../rpc/limit/RequestLimiterBuilder.java | 6 +- .../io/greptime/rpc/limit/VegasLimit.java | 75 ++-- .../rpc/signal/RpcLimitSignalHandler.java | 3 +- .../test/java/io/greptime/rpc/LimitTest.java | 25 +- .../rpc/RequestLimiterInterceptorTest.java | 34 +- .../io/greptime/rpc/StringMarshaller.java | 4 +- ingester-grpc/src/test/resources/log4j2.xml | 17 + ingester-protocol/pom.xml | 25 +- .../io/greptime/CachedPojoObjectMapper.java | 26 +- .../src/main/java/io/greptime/GreptimeDB.java | 48 ++- .../java/io/greptime/PojoObjectMapper.java | 3 +- .../src/main/java/io/greptime/Router.java | 3 +- .../main/java/io/greptime/RouterClient.java | 55 +-- .../java/io/greptime/RpcServiceRegister.java | 29 +- .../src/main/java/io/greptime/Status.java | 19 +- .../main/java/io/greptime/StreamWriter.java | 3 +- .../src/main/java/io/greptime/Util.java | 36 +- .../src/main/java/io/greptime/Write.java | 4 +- .../main/java/io/greptime/WriteClient.java | 210 +++++------ .../main/java/io/greptime/WriteObject.java | 4 +- .../src/main/java/io/greptime/WriteOp.java | 6 +- .../io/greptime/errors/LimitedException.java | 3 +- .../io/greptime/errors/PojoException.java | 3 +- .../io/greptime/errors/ServerException.java | 3 +- .../io/greptime/errors/StreamException.java | 3 +- .../io/greptime/limit/AbstractLimiter.java | 3 +- .../io/greptime/limit/InFlightLimiter.java | 3 +- .../java/io/greptime/limit/LimitedPolicy.java | 23 +- .../main/java/io/greptime/limit/Limiter.java | 3 +- .../java/io/greptime/limit/WriteLimiter.java | 3 +- .../java/io/greptime/models/AuthInfo.java | 13 +- .../main/java/io/greptime/models/Column.java | 3 +- .../java/io/greptime/models/DataType.java | 71 ++-- .../src/main/java/io/greptime/models/Err.java | 9 +- .../greptime/models/IntervalMonthDayNano.java | 11 +- .../main/java/io/greptime/models/Metric.java | 3 +- .../main/java/io/greptime/models/Result.java | 3 +- .../java/io/greptime/models/RowHelper.java | 10 +- .../java/io/greptime/models/SemanticType.java | 7 +- .../main/java/io/greptime/models/Table.java | 45 +-- .../java/io/greptime/models/TableHelper.java | 18 +- .../java/io/greptime/models/TableSchema.java | 33 +- .../java/io/greptime/models/ValueUtil.java | 18 +- .../main/java/io/greptime/models/WriteOk.java | 8 +- .../java/io/greptime/models/WriteTables.java | 3 +- .../io/greptime/options/GreptimeOptions.java | 16 +- .../io/greptime/options/RouterOptions.java | 12 +- .../io/greptime/options/WriteOptions.java | 20 +- .../greptime/signal/DisplaySignalHandler.java | 11 +- .../greptime/signal/MetricsSignalHandler.java | 17 +- .../signal/RwLoggingSignalHandler.java | 3 +- .../signal/ShowHelpSignalHandler.java | 3 +- .../main/resources/client_version.properties | 14 + .../io/greptime/PojoObjectMapperTest.java | 16 +- .../src/test/java/io/greptime/StatusTest.java | 3 +- .../src/test/java/io/greptime/TestUtil.java | 11 +- .../src/test/java/io/greptime/UtilTest.java | 3 +- .../java/io/greptime/WriteClientTest.java | 96 +++-- .../test/java/io/greptime/WriteLimitTest.java | 18 +- .../greptime/limit/InFlightLimiterTest.java | 3 +- .../test/java/io/greptime/models/ErrTest.java | 3 +- .../java/io/greptime/models/ResultTest.java | 3 +- .../io/greptime/models/TableSchemaTest.java | 53 +-- .../io/greptime/models/ValueUtilTest.java | 21 +- .../greptime/options/GreptimeOptionsTest.java | 39 +- ingester-rpc/pom.xml | 26 +- .../main/java/io/greptime/rpc/Context.java | 3 +- .../io/greptime/rpc/MethodDescriptor.java | 9 +- .../main/java/io/greptime/rpc/Observer.java | 3 +- .../main/java/io/greptime/rpc/RpcClient.java | 27 +- .../main/java/io/greptime/rpc/RpcFactory.java | 8 +- .../io/greptime/rpc/RpcFactoryProvider.java | 6 +- .../main/java/io/greptime/rpc/RpcOptions.java | 40 +-- .../main/java/io/greptime/rpc/TlsOptions.java | 14 +- .../rpc/errors/ConnectFailException.java | 3 +- .../greptime/rpc/errors/OnlyErrorMessage.java | 3 +- licenserc.toml | 19 + pom.xml | 183 +++++----- tools/check_format.sh | 8 - tools/codestyle/HEADER | 13 - tools/codestyle/formatter.xml | 337 ------------------ 156 files changed, 1677 insertions(+), 1841 deletions(-) create mode 100644 licenserc.toml delete mode 100644 tools/check_format.sh delete mode 100644 tools/codestyle/HEADER delete mode 100644 tools/codestyle/formatter.xml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 06eb0f7..512eb79 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,3 +1,17 @@ +# Copyright 2023 Greptime Team +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + name: build on: @@ -7,27 +21,27 @@ on: branches: [ main ] jobs: - check_format: + check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 + - uses: actions/checkout@v4 + - uses: korandoru/hawkeye@v4 + - uses: actions/setup-java@v4 with: - java-version: 1.8 + java-version: '21' + distribution: 'zulu' - name: Check format - run: mvn clean install -DskipTests=true -Dmaven.javadoc.skip=true -B -V - && sh ./tools/check_format.sh + run: mvn spotless:check test_ingester_common: - needs: check_format + needs: check runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 with: - java-version: 1.8 + java-version: '8' + distribution: 'zulu' - name: Maven Test run: mvn clean install -DskipTests=true -Dmaven.javadoc.skip=true -B -V && (mvn --projects ingester-common test @@ -35,14 +49,14 @@ jobs: || mvn --projects ingester-common test) test_ingester_grpc: - needs: check_format + needs: check runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 with: - java-version: 1.8 + java-version: '8' + distribution: 'zulu' - name: Maven Test run: mvn clean install -DskipTests=true -Dmaven.javadoc.skip=true -B -V && (mvn --projects ingester-grpc test @@ -50,14 +64,14 @@ jobs: || mvn --projects ingester-grpc test) test_ingester_protocol: - needs: check_format + needs: check runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 with: - java-version: 1.8 + java-version: '8' + distribution: 'zulu' - name: Maven Test run: mvn clean install -DskipTests=true -Dmaven.javadoc.skip=true -B -V && (mvn --projects ingester-protocol test diff --git a/.github/workflows/mvn_publish.yml b/.github/workflows/mvn_publish.yml index 7d5506c..dc01e68 100644 --- a/.github/workflows/mvn_publish.yml +++ b/.github/workflows/mvn_publish.yml @@ -1,3 +1,17 @@ +# Copyright 2023 Greptime Team +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + name: Maven Publish on: @@ -8,13 +22,11 @@ jobs: publish: runs-on: ubuntu-latest steps: - - name: Checkout Git Repo - uses: actions/checkout@v2 - - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 with: - java-version: 1.8 + java-version: '8' + distribution: 'zulu' server-id: ossrh server-username: MAVEN_USERNAME server-password: MAVEN_PASSWORD diff --git a/.gitignore b/.gitignore index 0e8ece6..06d8c0e 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ target # dev tools .idea +*.iml *.bak .vscode/* diff --git a/ingester-all/pom.xml b/ingester-all/pom.xml index cd20b7e..b68ae93 100644 --- a/ingester-all/pom.xml +++ b/ingester-all/pom.xml @@ -1,20 +1,31 @@ + 4.0.0 - greptimedb-ingester io.greptime + greptimedb-ingester 0.7.3 ingester-all - - 8 - 8 - UTF-8 - - ${project.groupId} diff --git a/ingester-common/pom.xml b/ingester-common/pom.xml index a390770..99b7cfb 100644 --- a/ingester-common/pom.xml +++ b/ingester-common/pom.xml @@ -1,19 +1,33 @@ + 4.0.0 - greptimedb-ingester io.greptime + greptimedb-ingester 0.7.3 ingester-common - 8 - 8 4.2.11 - UTF-8 @@ -35,8 +49,8 @@ ${metrics.version} - slf4j-api org.slf4j + slf4j-api diff --git a/ingester-common/src/main/java/com/google/protobuf/ByteStringHelper.java b/ingester-common/src/main/java/com/google/protobuf/ByteStringHelper.java index 0e46bc8..6a7c92a 100644 --- a/ingester-common/src/main/java/com/google/protobuf/ByteStringHelper.java +++ b/ingester-common/src/main/java/com/google/protobuf/ByteStringHelper.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.google.protobuf; /** * A {@code ByteString} helper, avoid some memory copying to improve performance. - * - * @author jiachun.fjc */ public class ByteStringHelper { diff --git a/ingester-common/src/main/java/io/greptime/common/Copiable.java b/ingester-common/src/main/java/io/greptime/common/Copiable.java index 93c8b35..3788a93 100644 --- a/ingester-common/src/main/java/io/greptime/common/Copiable.java +++ b/ingester-common/src/main/java/io/greptime/common/Copiable.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common; /** diff --git a/ingester-common/src/main/java/io/greptime/common/Display.java b/ingester-common/src/main/java/io/greptime/common/Display.java index 38bfe40..121841c 100644 --- a/ingester-common/src/main/java/io/greptime/common/Display.java +++ b/ingester-common/src/main/java/io/greptime/common/Display.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common; import java.io.PrintWriter; @@ -21,8 +22,6 @@ * Components that implement this interface need to be able to display * their own state and output state information via the {@code display} * method. - * - * @author jiachun.fjc */ public interface Display { diff --git a/ingester-common/src/main/java/io/greptime/common/Endpoint.java b/ingester-common/src/main/java/io/greptime/common/Endpoint.java index 9b5c78f..7544c21 100644 --- a/ingester-common/src/main/java/io/greptime/common/Endpoint.java +++ b/ingester-common/src/main/java/io/greptime/common/Endpoint.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common; import io.greptime.common.util.Strings; @@ -20,8 +21,6 @@ /** * An IP address with port. - * - * @author jiachun.fjc */ public class Endpoint implements Serializable { diff --git a/ingester-common/src/main/java/io/greptime/common/Into.java b/ingester-common/src/main/java/io/greptime/common/Into.java index 9a2bd27..374b402 100644 --- a/ingester-common/src/main/java/io/greptime/common/Into.java +++ b/ingester-common/src/main/java/io/greptime/common/Into.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common; /** * A value-to-value conversion. - * - * @author jiachun.fjc */ public interface Into { Output into(); diff --git a/ingester-common/src/main/java/io/greptime/common/Keys.java b/ingester-common/src/main/java/io/greptime/common/Keys.java index 2576556..0e18e6b 100644 --- a/ingester-common/src/main/java/io/greptime/common/Keys.java +++ b/ingester-common/src/main/java/io/greptime/common/Keys.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common; /** * Constant string keys. - * - * @author jiachun.fjc */ public final class Keys { public static final String DB_NAME = "GreptimeDB"; diff --git a/ingester-common/src/main/java/io/greptime/common/Lifecycle.java b/ingester-common/src/main/java/io/greptime/common/Lifecycle.java index 48e3874..3d7a1b6 100644 --- a/ingester-common/src/main/java/io/greptime/common/Lifecycle.java +++ b/ingester-common/src/main/java/io/greptime/common/Lifecycle.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common; /** * Service life cycle mark interface. - * - * @author jiachun.fjc */ public interface Lifecycle { diff --git a/ingester-common/src/main/java/io/greptime/common/SPI.java b/ingester-common/src/main/java/io/greptime/common/SPI.java index 8aad71c..5b4aac9 100644 --- a/ingester-common/src/main/java/io/greptime/common/SPI.java +++ b/ingester-common/src/main/java/io/greptime/common/SPI.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common; import java.lang.annotation.Documented; @@ -23,8 +24,6 @@ /** * Service provide interface annotation. - * - * @author jiachun.fjc */ @Documented @Retention(RetentionPolicy.RUNTIME) diff --git a/ingester-common/src/main/java/io/greptime/common/signal/FileOutputHelper.java b/ingester-common/src/main/java/io/greptime/common/signal/FileOutputHelper.java index 9ec7df8..07c7454 100644 --- a/ingester-common/src/main/java/io/greptime/common/signal/FileOutputHelper.java +++ b/ingester-common/src/main/java/io/greptime/common/signal/FileOutputHelper.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.signal; import io.greptime.common.Keys; @@ -26,8 +27,6 @@ /** * File output helper. - * - * @author jiachun.fjc */ public final class FileOutputHelper { diff --git a/ingester-common/src/main/java/io/greptime/common/signal/FileSignal.java b/ingester-common/src/main/java/io/greptime/common/signal/FileSignal.java index 4d65639..5581b36 100644 --- a/ingester-common/src/main/java/io/greptime/common/signal/FileSignal.java +++ b/ingester-common/src/main/java/io/greptime/common/signal/FileSignal.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.signal; import java.util.Optional; @@ -23,12 +24,10 @@ * Adopt the method of creating files with specified names to interact * with the Client process and implement signal transmission, achieve the * purpose of controlling the process to output specified content through this. - * - * @author jiachun.fjc */ public enum FileSignal { - RwLogging("rw_logging.sig", "How to open or close read/write log(The second execution means close)"), // - RpcLimit("rpc_limit.sig", "How to open or close rpc limiter(The second execution means close)"), // + RwLogging("rw_logging.sig", "How to open or close read/write log(The second execution means close)"), + RpcLimit("rpc_limit.sig", "How to open or close rpc limiter(The second execution means close)"), ; private final String filename; diff --git a/ingester-common/src/main/java/io/greptime/common/signal/FileSignalHelper.java b/ingester-common/src/main/java/io/greptime/common/signal/FileSignalHelper.java index 3e9b1eb..78c946b 100644 --- a/ingester-common/src/main/java/io/greptime/common/signal/FileSignalHelper.java +++ b/ingester-common/src/main/java/io/greptime/common/signal/FileSignalHelper.java @@ -13,19 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.signal; import java.io.File; import java.nio.file.Paths; /** - * @author jiachun.fjc + * */ public class FileSignalHelper { private static final String[] EMPTY_ARRAY = new String[0]; public static boolean ignoreSignal(FileSignal fileSignal) { - return !Paths.get(FileOutputHelper.getOutDir(), fileSignal.getFilename()).toFile().exists(); + return !Paths.get(FileOutputHelper.getOutDir(), fileSignal.getFilename()) + .toFile() + .exists(); } public static boolean ignoreFileOutputSignal() { diff --git a/ingester-common/src/main/java/io/greptime/common/signal/Signal.java b/ingester-common/src/main/java/io/greptime/common/signal/Signal.java index d32ebf6..b7bc1d2 100644 --- a/ingester-common/src/main/java/io/greptime/common/signal/Signal.java +++ b/ingester-common/src/main/java/io/greptime/common/signal/Signal.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.signal; /** * Signal types. - * - * @author jiachun.fjc */ public enum Signal { SIG_USR2("USR2"); diff --git a/ingester-common/src/main/java/io/greptime/common/signal/SignalHandler.java b/ingester-common/src/main/java/io/greptime/common/signal/SignalHandler.java index 42dada8..6310eb7 100644 --- a/ingester-common/src/main/java/io/greptime/common/signal/SignalHandler.java +++ b/ingester-common/src/main/java/io/greptime/common/signal/SignalHandler.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.signal; /** * This is the signal handler interface. - * - * @author jiachun.fjc */ public interface SignalHandler { diff --git a/ingester-common/src/main/java/io/greptime/common/signal/SignalHandlersLoader.java b/ingester-common/src/main/java/io/greptime/common/signal/SignalHandlersLoader.java index b8f69d4..b4f5cac 100644 --- a/ingester-common/src/main/java/io/greptime/common/signal/SignalHandlersLoader.java +++ b/ingester-common/src/main/java/io/greptime/common/signal/SignalHandlersLoader.java @@ -13,24 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.signal; import io.greptime.common.Keys; import io.greptime.common.util.ServiceLoader; import io.greptime.common.util.SystemPropertyUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A tool class for loading and registering all signals. *

* Do not support windows. - * - * @author jiachun.fjc */ public class SignalHandlersLoader { @@ -44,13 +43,13 @@ public class SignalHandlersLoader { public static void load() { try { if (USE_OS_SIGNAL && SignalHelper.supportSignal()) { - List handlers = ServiceLoader.load(SignalHandler.class) // - .sort(); + List handlers = + ServiceLoader.load(SignalHandler.class).sort(); LOG.info("Loaded signals: {}.", handlers); Map> mapTo = new HashMap<>(); - handlers.forEach(h -> mapTo.computeIfAbsent(h.signal(), sig -> new ArrayList<>()) // + handlers.forEach(h -> mapTo.computeIfAbsent(h.signal(), sig -> new ArrayList<>()) .add(h)); mapTo.forEach((sig, hs) -> { diff --git a/ingester-common/src/main/java/io/greptime/common/signal/SignalHelper.java b/ingester-common/src/main/java/io/greptime/common/signal/SignalHelper.java index f6b6350..34aea0d 100644 --- a/ingester-common/src/main/java/io/greptime/common/signal/SignalHelper.java +++ b/ingester-common/src/main/java/io/greptime/common/signal/SignalHelper.java @@ -13,17 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.signal; import io.greptime.common.util.Platform; +import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.List; /** * A signal helper, provides ANSI/ISO C signal support. - * - * @author jiachun.fjc */ public final class SignalHelper { diff --git a/ingester-common/src/main/java/io/greptime/common/util/Clock.java b/ingester-common/src/main/java/io/greptime/common/util/Clock.java index 3a35762..e490648 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/Clock.java +++ b/ingester-common/src/main/java/io/greptime/common/util/Clock.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; /** * A clock implementation which default returns the current millis. - * - * @author jiachun.fjc */ public abstract class Clock { diff --git a/ingester-common/src/main/java/io/greptime/common/util/Cpus.java b/ingester-common/src/main/java/io/greptime/common/util/Cpus.java index 1e412fe..5e101a4 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/Cpus.java +++ b/ingester-common/src/main/java/io/greptime/common/util/Cpus.java @@ -13,19 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; import io.greptime.common.Keys; /** * Utility for cpu. - * - * @author jiachun.fjc */ public class Cpus { - private static final int CPUS = SystemPropertyUtil.getInt(Keys.AVAILABLE_CPUS, Runtime.getRuntime() - .availableProcessors()); + private static final int CPUS = + SystemPropertyUtil.getInt(Keys.AVAILABLE_CPUS, Runtime.getRuntime().availableProcessors()); /** * The configured number of available processors. The default is diff --git a/ingester-common/src/main/java/io/greptime/common/util/DirectExecutor.java b/ingester-common/src/main/java/io/greptime/common/util/DirectExecutor.java index 3256902..7297c41 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/DirectExecutor.java +++ b/ingester-common/src/main/java/io/greptime/common/util/DirectExecutor.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; import com.codahale.metrics.Timer; @@ -20,8 +21,6 @@ /** * A direct executor. - * - * @author jiachun.fjc */ public class DirectExecutor implements Executor { private final String name; diff --git a/ingester-common/src/main/java/io/greptime/common/util/Ensures.java b/ingester-common/src/main/java/io/greptime/common/util/Ensures.java index dd6072e..f53ade6 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/Ensures.java +++ b/ingester-common/src/main/java/io/greptime/common/util/Ensures.java @@ -13,13 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; /** * Simple static methods to be called at the start of your own methods to verify * correct arguments and state. - * - * @author jiachun.fjc */ public final class Ensures { diff --git a/ingester-common/src/main/java/io/greptime/common/util/ExecutorServiceHelper.java b/ingester-common/src/main/java/io/greptime/common/util/ExecutorServiceHelper.java index 1dd8752..a59ce3d 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/ExecutorServiceHelper.java +++ b/ingester-common/src/main/java/io/greptime/common/util/ExecutorServiceHelper.java @@ -13,17 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Executor service shutdown helper. - * - * @author jiachun.fjc */ public final class ExecutorServiceHelper { diff --git a/ingester-common/src/main/java/io/greptime/common/util/Files.java b/ingester-common/src/main/java/io/greptime/common/util/Files.java index 72c4baa..666b651 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/Files.java +++ b/ingester-common/src/main/java/io/greptime/common/util/Files.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; import java.io.File; @@ -23,8 +24,6 @@ /** * File utilities. - * - * @author jiachun.fjc */ public class Files { @@ -56,8 +55,7 @@ public static void mkdirIfNotExists(String path) throws IOException { File dir = Paths.get(path).toFile().getAbsoluteFile(); if (dir.exists()) { if (!dir.isDirectory()) { - throw new IOException("File " + dir + " exists and is " - + "not a directory. Unable to create directory."); + throw new IOException("File " + dir + " exists and is not a directory. Unable to create directory."); } } else if (!dir.mkdirs() && !dir.isDirectory()) { // Double-check that some other thread or process hasn't made diff --git a/ingester-common/src/main/java/io/greptime/common/util/LogScheduledThreadPoolExecutor.java b/ingester-common/src/main/java/io/greptime/common/util/LogScheduledThreadPoolExecutor.java index 74f5a31..64c38d6 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/LogScheduledThreadPoolExecutor.java +++ b/ingester-common/src/main/java/io/greptime/common/util/LogScheduledThreadPoolExecutor.java @@ -13,23 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ThreadFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A {@link java.util.concurrent.ThreadPoolExecutor} that can additionally * schedule tasks to run after a given delay with a logger witch can print * error message for failed execution. - * - * @author jiachun.fjc */ public class LogScheduledThreadPoolExecutor extends ScheduledThreadPoolExecutor { @@ -38,10 +37,8 @@ public class LogScheduledThreadPoolExecutor extends ScheduledThreadPoolExecutor private final int corePoolSize; private final String name; - public LogScheduledThreadPoolExecutor(int corePoolSize, // - ThreadFactory threadFactory, // - RejectedExecutionHandler handler, // - String name) { + public LogScheduledThreadPoolExecutor( + int corePoolSize, ThreadFactory threadFactory, RejectedExecutionHandler handler, String name) { super(corePoolSize, threadFactory, handler); this.corePoolSize = corePoolSize; this.name = name; @@ -81,9 +78,9 @@ protected void terminated() { @Override public String toString() { - return "ScheduledThreadPoolExecutor {" + // - "corePoolSize=" + corePoolSize + // - ", name='" + name + '\'' + // - "} " + super.toString(); + return "ScheduledThreadPoolExecutor {" + "corePoolSize=" + + corePoolSize + ", name='" + + name + '\'' + "} " + + super.toString(); } } diff --git a/ingester-common/src/main/java/io/greptime/common/util/LogThreadPoolExecutor.java b/ingester-common/src/main/java/io/greptime/common/util/LogThreadPoolExecutor.java index c0e3dde..e1c02bd 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/LogThreadPoolExecutor.java +++ b/ingester-common/src/main/java/io/greptime/common/util/LogThreadPoolExecutor.java @@ -13,10 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.concurrent.BlockingQueue; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; @@ -25,12 +24,12 @@ import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A {@link java.util.concurrent.ExecutorService} that witch can print * error message for failed execution. - * - * @author jiachun.fjc */ public class LogThreadPoolExecutor extends ThreadPoolExecutor { @@ -40,13 +39,14 @@ public class LogThreadPoolExecutor extends ThreadPoolExecutor { private final int maximumPoolSize; private final String name; - public LogThreadPoolExecutor(int corePoolSize, // - int maximumPoolSize, // - long keepAliveTime, // - TimeUnit unit, // - BlockingQueue workQueue, // - ThreadFactory threadFactory, // - RejectedExecutionHandler handler, // + public LogThreadPoolExecutor( + int corePoolSize, + int maximumPoolSize, + long keepAliveTime, + TimeUnit unit, + BlockingQueue workQueue, + ThreadFactory threadFactory, + RejectedExecutionHandler handler, String name) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler); this.corePoolSize = corePoolSize; @@ -88,10 +88,10 @@ protected void terminated() { @Override public String toString() { - return "ThreadPoolExecutor{" + // - "corePoolSize=" + corePoolSize + // - ", maximumPoolSize=" + maximumPoolSize + // - ", name='" + name + '\'' + // - "} " + super.toString(); + return "ThreadPoolExecutor{" + "corePoolSize=" + + corePoolSize + ", maximumPoolSize=" + + maximumPoolSize + ", name='" + + name + '\'' + "} " + + super.toString(); } } diff --git a/ingester-common/src/main/java/io/greptime/common/util/MetricExecutor.java b/ingester-common/src/main/java/io/greptime/common/util/MetricExecutor.java index 193a17a..7ecf349 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/MetricExecutor.java +++ b/ingester-common/src/main/java/io/greptime/common/util/MetricExecutor.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; import com.codahale.metrics.Timer; @@ -21,8 +22,6 @@ /** * A {@link Executor} that with a timer metric * which aggregates timing durations and provides duration statistics. - * - * @author jiachun.fjc */ public class MetricExecutor implements Executor { private final Executor pool; @@ -43,9 +42,6 @@ public void execute(Runnable cmd) { @Override public String toString() { - return "MetricExecutor{" + // - "pool=" + pool + // - ", name='" + name + '\'' + // - '}'; + return "MetricExecutor{" + "pool=" + pool + ", name='" + name + '\'' + '}'; } } diff --git a/ingester-common/src/main/java/io/greptime/common/util/MetricReporter.java b/ingester-common/src/main/java/io/greptime/common/util/MetricReporter.java index 507bf47..a270e7d 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/MetricReporter.java +++ b/ingester-common/src/main/java/io/greptime/common/util/MetricReporter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; import com.codahale.metrics.Clock; @@ -58,10 +59,11 @@ public static Builder forRegistry(MetricRegistry registry) { */ public void report() { synchronized (this) { - report(this.registry.getGauges(this.filter), // - this.registry.getCounters(this.filter), // - this.registry.getHistograms(this.filter), // - this.registry.getMeters(this.filter), // + report( + this.registry.getGauges(this.filter), + this.registry.getCounters(this.filter), + this.registry.getHistograms(this.filter), + this.registry.getMeters(this.filter), this.registry.getTimers(this.filter)); } } @@ -205,15 +207,16 @@ public Builder disabledMetricAttributes(Set disabledMetricAttri * @return a {@link MetricReporter} */ public MetricReporter build() { - return new MetricReporter(this.registry, // - this.output, // - this.prefix, // - this.locale, // - this.clock, // - this.timeZone, // - this.rateUnit, // - this.durationUnit, // - this.filter, // + return new MetricReporter( + this.registry, + this.output, + this.prefix, + this.locale, + this.clock, + this.timeZone, + this.rateUnit, + this.durationUnit, + this.filter, this.disabledMetricAttributes); } } @@ -233,15 +236,16 @@ public MetricReporter build() { private final Clock clock; private final DateFormat dateFormat; - private MetricReporter(MetricRegistry registry, // - PrintStream output, // - String prefix, // - Locale locale, // - Clock clock, // - TimeZone timeZone, // - TimeUnit rateUnit, // - TimeUnit durationUnit, // - MetricFilter filter, // + private MetricReporter( + MetricRegistry registry, + PrintStream output, + String prefix, + Locale locale, + Clock clock, + TimeZone timeZone, + TimeUnit rateUnit, + TimeUnit durationUnit, + MetricFilter filter, Set disabledMetricAttributes) { this.registry = registry; this.output = output; @@ -260,10 +264,11 @@ private MetricReporter(MetricRegistry registry, // } @SuppressWarnings("rawtypes") - public void report(SortedMap gauges, // - SortedMap counters, // - SortedMap histograms, // - SortedMap meters, // + public void report( + SortedMap gauges, + SortedMap counters, + SortedMap histograms, + SortedMap meters, SortedMap timers) { String dateTime = this.dateFormat.format(new Date(this.clock.getTime())); printWithBanner(dateTime, '='); @@ -320,22 +325,39 @@ public void report(SortedMap gauges, // private void printMeter(Meter meter) { printIfEnabled(MetricAttribute.COUNT, String.format(this.locale, " count = %d", meter.getCount())); - printIfEnabled(MetricAttribute.MEAN_RATE, String.format(this.locale, " mean rate = %2.2f events/%s", - convertRate(meter.getMeanRate()), this.rateUnit)); - printIfEnabled(MetricAttribute.M1_RATE, String.format(this.locale, " 1-minute rate = %2.2f events/%s", - convertRate(meter.getOneMinuteRate()), this.rateUnit)); + printIfEnabled( + MetricAttribute.MEAN_RATE, + String.format( + this.locale, + " mean rate = %2.2f events/%s", + convertRate(meter.getMeanRate()), + this.rateUnit)); + printIfEnabled( + MetricAttribute.M1_RATE, + String.format( + this.locale, + " 1-minute rate = %2.2f events/%s", + convertRate(meter.getOneMinuteRate()), + this.rateUnit)); printIfEnabled( MetricAttribute.M5_RATE, - String.format(this.locale, " 5-minute rate = %2.2f events/%s", - convertRate(meter.getFiveMinuteRate()), this.rateUnit)); + String.format( + this.locale, + " 5-minute rate = %2.2f events/%s", + convertRate(meter.getFiveMinuteRate()), + this.rateUnit)); printIfEnabled( MetricAttribute.M15_RATE, - String.format(this.locale, " 15-minute rate = %2.2f events/%s", - convertRate(meter.getFifteenMinuteRate()), this.rateUnit)); + String.format( + this.locale, + " 15-minute rate = %2.2f events/%s", + convertRate(meter.getFifteenMinuteRate()), + this.rateUnit)); } private void printCounter(Map.Entry entry) { - this.output.printf(this.locale, " count = %d%n", entry.getValue().getCount()); + this.output.printf( + this.locale, " count = %d%n", entry.getValue().getCount()); } private void printGauge(Gauge gauge) { @@ -343,73 +365,136 @@ private void printGauge(Gauge gauge) { } private void printHistogram(Histogram histogram) { - printIfEnabled(MetricAttribute.COUNT, - String.format(this.locale, " count = %d", histogram.getCount())); + printIfEnabled( + MetricAttribute.COUNT, String.format(this.locale, " count = %d", histogram.getCount())); Snapshot snapshot = histogram.getSnapshot(); printIfEnabled(MetricAttribute.MIN, String.format(this.locale, " min = %d", snapshot.getMin())); printIfEnabled(MetricAttribute.MAX, String.format(this.locale, " max = %d", snapshot.getMax())); - printIfEnabled(MetricAttribute.MEAN, - String.format(this.locale, " mean = %2.2f", snapshot.getMean())); - printIfEnabled(MetricAttribute.STDDEV, - String.format(this.locale, " stddev = %2.2f", snapshot.getStdDev())); - printIfEnabled(MetricAttribute.P50, - String.format(this.locale, " median = %2.2f", snapshot.getMedian())); - printIfEnabled(MetricAttribute.P75, + printIfEnabled( + MetricAttribute.MEAN, String.format(this.locale, " mean = %2.2f", snapshot.getMean())); + printIfEnabled( + MetricAttribute.STDDEV, String.format(this.locale, " stddev = %2.2f", snapshot.getStdDev())); + printIfEnabled( + MetricAttribute.P50, String.format(this.locale, " median = %2.2f", snapshot.getMedian())); + printIfEnabled( + MetricAttribute.P75, String.format(this.locale, " 75%% <= %2.2f", snapshot.get75thPercentile())); - printIfEnabled(MetricAttribute.P95, + printIfEnabled( + MetricAttribute.P95, String.format(this.locale, " 95%% <= %2.2f", snapshot.get95thPercentile())); - printIfEnabled(MetricAttribute.P98, + printIfEnabled( + MetricAttribute.P98, String.format(this.locale, " 98%% <= %2.2f", snapshot.get98thPercentile())); - printIfEnabled(MetricAttribute.P99, + printIfEnabled( + MetricAttribute.P99, String.format(this.locale, " 99%% <= %2.2f", snapshot.get99thPercentile())); - printIfEnabled(MetricAttribute.P999, + printIfEnabled( + MetricAttribute.P999, String.format(this.locale, " 99.9%% <= %2.2f", snapshot.get999thPercentile())); } private void printTimer(Timer timer) { Snapshot snapshot = timer.getSnapshot(); printIfEnabled(MetricAttribute.COUNT, String.format(this.locale, " count = %d", timer.getCount())); - printIfEnabled(MetricAttribute.MEAN_RATE, String.format(this.locale, " mean rate = %2.2f calls/%s", - convertRate(timer.getMeanRate()), this.rateUnit)); - printIfEnabled(MetricAttribute.M1_RATE, String.format(this.locale, " 1-minute rate = %2.2f calls/%s", - convertRate(timer.getOneMinuteRate()), this.rateUnit)); - printIfEnabled(MetricAttribute.M5_RATE, String.format(this.locale, " 5-minute rate = %2.2f calls/%s", - convertRate(timer.getFiveMinuteRate()), this.rateUnit)); + printIfEnabled( + MetricAttribute.MEAN_RATE, + String.format( + this.locale, + " mean rate = %2.2f calls/%s", + convertRate(timer.getMeanRate()), + this.rateUnit)); + printIfEnabled( + MetricAttribute.M1_RATE, + String.format( + this.locale, + " 1-minute rate = %2.2f calls/%s", + convertRate(timer.getOneMinuteRate()), + this.rateUnit)); + printIfEnabled( + MetricAttribute.M5_RATE, + String.format( + this.locale, + " 5-minute rate = %2.2f calls/%s", + convertRate(timer.getFiveMinuteRate()), + this.rateUnit)); printIfEnabled( MetricAttribute.M15_RATE, - String.format(this.locale, " 15-minute rate = %2.2f calls/%s", - convertRate(timer.getFifteenMinuteRate()), this.rateUnit)); - - printIfEnabled(MetricAttribute.MIN, String.format(this.locale, " min = %2.2f %s", - convertDuration(snapshot.getMin()), this.durationUnit)); - printIfEnabled(MetricAttribute.MAX, String.format(this.locale, " max = %2.2f %s", - convertDuration(snapshot.getMax()), this.durationUnit)); - printIfEnabled(MetricAttribute.MEAN, String.format(this.locale, " mean = %2.2f %s", - convertDuration(snapshot.getMean()), this.durationUnit)); - printIfEnabled(MetricAttribute.STDDEV, String.format(this.locale, " stddev = %2.2f %s", - convertDuration(snapshot.getStdDev()), this.durationUnit)); - printIfEnabled(MetricAttribute.P50, String.format(this.locale, " median = %2.2f %s", - convertDuration(snapshot.getMedian()), this.durationUnit)); + String.format( + this.locale, + " 15-minute rate = %2.2f calls/%s", + convertRate(timer.getFifteenMinuteRate()), + this.rateUnit)); + + printIfEnabled( + MetricAttribute.MIN, + String.format( + this.locale, + " min = %2.2f %s", + convertDuration(snapshot.getMin()), + this.durationUnit)); + printIfEnabled( + MetricAttribute.MAX, + String.format( + this.locale, + " max = %2.2f %s", + convertDuration(snapshot.getMax()), + this.durationUnit)); + printIfEnabled( + MetricAttribute.MEAN, + String.format( + this.locale, + " mean = %2.2f %s", + convertDuration(snapshot.getMean()), + this.durationUnit)); + printIfEnabled( + MetricAttribute.STDDEV, + String.format( + this.locale, + " stddev = %2.2f %s", + convertDuration(snapshot.getStdDev()), + this.durationUnit)); + printIfEnabled( + MetricAttribute.P50, + String.format( + this.locale, + " median = %2.2f %s", + convertDuration(snapshot.getMedian()), + this.durationUnit)); printIfEnabled( MetricAttribute.P75, - String.format(this.locale, " 75%% <= %2.2f %s", - convertDuration(snapshot.get75thPercentile()), this.durationUnit)); + String.format( + this.locale, + " 75%% <= %2.2f %s", + convertDuration(snapshot.get75thPercentile()), + this.durationUnit)); printIfEnabled( MetricAttribute.P95, - String.format(this.locale, " 95%% <= %2.2f %s", - convertDuration(snapshot.get95thPercentile()), this.durationUnit)); + String.format( + this.locale, + " 95%% <= %2.2f %s", + convertDuration(snapshot.get95thPercentile()), + this.durationUnit)); printIfEnabled( MetricAttribute.P98, - String.format(this.locale, " 98%% <= %2.2f %s", - convertDuration(snapshot.get98thPercentile()), this.durationUnit)); + String.format( + this.locale, + " 98%% <= %2.2f %s", + convertDuration(snapshot.get98thPercentile()), + this.durationUnit)); printIfEnabled( MetricAttribute.P99, - String.format(this.locale, " 99%% <= %2.2f %s", - convertDuration(snapshot.get99thPercentile()), this.durationUnit)); + String.format( + this.locale, + " 99%% <= %2.2f %s", + convertDuration(snapshot.get99thPercentile()), + this.durationUnit)); printIfEnabled( MetricAttribute.P999, - String.format(this.locale, " 99.9%% <= %2.2f %s", - convertDuration(snapshot.get999thPercentile()), this.durationUnit)); + String.format( + this.locale, + " 99.9%% <= %2.2f %s", + convertDuration(snapshot.get999thPercentile()), + this.durationUnit)); } private void printWithBanner(String s, char c) { diff --git a/ingester-common/src/main/java/io/greptime/common/util/MetricScheduledThreadPoolExecutor.java b/ingester-common/src/main/java/io/greptime/common/util/MetricScheduledThreadPoolExecutor.java index 9630386..ec33e67 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/MetricScheduledThreadPoolExecutor.java +++ b/ingester-common/src/main/java/io/greptime/common/util/MetricScheduledThreadPoolExecutor.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; import java.util.concurrent.RejectedExecutionHandler; @@ -23,15 +24,11 @@ * A {@link java.util.concurrent.ThreadPoolExecutor} that can additionally * schedule tasks to run after a given delay with a timer metric * which aggregates timing durations and provides duration statistics. - * - * @author jiachun.fjc */ public class MetricScheduledThreadPoolExecutor extends LogScheduledThreadPoolExecutor { - public MetricScheduledThreadPoolExecutor(int corePoolSize, // - ThreadFactory threadFactory, // - RejectedExecutionHandler handler, // - String name) { + public MetricScheduledThreadPoolExecutor( + int corePoolSize, ThreadFactory threadFactory, RejectedExecutionHandler handler, String name) { super(corePoolSize, threadFactory, handler, name); } @@ -43,8 +40,8 @@ protected void beforeExecute(Thread t, Runnable r) { @Override protected void afterExecute(Runnable r, Throwable t) { - ThreadPoolMetricRegistry.metricRegistry() // - .timer("scheduled_thread_pool." + getName()) // + ThreadPoolMetricRegistry.metricRegistry() + .timer("scheduled_thread_pool." + getName()) .update(ThreadPoolMetricRegistry.finish(), TimeUnit.MILLISECONDS); super.afterExecute(r, t); } diff --git a/ingester-common/src/main/java/io/greptime/common/util/MetricThreadPoolExecutor.java b/ingester-common/src/main/java/io/greptime/common/util/MetricThreadPoolExecutor.java index 9bfea9a..bdcb1b7 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/MetricThreadPoolExecutor.java +++ b/ingester-common/src/main/java/io/greptime/common/util/MetricThreadPoolExecutor.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; import java.util.concurrent.BlockingQueue; @@ -23,18 +24,17 @@ /** * A {@link java.util.concurrent.ExecutorService} that with a timer metric * which aggregates timing durations and provides duration statistics. - * - * @author jiachun.fjc */ public class MetricThreadPoolExecutor extends LogThreadPoolExecutor { - public MetricThreadPoolExecutor(int corePoolSize, // - int maximumPoolSize, // - long keepAliveTime, // - TimeUnit unit, // - BlockingQueue workQueue, // - ThreadFactory threadFactory, // - RejectedExecutionHandler handler, // + public MetricThreadPoolExecutor( + int corePoolSize, + int maximumPoolSize, + long keepAliveTime, + TimeUnit unit, + BlockingQueue workQueue, + ThreadFactory threadFactory, + RejectedExecutionHandler handler, String name) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler, name); } @@ -47,8 +47,8 @@ protected void beforeExecute(Thread t, Runnable r) { @Override protected void afterExecute(Runnable r, Throwable t) { - ThreadPoolMetricRegistry.metricRegistry() // - .timer("thread_pool." + getName()) // + ThreadPoolMetricRegistry.metricRegistry() + .timer("thread_pool." + getName()) .update(ThreadPoolMetricRegistry.finish(), TimeUnit.MILLISECONDS); super.afterExecute(r, t); } diff --git a/ingester-common/src/main/java/io/greptime/common/util/MetricsUtil.java b/ingester-common/src/main/java/io/greptime/common/util/MetricsUtil.java index 853ca7a..2463a91 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/MetricsUtil.java +++ b/ingester-common/src/main/java/io/greptime/common/util/MetricsUtil.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; import com.codahale.metrics.Counter; @@ -22,16 +23,14 @@ import com.codahale.metrics.ScheduledReporter; import com.codahale.metrics.Slf4jReporter; import com.codahale.metrics.Timer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * In GreptimeDB client, metrics are required. As for whether to output (log) metrics * results, you decide. - * - * @author jiachun.fjc */ public final class MetricsUtil { @@ -41,22 +40,22 @@ public final class MetricsUtil { private static final ScheduledReporter SCHEDULED_REPORTER; static { - ScheduledExecutorService scheduledPool = ThreadPoolUtil.newScheduledBuilder() // - .enableMetric(true) // - .coreThreads(1) // - .poolName("metrics.reporter") // - .threadFactory(new NamedThreadFactory("metrics.reporter", true)) // + ScheduledExecutorService scheduledPool = ThreadPoolUtil.newScheduledBuilder() + .enableMetric(true) + .coreThreads(1) + .poolName("metrics.reporter") + .threadFactory(new NamedThreadFactory("metrics.reporter", true)) .build(); SCHEDULED_REPORTER = createReporter(scheduledPool); } private static ScheduledReporter createReporter(ScheduledExecutorService scheduledPool) { try { - return Slf4jReporter.forRegistry(MetricsUtil.METRIC_REGISTRY) // - .withLoggingLevel(Slf4jReporter.LoggingLevel.INFO) // - .outputTo(LOG) // - .scheduleOn(scheduledPool) // - .shutdownExecutorOnStop(true) // + return Slf4jReporter.forRegistry(MetricsUtil.METRIC_REGISTRY) + .withLoggingLevel(Slf4jReporter.LoggingLevel.INFO) + .outputTo(LOG) + .scheduleOn(scheduledPool) + .shutdownExecutorOnStop(true) .build(); } catch (Throwable ex) { LOG.warn("Fail to create metrics reporter.", ex); diff --git a/ingester-common/src/main/java/io/greptime/common/util/NamedThreadFactory.java b/ingester-common/src/main/java/io/greptime/common/util/NamedThreadFactory.java index 8fb16fe..084be48 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/NamedThreadFactory.java +++ b/ingester-common/src/main/java/io/greptime/common/util/NamedThreadFactory.java @@ -13,17 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicInteger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Named thread factory. - * - * @author jiachun.fjc */ @SuppressWarnings("unused") public class NamedThreadFactory implements ThreadFactory { diff --git a/ingester-common/src/main/java/io/greptime/common/util/ObjectPool.java b/ingester-common/src/main/java/io/greptime/common/util/ObjectPool.java index 1791819..cc9e1b4 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/ObjectPool.java +++ b/ingester-common/src/main/java/io/greptime/common/util/ObjectPool.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; /** * An object pool. - * - * @author jiachun.fjc */ public interface ObjectPool { diff --git a/ingester-common/src/main/java/io/greptime/common/util/Platform.java b/ingester-common/src/main/java/io/greptime/common/util/Platform.java index 0ebdc2c..ece3d96 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/Platform.java +++ b/ingester-common/src/main/java/io/greptime/common/util/Platform.java @@ -13,17 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; import io.greptime.common.Keys; +import java.util.Locale; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Locale; /** * Platform utilities. - * - * @author jiachun.fjc */ public class Platform { @@ -67,8 +66,6 @@ private static boolean isWindows0() { } private static boolean checkOS(String osKey) { - return SystemPropertyUtil.get(Keys.OS_NAME, "") // - .toLowerCase(Locale.US) // - .contains(osKey); + return SystemPropertyUtil.get(Keys.OS_NAME, "").toLowerCase(Locale.US).contains(osKey); } } diff --git a/ingester-common/src/main/java/io/greptime/common/util/RcObjectPool.java b/ingester-common/src/main/java/io/greptime/common/util/RcObjectPool.java index d23243f..677cffe 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/RcObjectPool.java +++ b/ingester-common/src/main/java/io/greptime/common/util/RcObjectPool.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; /** * An shared object pool with ref count. - * - * @author jiachun.fjc */ public class RcObjectPool implements ObjectPool { diff --git a/ingester-common/src/main/java/io/greptime/common/util/RcResourceHolder.java b/ingester-common/src/main/java/io/greptime/common/util/RcResourceHolder.java index 5a13add..033c446 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/RcResourceHolder.java +++ b/ingester-common/src/main/java/io/greptime/common/util/RcResourceHolder.java @@ -13,17 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.IdentityHashMap; import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Resource holder with ref count. - * - * @author jiachun.fjc */ public class RcResourceHolder { @@ -45,8 +44,11 @@ public synchronized T get(ObjectPool.Resource resource) { public synchronized void release(ObjectPool.Resource resource, T returned) { Instance cached = this.instances.get(resource); Ensures.ensureNonNull(cached, "No cached instance found for " + resource); - Ensures.ensure(returned == cached.payload(), "Releasing the wrong instance, expected=%s, actual=%s", - cached.payload(), returned); + Ensures.ensure( + returned == cached.payload(), + "Releasing the wrong instance, expected=%s, actual=%s", + cached.payload(), + returned); Ensures.ensure(cached.rc() > 0, "RefCount has already reached zero"); if (cached.decAndGet() == 0) { LOG.info("[RcResourceHolder] close instance: {}.", cached); @@ -83,11 +85,7 @@ T payload() { @Override public String toString() { - return "Instance{" + // - "payload=" + payload + // - ", refCount=" + refCount + // - ", maxRefCount=" + maxRefCount + // - '}'; + return "Instance{" + "payload=" + payload + ", refCount=" + refCount + ", maxRefCount=" + maxRefCount + '}'; } } } diff --git a/ingester-common/src/main/java/io/greptime/common/util/RefCell.java b/ingester-common/src/main/java/io/greptime/common/util/RefCell.java index 2f01c3d..0a0c9c6 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/RefCell.java +++ b/ingester-common/src/main/java/io/greptime/common/util/RefCell.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; /** * A reference cell. - * - * @author jiachun.fjc */ public class RefCell { diff --git a/ingester-common/src/main/java/io/greptime/common/util/SerializingExecutor.java b/ingester-common/src/main/java/io/greptime/common/util/SerializingExecutor.java index 0f352a3..624e27d 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/SerializingExecutor.java +++ b/ingester-common/src/main/java/io/greptime/common/util/SerializingExecutor.java @@ -13,17 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; import com.codahale.metrics.Histogram; import com.codahale.metrics.Timer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A SerializingExecutor is a queue of tasks that run in sequence. diff --git a/ingester-common/src/main/java/io/greptime/common/util/ServiceLoader.java b/ingester-common/src/main/java/io/greptime/common/util/ServiceLoader.java index fc2c857..cad930d 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/ServiceLoader.java +++ b/ingester-common/src/main/java/io/greptime/common/util/ServiceLoader.java @@ -13,11 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; import io.greptime.common.SPI; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -33,11 +32,11 @@ import java.util.NoSuchElementException; import java.util.ServiceConfigurationError; import java.util.function.Supplier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A simple service-provider loading facility (SPI). - * - * @author jiachun.fjc */ @SuppressWarnings("unused") public final class ServiceLoader implements Iterable { @@ -174,8 +173,8 @@ private static ServiceConfigurationError fail(Class service, URL url, int lin // parse a single line from the given configuration file, adding the name // on the line to the names list. - private int parseLine(Class service, URL u, BufferedReader r, int lc, List names) throws IOException, - ServiceConfigurationError { + private int parseLine(Class service, URL u, BufferedReader r, int lc, List names) + throws IOException, ServiceConfigurationError { String ln = r.readLine(); if (ln == null) { @@ -214,7 +213,8 @@ private Iterator parse(Class service, URL url) { BufferedReader r = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) { int lc = 1; // noinspection StatementWithEmptyBody - while ((lc = parseLine(service, url, r, lc, names)) >= 0); + while ((lc = parseLine(service, url, r, lc, names)) >= 0) + ; } catch (IOException x) { throw fail(service, "error reading configuration file", x); } @@ -226,7 +226,8 @@ private Iterator parse(Class service, URL url) { public Iterator iterator() { return new Iterator() { - final Iterator> knownProviders = ServiceLoader.this.providers.entrySet().iterator(); + final Iterator> knownProviders = + ServiceLoader.this.providers.entrySet().iterator(); @Override public boolean hasNext() { @@ -252,7 +253,8 @@ public void remove() { public Iterator> classIterator() { return new Iterator>() { - final Iterator> knownProviders = ServiceLoader.this.providers.entrySet().iterator(); + final Iterator> knownProviders = + ServiceLoader.this.providers.entrySet().iterator(); @Override public boolean hasNext() { diff --git a/ingester-common/src/main/java/io/greptime/common/util/SharedScheduledPool.java b/ingester-common/src/main/java/io/greptime/common/util/SharedScheduledPool.java index 204e8ca..106c09f 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/SharedScheduledPool.java +++ b/ingester-common/src/main/java/io/greptime/common/util/SharedScheduledPool.java @@ -13,14 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; import java.util.concurrent.ScheduledExecutorService; /** * Like rust: pub type SharedScheduledPool = RcObjectPool - * - * @author jiachun.fjc */ public class SharedScheduledPool extends RcObjectPool { diff --git a/ingester-common/src/main/java/io/greptime/common/util/SharedThreadPool.java b/ingester-common/src/main/java/io/greptime/common/util/SharedThreadPool.java index c708e91..edcb46b 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/SharedThreadPool.java +++ b/ingester-common/src/main/java/io/greptime/common/util/SharedThreadPool.java @@ -13,14 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; import java.util.concurrent.ExecutorService; /** * Like rust: pub type SharedThreadPool = RcObjectPool - * - * @author jiachun.fjc */ public class SharedThreadPool extends RcObjectPool { diff --git a/ingester-common/src/main/java/io/greptime/common/util/StringBuilderHelper.java b/ingester-common/src/main/java/io/greptime/common/util/StringBuilderHelper.java index 74cec9c..e556b07 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/StringBuilderHelper.java +++ b/ingester-common/src/main/java/io/greptime/common/util/StringBuilderHelper.java @@ -13,14 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; /** * Reuse {@link StringBuilder} based on {@link ThreadLocal}. *

* Be careful that do not to nest in the same thread. - * - * @author jiachun.fjc */ public class StringBuilderHelper { diff --git a/ingester-common/src/main/java/io/greptime/common/util/Strings.java b/ingester-common/src/main/java/io/greptime/common/util/Strings.java index 79bd9af..776ba68 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/Strings.java +++ b/ingester-common/src/main/java/io/greptime/common/util/Strings.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; import java.util.ArrayList; @@ -21,8 +22,6 @@ /** * Static utility methods pertaining to {@code String} or {@code CharSequence} * instances. - * - * @author jiachun.fjc */ public final class Strings { diff --git a/ingester-common/src/main/java/io/greptime/common/util/SystemPropertyUtil.java b/ingester-common/src/main/java/io/greptime/common/util/SystemPropertyUtil.java index 4f9e9dd..c0f59a9 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/SystemPropertyUtil.java +++ b/ingester-common/src/main/java/io/greptime/common/util/SystemPropertyUtil.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.security.AccessController; import java.security.PrivilegedAction; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A collection of utility methods to retrieve and @@ -160,7 +161,10 @@ public static long getLong(String key, long def) { // ignored } - LOG.warn("Unable to parse the long integer system property '{}':{} - using the default value: {}.", key, value, + LOG.warn( + "Unable to parse the long integer system property '{}':{} - using the default value: {}.", + key, + value, def); return def; diff --git a/ingester-common/src/main/java/io/greptime/common/util/ThreadPoolMetricRegistry.java b/ingester-common/src/main/java/io/greptime/common/util/ThreadPoolMetricRegistry.java index 478e4a4..7b1baee 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/ThreadPoolMetricRegistry.java +++ b/ingester-common/src/main/java/io/greptime/common/util/ThreadPoolMetricRegistry.java @@ -13,18 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; import com.codahale.metrics.MetricRegistry; /** * A global timer metric registry for thread pool, use threadLocal to pass timer context. - * - * @author jiachun.fjc */ public class ThreadPoolMetricRegistry { - private static final ThreadLocal TIME_THREAD_LOCAL = ThreadLocal.withInitial(() -> Clock.defaultClock().getTick()); + private static final ThreadLocal TIME_THREAD_LOCAL = + ThreadLocal.withInitial(() -> Clock.defaultClock().getTick()); /** * Return the global registry of metric instances. diff --git a/ingester-common/src/main/java/io/greptime/common/util/ThreadPoolUtil.java b/ingester-common/src/main/java/io/greptime/common/util/ThreadPoolUtil.java index 3c2effd..8537fe1 100644 --- a/ingester-common/src/main/java/io/greptime/common/util/ThreadPoolUtil.java +++ b/ingester-common/src/main/java/io/greptime/common/util/ThreadPoolUtil.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.common.util; import java.util.concurrent.BlockingQueue; @@ -25,8 +26,6 @@ /** * Factory and utility methods for creating {@link ThreadPoolExecutor} and * {@link ScheduledThreadPoolExecutor}. - * - * @author jiachun.fjc */ public final class ThreadPoolUtil { @@ -69,21 +68,36 @@ public static ScheduledPoolBuilder newScheduledBuilder() { * @throws NullPointerException if {@code workQueue} * or {@code threadFactory} or {@code handler} is null */ - public static ThreadPoolExecutor newThreadPool(String poolName, // - boolean enableMetric, // - int coreThreads, // - int maximumThreads, // - long keepAliveSeconds, // - BlockingQueue workQueue, // - ThreadFactory threadFactory, // + public static ThreadPoolExecutor newThreadPool( + String poolName, + boolean enableMetric, + int coreThreads, + int maximumThreads, + long keepAliveSeconds, + BlockingQueue workQueue, + ThreadFactory threadFactory, RejectedExecutionHandler rejectedHandler) { TimeUnit unit = TimeUnit.SECONDS; if (enableMetric) { - return new MetricThreadPoolExecutor(coreThreads, maximumThreads, keepAliveSeconds, unit, workQueue, - threadFactory, rejectedHandler, poolName); + return new MetricThreadPoolExecutor( + coreThreads, + maximumThreads, + keepAliveSeconds, + unit, + workQueue, + threadFactory, + rejectedHandler, + poolName); } else { - return new LogThreadPoolExecutor(coreThreads, maximumThreads, keepAliveSeconds, unit, workQueue, - threadFactory, rejectedHandler, poolName); + return new LogThreadPoolExecutor( + coreThreads, + maximumThreads, + keepAliveSeconds, + unit, + workQueue, + threadFactory, + rejectedHandler, + poolName); } } @@ -105,10 +119,11 @@ public static ThreadPoolExecutor newThreadPool(String poolName, // * {@code handler} is null * @return a new ScheduledThreadPoolExecutor */ - public static ScheduledThreadPoolExecutor newScheduledThreadPool(String poolName, // - boolean enableMetric, // - int coreThreads, // - ThreadFactory threadFactory, // + public static ScheduledThreadPoolExecutor newScheduledThreadPool( + String poolName, + boolean enableMetric, + int coreThreads, + ThreadFactory threadFactory, RejectedExecutionHandler rejectedHandler) { if (enableMetric) { return new MetricScheduledThreadPoolExecutor(coreThreads, threadFactory, rejectedHandler, poolName); @@ -179,8 +194,15 @@ public ThreadPoolExecutor build() { Ensures.ensureNonNull(this.threadFactory, "null `threadFactory`"); Ensures.ensureNonNull(this.handler, "null `handler`"); - return ThreadPoolUtil.newThreadPool(this.poolName, this.enableMetric, this.coreThreads, - this.maximumThreads, this.keepAliveSeconds, this.workQueue, this.threadFactory, this.handler); + return ThreadPoolUtil.newThreadPool( + this.poolName, + this.enableMetric, + this.coreThreads, + this.maximumThreads, + this.keepAliveSeconds, + this.workQueue, + this.threadFactory, + this.handler); } } @@ -223,8 +245,8 @@ public ScheduledThreadPoolExecutor build() { Ensures.ensureNonNull(this.threadFactory, "null `threadFactory`"); Ensures.ensureNonNull(this.handler, "null `handler`"); - return ThreadPoolUtil.newScheduledThreadPool(this.poolName, this.enableMetric, this.coreThreads, - this.threadFactory, this.handler); + return ThreadPoolUtil.newScheduledThreadPool( + this.poolName, this.enableMetric, this.coreThreads, this.threadFactory, this.handler); } } } diff --git a/ingester-common/src/test/java/common/EndpointTest.java b/ingester-common/src/test/java/common/EndpointTest.java index 8f26f0a..130f7fb 100644 --- a/ingester-common/src/test/java/common/EndpointTest.java +++ b/ingester-common/src/test/java/common/EndpointTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package common; import io.greptime.common.Endpoint; @@ -20,7 +21,7 @@ import org.junit.Test; /** - * @author jiachun.fjc + * */ public class EndpointTest { diff --git a/ingester-common/src/test/java/common/util/ExecutorServiceHelperTest.java b/ingester-common/src/test/java/common/util/ExecutorServiceHelperTest.java index f4abd1f..514d90b 100644 --- a/ingester-common/src/test/java/common/util/ExecutorServiceHelperTest.java +++ b/ingester-common/src/test/java/common/util/ExecutorServiceHelperTest.java @@ -13,18 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package common.util; import io.greptime.common.util.ExecutorServiceHelper; import io.greptime.common.util.NamedThreadFactory; import io.greptime.common.util.ThreadPoolUtil; -import org.junit.Assert; -import org.junit.Test; import java.util.concurrent.ExecutorService; import java.util.concurrent.SynchronousQueue; +import org.junit.Assert; +import org.junit.Test; /** - * @author jiachun.fjc + * */ public class ExecutorServiceHelperTest { @@ -35,13 +36,14 @@ public void shutdownNullTest() { @Test public void shutdownNotStart() { - ExecutorService e = ThreadPoolUtil.newBuilder().poolName("test_shutdown") // - .coreThreads(1) // - .maximumThreads(1) // - .keepAliveSeconds(100L) // - .workQueue(new SynchronousQueue<>()) // - .enableMetric(false) // - .threadFactory(new NamedThreadFactory("test_shutdown")) // + ExecutorService e = ThreadPoolUtil.newBuilder() + .poolName("test_shutdown") + .coreThreads(1) + .maximumThreads(1) + .keepAliveSeconds(100L) + .workQueue(new SynchronousQueue<>()) + .enableMetric(false) + .threadFactory(new NamedThreadFactory("test_shutdown")) .build(); Assert.assertTrue(ExecutorServiceHelper.shutdownAndAwaitTermination(e)); } diff --git a/ingester-common/src/test/java/common/util/RcObjectPoolTest.java b/ingester-common/src/test/java/common/util/RcObjectPoolTest.java index 9c6b628..d4da335 100644 --- a/ingester-common/src/test/java/common/util/RcObjectPoolTest.java +++ b/ingester-common/src/test/java/common/util/RcObjectPoolTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package common.util; import io.greptime.common.util.ObjectPool; @@ -21,8 +22,6 @@ import org.junit.Test; /** - * - * @author jiachun.fjc */ public class RcObjectPoolTest { diff --git a/ingester-common/src/test/java/common/util/StringsTest.java b/ingester-common/src/test/java/common/util/StringsTest.java index f75bace..3b36eaa 100644 --- a/ingester-common/src/test/java/common/util/StringsTest.java +++ b/ingester-common/src/test/java/common/util/StringsTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package common.util; import io.greptime.common.util.Strings; @@ -20,7 +21,7 @@ import org.junit.Test; /** - * @author jiachun.fjc + * */ public class StringsTest { diff --git a/ingester-example/pom.xml b/ingester-example/pom.xml index d9020a0..ac8dc14 100644 --- a/ingester-example/pom.xml +++ b/ingester-example/pom.xml @@ -1,20 +1,31 @@ + 4.0.0 - greptimedb-ingester io.greptime + greptimedb-ingester 0.7.3 ingester-example - - 8 - 8 - UTF-8 - - ${project.groupId} diff --git a/ingester-example/src/main/java/io/greptime/Cpu.java b/ingester-example/src/main/java/io/greptime/Cpu.java index 38ca0dd..b6afde5 100644 --- a/ingester-example/src/main/java/io/greptime/Cpu.java +++ b/ingester-example/src/main/java/io/greptime/Cpu.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import io.greptime.models.Column; @@ -20,7 +21,7 @@ import io.greptime.models.Metric; /** - * @author jiachun.fjc + * */ @Metric(name = "cpu_metric") public class Cpu { @@ -32,6 +33,7 @@ public class Cpu { @Column(name = "cpu_user", dataType = DataType.Float64) private double cpuUser; + @Column(name = "cpu_sys", dataType = DataType.Float64) private double cpuSys; diff --git a/ingester-example/src/main/java/io/greptime/HighLevelApiStreamWriteQuickStart.java b/ingester-example/src/main/java/io/greptime/HighLevelApiStreamWriteQuickStart.java index 8f184ac..ba9897f 100644 --- a/ingester-example/src/main/java/io/greptime/HighLevelApiStreamWriteQuickStart.java +++ b/ingester-example/src/main/java/io/greptime/HighLevelApiStreamWriteQuickStart.java @@ -13,18 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import io.greptime.models.WriteOk; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** - * @author jiachun.fjc + * */ public class HighLevelApiStreamWriteQuickStart { diff --git a/ingester-example/src/main/java/io/greptime/HighLevelApiWriteQuickStart.java b/ingester-example/src/main/java/io/greptime/HighLevelApiWriteQuickStart.java index 21478b1..a9bbeb9 100644 --- a/ingester-example/src/main/java/io/greptime/HighLevelApiWriteQuickStart.java +++ b/ingester-example/src/main/java/io/greptime/HighLevelApiWriteQuickStart.java @@ -13,21 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import io.greptime.models.Err; import io.greptime.models.Result; import io.greptime.models.WriteOk; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** - * @author jiachun.fjc + * */ public class HighLevelApiWriteQuickStart { @@ -62,9 +63,8 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc Result result = puts.get(); - Result simpleResult = result // - .map(WriteOk::getSuccess) // - .mapErr(err -> err.getError().getMessage()); + Result simpleResult = + result.map(WriteOk::getSuccess).mapErr(err -> err.getError().getMessage()); if (simpleResult.isOk()) { LOG.info("Write success: {}", simpleResult.getOk()); } else { @@ -72,7 +72,8 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc } List> deletePojoObjects = Arrays.asList(cpus.subList(0, 5), memories.subList(0, 5)); - Result deletes = greptimeDB.writeObjects(deletePojoObjects, WriteOp.Delete).get(); + Result deletes = + greptimeDB.writeObjects(deletePojoObjects, WriteOp.Delete).get(); if (deletes.isOk()) { LOG.info("Delete result: {}", result.getOk()); diff --git a/ingester-example/src/main/java/io/greptime/LowLevelApiStreamWriteQuickStart.java b/ingester-example/src/main/java/io/greptime/LowLevelApiStreamWriteQuickStart.java index d30ea2f..d4e6912 100644 --- a/ingester-example/src/main/java/io/greptime/LowLevelApiStreamWriteQuickStart.java +++ b/ingester-example/src/main/java/io/greptime/LowLevelApiStreamWriteQuickStart.java @@ -13,19 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import io.greptime.models.DataType; import io.greptime.models.Table; import io.greptime.models.TableSchema; import io.greptime.models.WriteOk; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** - * @author jiachun.fjc + * */ public class LowLevelApiStreamWriteQuickStart { @@ -34,17 +35,17 @@ public class LowLevelApiStreamWriteQuickStart { public static void main(String[] args) throws ExecutionException, InterruptedException { GreptimeDB greptimeDB = TestConnector.connectToDefaultDB(); - TableSchema cpuMetricSchema = TableSchema.newBuilder("cpu_metric") // - .addTag("host", DataType.String) // - .addTimestamp("ts", DataType.TimestampMillisecond) // - .addField("cpu_user", DataType.Float64) // - .addField("cpu_sys", DataType.Float64) // + TableSchema cpuMetricSchema = TableSchema.newBuilder("cpu_metric") + .addTag("host", DataType.String) + .addTimestamp("ts", DataType.TimestampMillisecond) + .addField("cpu_user", DataType.Float64) + .addField("cpu_sys", DataType.Float64) .build(); - TableSchema memMetricSchema = TableSchema.newBuilder("mem_metric") // - .addTag("host", DataType.String) // - .addTimestamp("ts", DataType.TimestampMillisecond) // - .addField("mem_usage", DataType.Float64) // + TableSchema memMetricSchema = TableSchema.newBuilder("mem_metric") + .addTag("host", DataType.String) + .addTimestamp("ts", DataType.TimestampMillisecond) + .addField("mem_usage", DataType.Float64) .build(); Table cpuMetric = Table.from(cpuMetricSchema); diff --git a/ingester-example/src/main/java/io/greptime/LowLevelApiWriteQuickStart.java b/ingester-example/src/main/java/io/greptime/LowLevelApiWriteQuickStart.java index 8ea8841..7184f15 100644 --- a/ingester-example/src/main/java/io/greptime/LowLevelApiWriteQuickStart.java +++ b/ingester-example/src/main/java/io/greptime/LowLevelApiWriteQuickStart.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import io.greptime.models.DataType; @@ -21,15 +22,15 @@ import io.greptime.models.Table; import io.greptime.models.TableSchema; import io.greptime.models.WriteOk; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.Arrays; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** - * @author jiachun.fjc + * */ public class LowLevelApiWriteQuickStart { @@ -38,17 +39,17 @@ public class LowLevelApiWriteQuickStart { public static void main(String[] args) throws ExecutionException, InterruptedException { GreptimeDB greptimeDB = TestConnector.connectToDefaultDB(); - TableSchema cpuMetricSchema = TableSchema.newBuilder("cpu_metric") // - .addTag("host", DataType.String) // - .addTimestamp("ts", DataType.TimestampMillisecond) // - .addField("cpu_user", DataType.Float64) // - .addField("cpu_sys", DataType.Float64) // + TableSchema cpuMetricSchema = TableSchema.newBuilder("cpu_metric") + .addTag("host", DataType.String) + .addTimestamp("ts", DataType.TimestampMillisecond) + .addField("cpu_user", DataType.Float64) + .addField("cpu_sys", DataType.Float64) .build(); - TableSchema memMetricSchema = TableSchema.newBuilder("mem_metric") // - .addTag("host", DataType.String) // - .addTimestamp("ts", DataType.TimestampMillisecond) // - .addField("mem_usage", DataType.Float64) // + TableSchema memMetricSchema = TableSchema.newBuilder("mem_metric") + .addTag("host", DataType.String) + .addTimestamp("ts", DataType.TimestampMillisecond) + .addField("mem_usage", DataType.Float64) .build(); Table cpuMetric = Table.from(cpuMetricSchema); @@ -76,9 +77,8 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc Result result = future.get(); - Result simpleResult = result // - .map(WriteOk::getSuccess) // - .mapErr(err -> err.getError().getMessage()); + Result simpleResult = + result.map(WriteOk::getSuccess).mapErr(err -> err.getError().getMessage()); if (simpleResult.isOk()) { LOG.info("Write success: {}", simpleResult.getOk()); } else { @@ -86,7 +86,8 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc } List delete_objs = Arrays.asList(cpuMetric.subRange(0, 5), memMetric.subRange(0, 5)); - Result deletes = greptimeDB.write(delete_objs, WriteOp.Delete).get(); + Result deletes = + greptimeDB.write(delete_objs, WriteOp.Delete).get(); if (deletes.isOk()) { LOG.info("Delete result: {}", result.getOk()); diff --git a/ingester-example/src/main/java/io/greptime/Memory.java b/ingester-example/src/main/java/io/greptime/Memory.java index 1e22d37..32492cb 100644 --- a/ingester-example/src/main/java/io/greptime/Memory.java +++ b/ingester-example/src/main/java/io/greptime/Memory.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import io.greptime.models.Column; @@ -20,7 +21,7 @@ import io.greptime.models.Metric; /** - * @author jiachun.fjc + * */ @Metric(name = "mem_metric") public class Memory { diff --git a/ingester-example/src/main/java/io/greptime/QueryJDBC.java b/ingester-example/src/main/java/io/greptime/QueryJDBC.java index 047b2ab..09f7f4b 100644 --- a/ingester-example/src/main/java/io/greptime/QueryJDBC.java +++ b/ingester-example/src/main/java/io/greptime/QueryJDBC.java @@ -13,10 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; @@ -28,9 +27,11 @@ import java.util.Objects; import java.util.Properties; import java.util.concurrent.ExecutionException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** - * @author jiachun.fjc + * */ public class QueryJDBC { @@ -49,12 +50,13 @@ public static void main(String[] args) throws Exception { ResultSet rs = statement.executeQuery("DESC cpu_metric"); LOG.info("Column | Type | Key | Null | Default | Semantic Type "); while (rs.next()) { - LOG.info("{} | {} | {} | {} | {} | {}", // - rs.getString(1), // - rs.getString(2), // - rs.getString(3), // - rs.getString(4), // - rs.getString(5), // + LOG.info( + "{} | {} | {} | {} | {} | {}", + rs.getString(1), + rs.getString(2), + rs.getString(3), + rs.getString(4), + rs.getString(5), rs.getString(6)); } @@ -68,10 +70,11 @@ public static void main(String[] args) throws Exception { rs = statement.executeQuery("SELECT * FROM cpu_metric ORDER BY ts DESC LIMIT 5"); LOG.info("host | ts | cpu_user | cpu_sys"); while (rs.next()) { - LOG.info("{} | {} | {} | {}", // - rs.getString("host"), // - rs.getTimestamp("ts"), // - rs.getDouble("cpu_user"), // + LOG.info( + "{} | {} | {} | {}", + rs.getString("host"), + rs.getTimestamp("ts"), + rs.getDouble("cpu_user"), rs.getDouble("cpu_sys")); } } diff --git a/ingester-example/src/main/java/io/greptime/TestConnector.java b/ingester-example/src/main/java/io/greptime/TestConnector.java index c056d5d..7f61dc6 100644 --- a/ingester-example/src/main/java/io/greptime/TestConnector.java +++ b/ingester-example/src/main/java/io/greptime/TestConnector.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import io.greptime.common.util.SerializingExecutor; @@ -22,7 +23,7 @@ import io.greptime.rpc.RpcOptions; /** - * @author jiachun.fjc + * */ public class TestConnector { @@ -34,9 +35,7 @@ public static GreptimeDB connectToDefaultDB() { // We can provide multiple endpoints that point to the same GreptimeDB cluster. // The client will make calls to these endpoints based on a load balancing strategy. String[] endpoints = {"127.0.0.1:4001"}; - GreptimeOptions opts = GreptimeOptions.newBuilder(endpoints, database) // - // Optional, the default value is fine. - // + GreptimeOptions opts = GreptimeOptions.newBuilder(endpoints, database) // Optional, the default value is fine. // Asynchronous thread pool, which is used to handle various asynchronous // tasks in the SDK (You are using a purely asynchronous SDK). If you do not // set it, there will be a default implementation, which you can reconfigure @@ -44,23 +43,19 @@ public static GreptimeDB connectToDefaultDB() { // The default implementation is: `SerializingExecutor` .asyncPool(new SerializingExecutor("async_pool")) // Optional, the default value is fine. - // // Sets the RPC options, in general, the default configuration is fine. .rpcOptions(RpcOptions.newDefault()) // Enable TLS connection when remote port is secured by TLS // .tlsOptions(null) // Optional, the default value is fine. - // // In some case of failure, a retry of write can be attempted. // The default is 1 .writeMaxRetries(1) // Optional, the default value is fine. - // // Write flow limit: maximum number of data points in-flight. It does not take effect on `StreamWriter` // The default is 10 * 65536 .maxInFlightWritePoints(10 * 65536) // Optional, the default value is fine. - // // Write flow limit: the policy to use when the write flow limit is exceeded. // All options: // - `LimitedPolicy.DiscardPolicy`: discard the data if the limiter is full. @@ -70,18 +65,15 @@ public static GreptimeDB connectToDefaultDB() { // The default is `LimitedPolicy.AbortOnBlockingTimeoutPolicy` .writeLimitedPolicy(LimitedPolicy.defaultWriteLimitedPolicy()) // Optional, the default value is fine. - // // The default rate limit for stream writer. It only takes effect when we do not specify the // `maxPointsPerSecond` when creating a `StreamWriter`. // The default is 10 * 65536 .defaultStreamMaxWritePointsPerSecond(10 * 65536) // Optional, the default value is fine. - // // Refresh frequency of route tables. The background refreshes all route tables // periodically. By default, the route tables will not be refreshed. .routeTableRefreshPeriodSeconds(-1) // Optional, the default value is fine. - // // Sets the request router, The internal default implementation works well. // You don't need to set it unless you have special requirements. .router(null) diff --git a/ingester-example/src/main/resources/db-connection.properties b/ingester-example/src/main/resources/db-connection.properties index 9e47c11..dc7f61a 100644 --- a/ingester-example/src/main/resources/db-connection.properties +++ b/ingester-example/src/main/resources/db-connection.properties @@ -1,3 +1,17 @@ +# Copyright 2023 Greptime Team +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + # DataSource db.database-driver=com.mysql.cj.jdbc.Driver db.url=jdbc:mysql://localhost:4002/public diff --git a/ingester-example/src/main/resources/log4j2.xml b/ingester-example/src/main/resources/log4j2.xml index 8763e64..d99eb5b 100644 --- a/ingester-example/src/main/resources/log4j2.xml +++ b/ingester-example/src/main/resources/log4j2.xml @@ -1,4 +1,21 @@ + diff --git a/ingester-grpc/pom.xml b/ingester-grpc/pom.xml index 8aede03..90451f7 100644 --- a/ingester-grpc/pom.xml +++ b/ingester-grpc/pom.xml @@ -1,9 +1,26 @@ + 4.0.0 - greptimedb-ingester io.greptime + greptimedb-ingester 0.7.3 @@ -13,9 +30,6 @@ 2.9.1 1.56.1 0.3.6 - 8 - 8 - UTF-8 @@ -36,8 +50,8 @@ ${io.grpc.version} - guava com.google.guava + guava @@ -64,8 +78,8 @@ ${limits.version} - slf4j-api org.slf4j + slf4j-api @@ -95,5 +109,4 @@ test - diff --git a/ingester-grpc/src/main/java/io/greptime/rpc/GrpcClient.java b/ingester-grpc/src/main/java/io/greptime/rpc/GrpcClient.java index 71597d5..c877f1c 100644 --- a/ingester-grpc/src/main/java/io/greptime/rpc/GrpcClient.java +++ b/ingester-grpc/src/main/java/io/greptime/rpc/GrpcClient.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc; import com.google.protobuf.Message; @@ -56,8 +57,6 @@ import io.grpc.protobuf.ProtoUtils; import io.grpc.stub.ClientCalls; import io.grpc.stub.StreamObserver; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.File; import java.util.List; import java.util.Map; @@ -74,18 +73,18 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; import javax.net.ssl.SSLException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Grpc client implementation. - * - * @author jiachun.fjc */ public class GrpcClient implements RpcClient { private static final Logger LOG = LoggerFactory.getLogger(GrpcClient.class); - private static final SharedThreadPool SHARED_ASYNC_POOL = new SharedThreadPool( - new ObjectPool.Resource() { + private static final SharedThreadPool SHARED_ASYNC_POOL = + new SharedThreadPool(new ObjectPool.Resource() { @Override public ExecutorService create() { @@ -168,20 +167,15 @@ public void registerConnectionObserver(ConnectionObserver observer) { @Override public void invokeAsync( - Endpoint endpoint, - Req request, - Context ctx, - Observer observer, - long timeoutMs) { + Endpoint endpoint, Req request, Context ctx, Observer observer, long timeoutMs) { checkArgs(endpoint, request, ctx, observer); ContextToHeadersInterceptor.setCurrentCtx(ctx); - MethodDescriptor method = getCallMethod(request, - MethodDescriptor.MethodType.UNARY); + MethodDescriptor method = getCallMethod(request, MethodDescriptor.MethodType.UNARY); long timeout = calcTimeout(timeoutMs); - CallOptions callOpts = CallOptions.DEFAULT // - .withDeadlineAfter(timeout, TimeUnit.MILLISECONDS) // - .withExecutor(getObserverExecutor(observer)); + CallOptions callOpts = CallOptions.DEFAULT + .withDeadlineAfter(timeout, TimeUnit.MILLISECONDS) + .withExecutor(getObserverExecutor(observer)); String methodName = method.getFullMethodName(); String address = endpoint.toString(); @@ -205,7 +199,6 @@ public void invokeAsync( public void onNext(Message value) { onReceived(false); observer.onNext((Resp) value); - } @Override @@ -237,15 +230,12 @@ private long onReceived(boolean onError) { @Override public void invokeServerStreaming( - Endpoint endpoint, - Req request, - Context ctx, - Observer observer) { + Endpoint endpoint, Req request, Context ctx, Observer observer) { checkArgs(endpoint, request, ctx, observer); ContextToHeadersInterceptor.setCurrentCtx(ctx); - MethodDescriptor method = getCallMethod(request, - MethodDescriptor.MethodType.SERVER_STREAMING); + MethodDescriptor method = + getCallMethod(request, MethodDescriptor.MethodType.SERVER_STREAMING); CallOptions callOpts = CallOptions.DEFAULT.withExecutor(getObserverExecutor(observer)); String methodName = method.getFullMethodName(); @@ -263,39 +253,36 @@ public void invokeServerStreaming( String target = target(ch, address); - ClientCalls.asyncServerStreamingCall(ch.newCall(method, callOpts), (Message) request, - new StreamObserver() { + ClientCalls.asyncServerStreamingCall( + ch.newCall(method, callOpts), (Message) request, new StreamObserver() { - @SuppressWarnings("unchecked") - @Override - public void onNext(Message value) { - observer.onNext((Resp) value); - } + @SuppressWarnings("unchecked") + @Override + public void onNext(Message value) { + observer.onNext((Resp) value); + } - @Override - public void onError(Throwable err) { - attachErrMsg(err, SERVER_STREAMING_CALL, methodName, target, startCall, -1, ctx); - observer.onError(err); - } + @Override + public void onError(Throwable err) { + attachErrMsg(err, SERVER_STREAMING_CALL, methodName, target, startCall, -1, ctx); + observer.onError(err); + } - @Override - public void onCompleted() { - observer.onCompleted(); - } - }); + @Override + public void onCompleted() { + observer.onCompleted(); + } + }); } @Override public Observer invokeClientStreaming( - Endpoint endpoint, - Req defaultReqIns, - Context ctx, - Observer respObserver) { + Endpoint endpoint, Req defaultReqIns, Context ctx, Observer respObserver) { checkArgs(endpoint, defaultReqIns, ctx, respObserver); ContextToHeadersInterceptor.setCurrentCtx(ctx); - MethodDescriptor method = getCallMethod(defaultReqIns, - MethodDescriptor.MethodType.CLIENT_STREAMING); + MethodDescriptor method = + getCallMethod(defaultReqIns, MethodDescriptor.MethodType.CLIENT_STREAMING); CallOptions callOpts = CallOptions.DEFAULT.withExecutor(getObserverExecutor(respObserver)); String methodName = method.getFullMethodName(); @@ -315,26 +302,26 @@ public Observer invokeClientStreaming( String target = target(ch, address); - StreamObserver gRpcObs = ClientCalls.asyncClientStreamingCall(ch.newCall(method, callOpts), - new StreamObserver() { + StreamObserver gRpcObs = + ClientCalls.asyncClientStreamingCall(ch.newCall(method, callOpts), new StreamObserver() { - @SuppressWarnings("unchecked") - @Override - public void onNext(Message value) { - respObserver.onNext((Resp) value); - } + @SuppressWarnings("unchecked") + @Override + public void onNext(Message value) { + respObserver.onNext((Resp) value); + } - @Override - public void onError(Throwable err) { - attachErrMsg(err, CLIENT_STREAMING_CALL, methodName, target, startCall, -1, ctx); - respObserver.onError(err); - } + @Override + public void onError(Throwable err) { + attachErrMsg(err, CLIENT_STREAMING_CALL, methodName, target, startCall, -1, ctx); + respObserver.onError(err); + } - @Override - public void onCompleted() { - respObserver.onCompleted(); - } - }); + @Override + public void onCompleted() { + respObserver.onCompleted(); + } + }); return new Observer() { @@ -382,23 +369,23 @@ private ClientRequestLimitInterceptor createRequestLimitInterceptor(RpcOptions.L Limit limit; switch (kind) { case Vegas: - limit = VegasLimit.newBuilder() // - .initialLimit(Math.max(minInitialLimit, this.opts.getInitialLimit())) // - .maxConcurrency(this.opts.getMaxLimit()) // - .smoothing(this.opts.getSmoothing()) // - .logOnLimitChange(this.opts.isLogOnLimitChange()) // - .metricRegistry(metricRegistry) // + limit = VegasLimit.newBuilder() + .initialLimit(Math.max(minInitialLimit, this.opts.getInitialLimit())) + .maxConcurrency(this.opts.getMaxLimit()) + .smoothing(this.opts.getSmoothing()) + .logOnLimitChange(this.opts.isLogOnLimitChange()) + .metricRegistry(metricRegistry) .build(); break; case Gradient: - limit = Gradient2Limit.newBuilder() // - .initialLimit(Math.max(minInitialLimit, this.opts.getInitialLimit())) // - .maxConcurrency(this.opts.getMaxLimit()) // - .longWindow(this.opts.getLongRttWindow()) // - .smoothing(this.opts.getSmoothing()) // - .queueSize(Math.max(4, Cpus.cpus() << 1)) // - .logOnLimitChange(this.opts.isLogOnLimitChange()) // - .metricRegistry(metricRegistry) // + limit = Gradient2Limit.newBuilder() + .initialLimit(Math.max(minInitialLimit, this.opts.getInitialLimit())) + .maxConcurrency(this.opts.getMaxLimit()) + .longWindow(this.opts.getLongRttWindow()) + .smoothing(this.opts.getSmoothing()) + .queueSize(Math.max(4, Cpus.cpus() << 1)) + .logOnLimitChange(this.opts.isLogOnLimitChange()) + .metricRegistry(metricRegistry) .build(); break; default: @@ -406,45 +393,40 @@ private ClientRequestLimitInterceptor createRequestLimitInterceptor(RpcOptions.L } RequestLimiterBuilder limiterBuilder = RequestLimiterBuilder.newBuilder() - .named(LIMITER_NAME) // - .metricRegistry(metricRegistry) // - .blockOnLimit(this.opts.isBlockOnLimit(), this.opts.getDefaultRpcTimeout()) // + .named(LIMITER_NAME) + .metricRegistry(metricRegistry) + .blockOnLimit(this.opts.isBlockOnLimit(), this.opts.getDefaultRpcTimeout()) .limit(limit); Map methodsLimitPercent = this.marshallerRegistry.getAllMethodsLimitPercent(); if (methodsLimitPercent.isEmpty()) { return new ClientRequestLimitInterceptor(limiterBuilder.build()); } else { - double sum = methodsLimitPercent // - .values() // - .stream() // - .reduce(0.0, Double::sum); + double sum = methodsLimitPercent.values().stream().reduce(0.0, Double::sum); Ensures.ensure(Math.abs(sum - 1.0) < 0.1, "the total percent sum of partitions must be near 100%"); methodsLimitPercent.forEach(limiterBuilder::partition); - return new ClientRequestLimitInterceptor(limiterBuilder.partitionByMethod().build(), methodsLimitPercent::containsKey); + return new ClientRequestLimitInterceptor( + limiterBuilder.partitionByMethod().build(), methodsLimitPercent::containsKey); } } - private void attachErrMsg(Throwable err, String callType, String method, String target, long startCall, - long duration, Context ctx) { - StringBuilder buf = StringBuilderHelper.get() // - .append("Grpc ") // - .append(callType) // - .append(" got an error,") // - .append(" method=") // - .append(method) // - .append(", target=") // - .append(target) // - .append(", startCall=") // + private void attachErrMsg( + Throwable err, String callType, String method, String target, long startCall, long duration, Context ctx) { + StringBuilder buf = StringBuilderHelper.get() + .append("Grpc ") + .append(callType) + .append(" got an error,") + .append(" method=") + .append(method) + .append(", target=") + .append(target) + .append(", startCall=") .append(startCall); if (duration > 0) { - buf.append(", duration=") // - .append(duration) // - .append(" millis"); + buf.append(", duration=").append(duration).append(" millis"); } - buf.append(", ctx=") // - .append(ctx); + buf.append(", ctx=").append(ctx); err.addSuppressed(new OnlyErrorMessage(buf.toString())); } @@ -498,8 +480,10 @@ private boolean checkConnectivity(Endpoint endpoint, ManagedChannel ch) { return false; } - LOG.warn("Channel {} in [INACTIVE] state {} times, it has been removed from the pool.", - target(removedCh, endpoint), c); + LOG.warn( + "Channel {} in [INACTIVE] state {} times, it has been removed from the pool.", + target(removedCh, endpoint), + c); if (removedCh != ch) { // Now that it's removed, close it @@ -512,7 +496,9 @@ private boolean checkConnectivity(Endpoint endpoint, ManagedChannel ch) { } private int incConnFailuresCount(Endpoint endpoint) { - return this.transientFailures.computeIfAbsent(endpoint, ep -> new AtomicInteger()).incrementAndGet(); + return this.transientFailures + .computeIfAbsent(endpoint, ep -> new AtomicInteger()) + .incrementAndGet(); } private void clearConnFailuresCount(Endpoint endpoint) { @@ -527,12 +513,11 @@ private MethodDescriptor getCallMethod(Object request, MethodD Ensures.ensureNonNull(defaultReqIns, "null default request instance: " + reqCls.getName()); Ensures.ensureNonNull(defaultRespIns, "null default response instance: " + reqCls.getName()); - return MethodDescriptor // - .newBuilder() // - .setType(methodType) // - .setFullMethodName(this.marshallerRegistry.getMethodName(reqCls, methodType)) // - .setRequestMarshaller(ProtoUtils.marshaller(defaultReqIns)) // - .setResponseMarshaller(ProtoUtils.marshaller(defaultRespIns)) // + return MethodDescriptor.newBuilder() + .setType(methodType) + .setFullMethodName(this.marshallerRegistry.getMethodName(reqCls, methodType)) + .setRequestMarshaller(ProtoUtils.marshaller(defaultReqIns)) + .setResponseMarshaller(ProtoUtils.marshaller(defaultRespIns)) .build(); } @@ -558,8 +543,7 @@ private SslContext newSslContext(TlsOptions tlsOptions) { if (clientCertChain.isPresent() && privateKey.isPresent()) { if (privateKeyPassword.isPresent()) { - builder.keyManager(clientCertChain.get(), privateKey.get(), - privateKeyPassword.get()); + builder.keyManager(clientCertChain.get(), privateKey.get(), privateKeyPassword.get()); } else { builder.keyManager(clientCertChain.get(), privateKey.get()); } @@ -584,16 +568,17 @@ private IdChannel newChannel(Endpoint endpoint) { innerChannelBuilder.usePlaintext(); } - ManagedChannel innerChannel = innerChannelBuilder.executor(this.asyncPool) // - .intercept(this.interceptors) // - .maxInboundMessageSize(this.opts.getMaxInboundMessageSize()) // - .flowControlWindow(this.opts.getFlowControlWindow()) // - .idleTimeout(this.opts.getIdleTimeoutSeconds(), TimeUnit.SECONDS) // - .keepAliveTime(this.opts.getKeepAliveTimeSeconds(), TimeUnit.SECONDS) // - .keepAliveTimeout(this.opts.getKeepAliveTimeoutSeconds(), TimeUnit.SECONDS) // - .keepAliveWithoutCalls(this.opts.isKeepAliveWithoutCalls()) // - .withOption(ChannelOption.SO_REUSEADDR, true) // - .withOption(ChannelOption.TCP_NODELAY, true) // + ManagedChannel innerChannel = innerChannelBuilder + .executor(this.asyncPool) + .intercept(this.interceptors) + .maxInboundMessageSize(this.opts.getMaxInboundMessageSize()) + .flowControlWindow(this.opts.getFlowControlWindow()) + .idleTimeout(this.opts.getIdleTimeoutSeconds(), TimeUnit.SECONDS) + .keepAliveTime(this.opts.getKeepAliveTimeSeconds(), TimeUnit.SECONDS) + .keepAliveTimeout(this.opts.getKeepAliveTimeoutSeconds(), TimeUnit.SECONDS) + .keepAliveWithoutCalls(this.opts.isKeepAliveWithoutCalls()) + .withOption(ChannelOption.SO_REUSEADDR, true) + .withOption(ChannelOption.TCP_NODELAY, true) .build(); IdChannel idChannel = new IdChannel(innerChannel); @@ -654,20 +639,20 @@ private void notifyShutdown(Endpoint endpoint) { @Override public void display(Printer out) { - out.println("--- GrpcClient ---")// - .print("started=") // - .println(this.started) // - .print("opts=") // - .println(this.opts) // - .print("connectionObservers=") // - .println(this.connectionObservers) // - .print("asyncPool=") // - .println(this.asyncPool) // - .print("interceptors=") // - .println(this.interceptors) // - .print("managedChannelPool=") // - .println(this.managedChannelPool) // - .print("transientFailures=") // + out.println("--- GrpcClient ---") + .print("started=") + .println(this.started) + .print("opts=") + .println(this.opts) + .print("connectionObservers=") + .println(this.connectionObservers) + .print("asyncPool=") + .println(this.asyncPool) + .print("interceptors=") + .println(this.interceptors) + .print("managedChannelPool=") + .println(this.managedChannelPool) + .print("transientFailures=") .println(this.transientFailures); } @@ -676,12 +661,12 @@ private static String target(Channel ch, Endpoint ep) { } private static String target(Channel ch, String address) { - return StringBuilderHelper.get() // - .append('[') // - .append(channelId(ch)) // - .append('/') // - .append(address) // - .append(']') // + return StringBuilderHelper.get() + .append('[') + .append(channelId(ch)) + .append('/') + .append(address) + .append(']') .toString(); } @@ -692,10 +677,7 @@ private static long channelId(Channel ch) { return -1; } - private static void checkArgs(Endpoint endpoint, // - Object request, // - Context ctx, // - Observer observer) { + private static void checkArgs(Endpoint endpoint, Object request, Context ctx, Observer observer) { Ensures.ensureNonNull(endpoint, "null `endpoint`"); Ensures.ensureNonNull(request, "null `request`"); Ensures.ensureNonNull(ctx, "null `ctx`"); @@ -707,15 +689,15 @@ private static ExecutorService newSharedPool() { int coreWorks = SystemPropertyUtil.getInt(Keys.GRPC_POOL_CORE_WORKERS, Cpus.cpus()); int maximumWorks = SystemPropertyUtil.getInt(Keys.GRPC_POOL_MAXIMUM_WORKERS, Cpus.cpus() << 2); - return ThreadPoolUtil.newBuilder() // - .poolName(name) // - .enableMetric(true) // - .coreThreads(coreWorks) // - .maximumThreads(maximumWorks) // - .keepAliveSeconds(60L) // - .workQueue(new ArrayBlockingQueue<>(512)) // - .threadFactory(new NamedThreadFactory(name, true)) // - .rejectedHandler(new AsyncPoolRejectedHandler(name)) // + return ThreadPoolUtil.newBuilder() + .poolName(name) + .enableMetric(true) + .coreThreads(coreWorks) + .maximumThreads(maximumWorks) + .keepAliveSeconds(60L) + .workQueue(new ArrayBlockingQueue<>(512)) + .threadFactory(new NamedThreadFactory(name, true)) + .rejectedHandler(new AsyncPoolRejectedHandler(name)) .build(); } @@ -729,8 +711,11 @@ private static class AsyncPoolRejectedHandler implements RejectedExecutionHandle @Override public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { - LOG.error("Thread poll {} is busy, the caller thread {} will run this task {}.", this.name, - Thread.currentThread(), r); + LOG.error( + "Thread poll {} is busy, the caller thread {} will run this task {}.", + this.name, + Thread.currentThread(), + r); if (!executor.isShutdown()) { r.run(); } diff --git a/ingester-grpc/src/main/java/io/greptime/rpc/GrpcFactory.java b/ingester-grpc/src/main/java/io/greptime/rpc/GrpcFactory.java index 3dc43ad..19f0c0c 100644 --- a/ingester-grpc/src/main/java/io/greptime/rpc/GrpcFactory.java +++ b/ingester-grpc/src/main/java/io/greptime/rpc/GrpcFactory.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc; import com.google.protobuf.Message; @@ -20,21 +21,16 @@ /** * GreptimeDB grpc impl service factory. - * - * @author jiachun.fjc */ @SPI public class GrpcFactory implements RpcFactory { @SuppressWarnings("unchecked") @Override - public void register(MethodDescriptor method, // - Class reqCls, // - Object defaultReqIns, // - Object defaultRespIns) { - getMarshallerRegistry() // - .registerMarshaller(method, (Class) reqCls, (Message) defaultReqIns, - (Message) defaultRespIns); + public void register(MethodDescriptor method, Class reqCls, Object defaultReqIns, Object defaultRespIns) { + getMarshallerRegistry() + .registerMarshaller( + method, (Class) reqCls, (Message) defaultReqIns, (Message) defaultRespIns); } @Override diff --git a/ingester-grpc/src/main/java/io/greptime/rpc/IdChannel.java b/ingester-grpc/src/main/java/io/greptime/rpc/IdChannel.java index f3fe436..8412303 100644 --- a/ingester-grpc/src/main/java/io/greptime/rpc/IdChannel.java +++ b/ingester-grpc/src/main/java/io/greptime/rpc/IdChannel.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc; import io.grpc.CallOptions; @@ -25,8 +26,6 @@ /** * A managed channel that has a channel id. - * - * @author jiachun.fjc */ public class IdChannel extends ManagedChannel { @@ -106,9 +105,6 @@ public void enterIdle() { @Override public String toString() { - return "IdChannel{" + // - "channelId=" + channelId + // - ", channel=" + channel + // - '}'; + return "IdChannel{" + "channelId=" + channelId + ", channel=" + channel + '}'; } } diff --git a/ingester-grpc/src/main/java/io/greptime/rpc/ManagedChannelHelper.java b/ingester-grpc/src/main/java/io/greptime/rpc/ManagedChannelHelper.java index c1686c5..e49e036 100644 --- a/ingester-grpc/src/main/java/io/greptime/rpc/ManagedChannelHelper.java +++ b/ingester-grpc/src/main/java/io/greptime/rpc/ManagedChannelHelper.java @@ -13,17 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc; import io.grpc.ManagedChannel; +import java.util.concurrent.TimeUnit; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.concurrent.TimeUnit; /** * Managed channel shutdown helper. - * - * @author jiachun.fjc */ public final class ManagedChannelHelper { diff --git a/ingester-grpc/src/main/java/io/greptime/rpc/MarshallerRegistry.java b/ingester-grpc/src/main/java/io/greptime/rpc/MarshallerRegistry.java index 1ca1ad5..3b59907 100644 --- a/ingester-grpc/src/main/java/io/greptime/rpc/MarshallerRegistry.java +++ b/ingester-grpc/src/main/java/io/greptime/rpc/MarshallerRegistry.java @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc; import com.google.protobuf.Message; import io.greptime.common.util.Ensures; - import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -25,8 +25,6 @@ /** * Marshaller registry for grpc service. - * - * @author jiachun.fjc */ public interface MarshallerRegistry { @@ -37,8 +35,7 @@ public interface MarshallerRegistry { * @param methodType grpc method type * @return method name */ - default String getMethodName(Class reqCls, // - io.grpc.MethodDescriptor.MethodType methodType) { + default String getMethodName(Class reqCls, io.grpc.MethodDescriptor.MethodType methodType) { return getMethodName(reqCls, supportedMethodType(methodType)); } @@ -64,9 +61,8 @@ default String getMethodName(Class reqCls, // * @return method's limit percent */ default Map getAllMethodsLimitPercent() { - return getAllMethodDescriptors() // - .stream() // - .filter(mth -> mth.getLimitPercent() > 0) // + return getAllMethodDescriptors().stream() + .filter(mth -> mth.getLimitPercent() > 0) .collect(Collectors.toMap(MethodDescriptor::getName, MethodDescriptor::getLimitPercent)); } @@ -94,10 +90,8 @@ default Map getAllMethodsLimitPercent() { * @param defaultReqIns default request instance * @param defaultRespIns default response instance */ - void registerMarshaller(MethodDescriptor method, // - Class reqCls, // - Message defaultReqIns, // - Message defaultRespIns); + void registerMarshaller( + MethodDescriptor method, Class reqCls, Message defaultReqIns, Message defaultRespIns); default MethodDescriptor.MethodType supportedMethodType(io.grpc.MethodDescriptor.MethodType mt) { switch (mt) { @@ -115,12 +109,10 @@ default MethodDescriptor.MethodType supportedMethodType(io.grpc.MethodDescriptor enum DefaultMarshallerRegistry implements MarshallerRegistry { INSTANCE; - private final Map, Map> methods = - new ConcurrentHashMap<>(); - private final Map, Message> requests = - new ConcurrentHashMap<>(); - private final Map, Message> responses = - new ConcurrentHashMap<>(); + private final Map, Map> methods = + new ConcurrentHashMap<>(); + private final Map, Message> requests = new ConcurrentHashMap<>(); + private final Map, Message> responses = new ConcurrentHashMap<>(); @Override public String getMethodName(Class reqCls, MethodDescriptor.MethodType methodType) { @@ -133,9 +125,7 @@ public String getMethodName(Class reqCls, MethodDescriptor.Me @Override public Set getAllMethodDescriptors() { - return this.methods - .values() - .stream() + return this.methods.values().stream() .flatMap(map -> map.values().stream()) .collect(Collectors.toSet()); } @@ -151,11 +141,14 @@ public Message getDefaultResponseInstance(Class reqCls) { } @Override - public void registerMarshaller(MethodDescriptor method, // - Class reqCls, // - Message defaultReqIns, // - Message defaultRespIns) { - this.methods.computeIfAbsent(reqCls, cls -> new ConcurrentHashMap<>()).put(method.getType(), method); + public void registerMarshaller( + MethodDescriptor method, + Class reqCls, + Message defaultReqIns, + Message defaultRespIns) { + this.methods + .computeIfAbsent(reqCls, cls -> new ConcurrentHashMap<>()) + .put(method.getType(), method); this.requests.put(reqCls, defaultReqIns); this.responses.put(reqCls, defaultRespIns); } diff --git a/ingester-grpc/src/main/java/io/greptime/rpc/interceptors/ClientRequestLimitInterceptor.java b/ingester-grpc/src/main/java/io/greptime/rpc/interceptors/ClientRequestLimitInterceptor.java index 5be99e2..78600a3 100644 --- a/ingester-grpc/src/main/java/io/greptime/rpc/interceptors/ClientRequestLimitInterceptor.java +++ b/ingester-grpc/src/main/java/io/greptime/rpc/interceptors/ClientRequestLimitInterceptor.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc.interceptors; import com.netflix.concurrency.limits.Limiter; @@ -37,8 +38,6 @@ * reached. *

* Refer to `concurrency-limit-grpc` - * - * @author jiachun.fjc */ public class ClientRequestLimitInterceptor implements ClientInterceptor { @@ -59,9 +58,8 @@ public ClientRequestLimitInterceptor(Limiter limiter, Function< } @Override - public ClientCall interceptCall(MethodDescriptor method, // - CallOptions callOpts, // - Channel next) { + public ClientCall interceptCall( + MethodDescriptor method, CallOptions callOpts, Channel next) { if (shouldNotUseLimiter(method.getType()) || !this.filter.apply(method.getFullMethodName())) { return next.newCall(method, callOpts); } @@ -70,44 +68,49 @@ public ClientCall interceptCall(MethodDescriptor this.limiter.acquire(() -> methodName)) - .map(listener -> (ClientCall) new ForwardingClientCall.SimpleForwardingClientCall(next.newCall(method, callOpts)) { + .map(listener -> (ClientCall) + new ForwardingClientCall.SimpleForwardingClientCall( + next.newCall(method, callOpts)) { - private final AtomicBoolean done = new AtomicBoolean(false); + private final AtomicBoolean done = new AtomicBoolean(false); - @Override - public void start(Listener respListener, Metadata headers) { - super.start(new ForwardingClientCallListener.SimpleForwardingClientCallListener(respListener) { + @Override + public void start(Listener respListener, Metadata headers) { + super.start( + new ForwardingClientCallListener.SimpleForwardingClientCallListener( + respListener) { + + @Override + public void onClose(Status status, Metadata trailers) { + try { + super.onClose(status, trailers); + } finally { + if (done.compareAndSet(false, true)) { + if (status.isOk()) { + listener.onSuccess(); + } else if (Status.Code.UNAVAILABLE == status.getCode()) { + listener.onDropped(); + } else { + listener.onIgnore(); + } + } + } + } + }, + headers); + } @Override - public void onClose(Status status, Metadata trailers) { + public void cancel(String message, Throwable cause) { try { - super.onClose(status, trailers); + super.cancel(message, cause); } finally { if (done.compareAndSet(false, true)) { - if (status.isOk()) { - listener.onSuccess(); - } else if (Status.Code.UNAVAILABLE == status.getCode()) { - listener.onDropped(); - } else { - listener.onIgnore(); - } + listener.onIgnore(); } } } - }, headers); - } - - @Override - public void cancel(String message, Throwable cause) { - try { - super.cancel(message, cause); - } finally { - if (done.compareAndSet(false, true)) { - listener.onIgnore(); - } - } - } - }) + }) .orElseGet(() -> new ClientCall() { private Listener respListener; @@ -118,12 +121,10 @@ public void start(Listener respListener, Metadata headers) { } @Override - public void request(int numMessages) { - } + public void request(int numMessages) {} @Override - public void cancel(String message, Throwable cause) { - } + public void cancel(String message, Throwable cause) {} @Override public void halfClose() { @@ -131,8 +132,7 @@ public void halfClose() { } @Override - public void sendMessage(ReqT message) { - } + public void sendMessage(ReqT message) {} }); } diff --git a/ingester-grpc/src/main/java/io/greptime/rpc/interceptors/ContextToHeadersInterceptor.java b/ingester-grpc/src/main/java/io/greptime/rpc/interceptors/ContextToHeadersInterceptor.java index 5614616..f418e21 100644 --- a/ingester-grpc/src/main/java/io/greptime/rpc/interceptors/ContextToHeadersInterceptor.java +++ b/ingester-grpc/src/main/java/io/greptime/rpc/interceptors/ContextToHeadersInterceptor.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc.interceptors; import io.greptime.rpc.Context; @@ -26,8 +27,6 @@ /** * Add RPC context to gRPC headers. - * - * @author jiachun.fjc */ public class ContextToHeadersInterceptor implements ClientInterceptor { @@ -38,14 +37,13 @@ public static void setCurrentCtx(Context ctx) { } @Override - public ClientCall interceptCall(MethodDescriptor method, // - CallOptions callOpts, // - Channel next) { + public ClientCall interceptCall( + MethodDescriptor method, CallOptions callOpts, Channel next) { return new HeaderAttachingClientCall<>(next.newCall(method, callOpts)); } - private static final class HeaderAttachingClientCall extends - ForwardingClientCall.SimpleForwardingClientCall { + private static final class HeaderAttachingClientCall + extends ForwardingClientCall.SimpleForwardingClientCall { HeaderAttachingClientCall(ClientCall delegate) { super(delegate); @@ -55,10 +53,10 @@ private static final class HeaderAttachingClientCall extends public void start(Listener respListener, Metadata headers) { Context ctx = CURRENT_CTX.get(); if (ctx != null) { - ctx.entrySet().forEach(e -> headers.put( // - Metadata.Key.of(e.getKey(), Metadata.ASCII_STRING_MARSHALLER), // - String.valueOf(e.getValue())) // - ); + ctx.entrySet() + .forEach(e -> headers.put( + Metadata.Key.of(e.getKey(), Metadata.ASCII_STRING_MARSHALLER), + String.valueOf(e.getValue()))); } CURRENT_CTX.remove(); super.start(respListener, headers); diff --git a/ingester-grpc/src/main/java/io/greptime/rpc/interceptors/MetricInterceptor.java b/ingester-grpc/src/main/java/io/greptime/rpc/interceptors/MetricInterceptor.java index 7b9469d..9386f39 100644 --- a/ingester-grpc/src/main/java/io/greptime/rpc/interceptors/MetricInterceptor.java +++ b/ingester-grpc/src/main/java/io/greptime/rpc/interceptors/MetricInterceptor.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc.interceptors; import com.codahale.metrics.Counter; @@ -29,8 +30,6 @@ /** * Request method metric interceptor. - * - * @author jiachun.fjc */ public class MetricInterceptor implements ClientInterceptor { @@ -44,8 +43,8 @@ public class MetricInterceptor implements ClientInterceptor { private static final Counter RESP_BYTES = MetricsUtil.counter(RESP_TYPE, BYTES); @Override - public ClientCall interceptCall(MethodDescriptor method, - CallOptions callOpts, Channel next) { + public ClientCall interceptCall( + MethodDescriptor method, CallOptions callOpts, Channel next) { String methodName = method.getFullMethodName(); MetricsUtil.meter(REQ_TYPE, QPS, methodName).mark(); @@ -53,25 +52,29 @@ public ClientCall interceptCall(MethodDescriptor respListener, Metadata headers) { - super.start(new ForwardingClientCallListener.SimpleForwardingClientCallListener(respListener) { + super.start( + new ForwardingClientCallListener.SimpleForwardingClientCallListener(respListener) { - @Override - public void onMessage(RespT msg) { - if (msg instanceof MessageLite) { - int size = ((MessageLite) msg).getSerializedSize(); - MetricsUtil.histogram(RESP_TYPE, SERIALIZED_BYTES, methodName).update(size); - RESP_BYTES.inc(size); - } - super.onMessage(msg); - } - }, headers); + @Override + public void onMessage(RespT msg) { + if (msg instanceof MessageLite) { + int size = ((MessageLite) msg).getSerializedSize(); + MetricsUtil.histogram(RESP_TYPE, SERIALIZED_BYTES, methodName) + .update(size); + RESP_BYTES.inc(size); + } + super.onMessage(msg); + } + }, + headers); } @Override public void sendMessage(ReqT msg) { if (msg instanceof MessageLite) { int size = ((MessageLite) msg).getSerializedSize(); - MetricsUtil.histogram(REQ_TYPE, SERIALIZED_BYTES, methodName).update(size); + MetricsUtil.histogram(REQ_TYPE, SERIALIZED_BYTES, methodName) + .update(size); REQ_BYTES.inc(size); } super.sendMessage(msg); diff --git a/ingester-grpc/src/main/java/io/greptime/rpc/limit/Gradient2Limit.java b/ingester-grpc/src/main/java/io/greptime/rpc/limit/Gradient2Limit.java index d473405..b56d682 100644 --- a/ingester-grpc/src/main/java/io/greptime/rpc/limit/Gradient2Limit.java +++ b/ingester-grpc/src/main/java/io/greptime/rpc/limit/Gradient2Limit.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc.limit; import com.netflix.concurrency.limits.MetricIds; @@ -22,11 +23,10 @@ import com.netflix.concurrency.limits.limit.AbstractLimit; import com.netflix.concurrency.limits.limit.measurement.ExpAvgMeasurement; import com.netflix.concurrency.limits.limit.measurement.Measurement; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.concurrent.TimeUnit; import java.util.function.Function; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Concurrency limit algorithm that adjusts the limit based on the gradient of change of the current average RTT and @@ -227,6 +227,7 @@ public static Gradient2Limit newDefault() { * Maximum allowed limit providing an upper bound failsafe */ private final int maxLimit; + private final int minLimit; private final Function queueSize; private final double smoothing; @@ -282,7 +283,7 @@ public int _update(long startTime, long rtt, int inflight, boolean didDrop) { // Rtt could be higher than rtt_noload because of smoothing rtt noload updates // so set to 1.0 to indicate no queuing. Otherwise calculate the slope and don't - // allow it to be reduced by more than half to avoid aggressive load-shedding due to + // allow it to be reduced by more than half to avoid aggressive load-shedding due to // outliers. double gradient = Math.max(0.5, Math.min(1.0, this.tolerance * longRtt / shortRtt)); double newLimit = currLimit * gradient + queueSize; @@ -290,7 +291,8 @@ public int _update(long startTime, long rtt, int inflight, boolean didDrop) { newLimit = Math.max(this.minLimit, Math.min(this.maxLimit, newLimit)); if (this.logOnLimitChange && (int) currLimit != (int) newLimit) { - LOG.info("New limit={}, previous limit={}, shortRtt={} ms, longRtt={} ms, queueSize={}, gradient={}.", + LOG.info( + "New limit={}, previous limit={}, shortRtt={} ms, longRtt={} ms, queueSize={}, gradient={}.", (int) newLimit, (int) currLimit, getLastRtt(TimeUnit.MICROSECONDS) / 1000.0, diff --git a/ingester-grpc/src/main/java/io/greptime/rpc/limit/LimitMetricRegistry.java b/ingester-grpc/src/main/java/io/greptime/rpc/limit/LimitMetricRegistry.java index e8c1ef9..c5ddf44 100644 --- a/ingester-grpc/src/main/java/io/greptime/rpc/limit/LimitMetricRegistry.java +++ b/ingester-grpc/src/main/java/io/greptime/rpc/limit/LimitMetricRegistry.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc.limit; import com.netflix.concurrency.limits.MetricRegistry; @@ -21,8 +22,6 @@ /** * For tracking metrics in the limiters. - * - * @author jiachun.fjc */ public class LimitMetricRegistry implements MetricRegistry { diff --git a/ingester-grpc/src/main/java/io/greptime/rpc/limit/RequestLimitCtx.java b/ingester-grpc/src/main/java/io/greptime/rpc/limit/RequestLimitCtx.java index 3859a14..393170c 100644 --- a/ingester-grpc/src/main/java/io/greptime/rpc/limit/RequestLimitCtx.java +++ b/ingester-grpc/src/main/java/io/greptime/rpc/limit/RequestLimitCtx.java @@ -13,11 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc.limit; /** - * - * @author jiachun.fjc */ public interface RequestLimitCtx { diff --git a/ingester-grpc/src/main/java/io/greptime/rpc/limit/RequestLimiterBuilder.java b/ingester-grpc/src/main/java/io/greptime/rpc/limit/RequestLimiterBuilder.java index 2feccfd..572adb2 100644 --- a/ingester-grpc/src/main/java/io/greptime/rpc/limit/RequestLimiterBuilder.java +++ b/ingester-grpc/src/main/java/io/greptime/rpc/limit/RequestLimiterBuilder.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc.limit; import com.netflix.concurrency.limits.Limiter; @@ -22,8 +23,6 @@ /** * Refer to `concurrency-limit-grpc` - * - * @author jiachun.fjc */ public class RequestLimiterBuilder extends AbstractPartitionedLimiter.Builder { @@ -53,7 +52,8 @@ public RequestLimiterBuilder blockOnLimit(boolean blockOnLimit, long blockTimeou } public Limiter build() { - return this.blockOnLimit ? BlockingLimiter.wrap(super.build(), Duration.ofMillis(this.blockTimeoutMillis)) + return this.blockOnLimit + ? BlockingLimiter.wrap(super.build(), Duration.ofMillis(this.blockTimeoutMillis)) : super.build(); } diff --git a/ingester-grpc/src/main/java/io/greptime/rpc/limit/VegasLimit.java b/ingester-grpc/src/main/java/io/greptime/rpc/limit/VegasLimit.java index 93aa324..a1c5999 100644 --- a/ingester-grpc/src/main/java/io/greptime/rpc/limit/VegasLimit.java +++ b/ingester-grpc/src/main/java/io/greptime/rpc/limit/VegasLimit.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc.limit; import com.netflix.concurrency.limits.MetricIds; @@ -22,21 +23,20 @@ import com.netflix.concurrency.limits.limit.AbstractLimit; import com.netflix.concurrency.limits.limit.functions.Log10RootFunction; import io.greptime.common.util.Ensures; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import java.util.function.Function; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Limiter based on TCP Vegas where the limit increases by alpha if the queue_use is small ({@literal <} alpha) * and decreases by alpha if the queue_use is large ({@literal >} beta). *

- * Queue size is calculated using the formula, + * Queue size is calculated using the formula, * queue_use = limit − BWE×RTTnoLoad = limit × (1 − RTTnoLoad/RTTactual) *

- * For traditional TCP Vegas alpha is typically 2-3 and beta is typically 4-6. To allow for better growth and + * For traditional TCP Vegas alpha is typically 2-3 and beta is typically 4-6. To allow for better growth and * stability at higher limits we set alpha=Max(3, 10% of the current limit) and beta=Max(6, 20% of the current limit) *

* Refer to {@link com.netflix.concurrency.limits.limit.VegasLimit} @@ -45,7 +45,7 @@ public class VegasLimit extends AbstractLimit { private static final Logger LOG = LoggerFactory.getLogger(VegasLimit.class); - + private static final Function LOG10 = Log10RootFunction.create(0); public static class Builder { @@ -53,7 +53,7 @@ public static class Builder { private int maxConcurrency = 1000; private MetricRegistry registry = EmptyMetricRegistry.INSTANCE; private double smoothing = 1.0; - + private Function alphaFunc = (limit) -> 3 * LOG10.apply(limit); private Function betaFunc = (limit) -> 6 * LOG10.apply(limit); private Function thresholdFunc = LOG10; @@ -61,10 +61,9 @@ public static class Builder { private Function decreaseFunc = (limit) -> limit - LOG10.apply(limit.intValue()); private int probeMultiplier = 30; private boolean logOnLimitChange = true; - - private Builder() { - } - + + private Builder() {} + /** * The limiter will probe for a new noload RTT every probeMultiplier * current limit * iterations. Default value is 30. @@ -76,47 +75,47 @@ public Builder probeMultiplier(int probeMultiplier) { this.probeMultiplier = probeMultiplier; return this; } - + public Builder alpha(int alpha) { this.alphaFunc = (ignore) -> alpha; return this; } - + public Builder threshold(Function threshold) { this.thresholdFunc = threshold; return this; } - + public Builder alpha(Function alpha) { this.alphaFunc = alpha; return this; } - + public Builder beta(int beta) { this.betaFunc = (ignore) -> beta; return this; } - + public Builder beta(Function beta) { this.betaFunc = beta; return this; } - + public Builder increase(Function increase) { this.increaseFunc = increase; return this; } - + public Builder decrease(Function decrease) { this.decreaseFunc = decrease; return this; } - + public Builder smoothing(double smoothing) { this.smoothing = smoothing; return this; } - + public Builder initialLimit(int initialLimit) { this.initialLimit = initialLimit; return this; @@ -136,32 +135,32 @@ public Builder metricRegistry(MetricRegistry registry) { this.registry = registry; return this; } - + public VegasLimit build() { return new VegasLimit(this); } } - + public static Builder newBuilder() { return new Builder(); } - + public static VegasLimit newDefault() { return newBuilder().build(); } - + /** * Estimated concurrency limit based on our algorithm */ private volatile double estimatedLimit; - + private volatile long rtt_noload = 0; - + /** * Maximum allowed limit providing an upper bound failsafe */ - private final int maxLimit; - + private final int maxLimit; + private final double smoothing; private final Function alphaFunc; private final Function betaFunc; @@ -212,13 +211,13 @@ protected int _update(long startTime, long rtt, int inflight, boolean didDrop) { this.rtt_noload = rtt; return (int) this.estimatedLimit; } - + if (this.rtt_noload == 0 || rtt < this.rtt_noload) { LOG.debug("New MinRTT {}.", TimeUnit.NANOSECONDS.toMicros(rtt) / 1000.0); this.rtt_noload = rtt; return (int) this.estimatedLimit; } - + this.rttSampleListener.addSample(getRttMillis(this.rtt_noload)); return updateEstimatedLimit(rtt, inflight, didDrop); @@ -233,7 +232,7 @@ private int updateEstimatedLimit(long rtt, int inflight, boolean didDrop) { // Treat any drop (i.e timeout) as needing to reduce the limit if (didDrop) { newLimit = this.decreaseFunc.apply(currLimit); - // Prevent upward drift if not close to the limit + // Prevent upward drift if not close to the limit } else if (inflight * 2 < currLimit) { return (int) currLimit; } else { @@ -244,13 +243,13 @@ private int updateEstimatedLimit(long rtt, int inflight, boolean didDrop) { // Aggressive increase when no queuing if (queueSize <= threshold) { newLimit = currLimit + beta; - // Increase the limit if queue is still manageable + // Increase the limit if queue is still manageable } else if (queueSize < alpha) { newLimit = this.increaseFunc.apply(currLimit); - // Detecting latency so decrease + // Detecting latency so decrease } else if (queueSize > beta) { newLimit = this.decreaseFunc.apply(currLimit); - // We're within he sweet spot so nothing to do + // We're within he sweet spot so nothing to do } else { return (int) currLimit; } @@ -260,7 +259,8 @@ private int updateEstimatedLimit(long rtt, int inflight, boolean didDrop) { newLimit = (1 - this.smoothing) * currLimit + this.smoothing * newLimit; if (this.logOnLimitChange && (int) newLimit != (int) currLimit) { - LOG.info("New limit={}, previous limit={}, minRtt={} ms, winRtt={} ms, queueSize={}.", + LOG.info( + "New limit={}, previous limit={}, minRtt={} ms, winRtt={} ms, queueSize={}.", (int) newLimit, (int) currLimit, TimeUnit.NANOSECONDS.toMicros(this.rtt_noload) / 1000.0, @@ -279,8 +279,7 @@ private long getRttMillis(long nanos) { @Override public String toString() { - return "VegasLimit [limit=" + getLimit() + // - ", rtt_noload=" + TimeUnit.NANOSECONDS.toMicros(this.rtt_noload) / 1000.0 + // - " ms]"; + return "VegasLimit [limit=" + getLimit() + ", rtt_noload=" + + TimeUnit.NANOSECONDS.toMicros(this.rtt_noload) / 1000.0 + " ms]"; } } diff --git a/ingester-grpc/src/main/java/io/greptime/rpc/signal/RpcLimitSignalHandler.java b/ingester-grpc/src/main/java/io/greptime/rpc/signal/RpcLimitSignalHandler.java index f7e39f7..0b4aec6 100644 --- a/ingester-grpc/src/main/java/io/greptime/rpc/signal/RpcLimitSignalHandler.java +++ b/ingester-grpc/src/main/java/io/greptime/rpc/signal/RpcLimitSignalHandler.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc.signal; import io.greptime.common.SPI; @@ -25,8 +26,6 @@ /** * A signal handler that can reset LIMIT_SWITCH by {@link ClientRequestLimitInterceptor#resetLimitSwitch()}. - * - * @author jiachun.fjc */ @SPI(priority = 89) public class RpcLimitSignalHandler implements SignalHandler { diff --git a/ingester-grpc/src/test/java/io/greptime/rpc/LimitTest.java b/ingester-grpc/src/test/java/io/greptime/rpc/LimitTest.java index a39b46c..6ac53c1 100644 --- a/ingester-grpc/src/test/java/io/greptime/rpc/LimitTest.java +++ b/ingester-grpc/src/test/java/io/greptime/rpc/LimitTest.java @@ -13,39 +13,40 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc; import com.netflix.concurrency.limits.Limit; import io.greptime.rpc.limit.Gradient2Limit; import io.greptime.rpc.limit.VegasLimit; +import java.util.concurrent.TimeUnit; import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.concurrent.TimeUnit; /** - * @author jiachun.fjc + * */ public class LimitTest { private static final Logger LOG = LoggerFactory.getLogger(LimitTest.class); static Gradient2Limit createGradient2() { - return Gradient2Limit.newBuilder() // - .initialLimit(512) // - .maxConcurrency(1024) // - .smoothing(0.2) // - .longWindow(100) // - .queueSize(16) // + return Gradient2Limit.newBuilder() + .initialLimit(512) + .maxConcurrency(1024) + .smoothing(0.2) + .longWindow(100) + .queueSize(16) .build(); } static VegasLimit createVegas() { - return VegasLimit.newBuilder() // - .initialLimit(512) // - .maxConcurrency(1024) // - .smoothing(0.2) // + return VegasLimit.newBuilder() + .initialLimit(512) + .maxConcurrency(1024) + .smoothing(0.2) .build(); } diff --git a/ingester-grpc/src/test/java/io/greptime/rpc/RequestLimiterInterceptorTest.java b/ingester-grpc/src/test/java/io/greptime/rpc/RequestLimiterInterceptorTest.java index 5c509f1..bb8f830 100644 --- a/ingester-grpc/src/test/java/io/greptime/rpc/RequestLimiterInterceptorTest.java +++ b/ingester-grpc/src/test/java/io/greptime/rpc/RequestLimiterInterceptorTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc; import com.netflix.concurrency.limits.Limiter; @@ -30,29 +31,27 @@ import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder; import io.grpc.stub.ClientCalls; import io.grpc.stub.ServerCalls; -import org.junit.Ignore; -import org.junit.Test; import java.io.IOException; import java.util.concurrent.Executors; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; +import org.junit.Ignore; +import org.junit.Test; /** * Refer to `concurrency-limit-grpc's test` - * - * @author jiachun.fjc */ public class RequestLimiterInterceptorTest { private static final MethodDescriptor METHOD_DESCRIPTOR; static { - METHOD_DESCRIPTOR = MethodDescriptor.newBuilder() // - .setType(MethodDescriptor.MethodType.UNARY) // - .setFullMethodName("service/method") // - .setRequestMarshaller(StringMarshaller.INSTANCE) // - .setResponseMarshaller(StringMarshaller.INSTANCE) // + METHOD_DESCRIPTOR = MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("service/method") + .setRequestMarshaller(StringMarshaller.INSTANCE) + .setResponseMarshaller(StringMarshaller.INSTANCE) .build(); } @@ -80,19 +79,22 @@ public void simulation() throws IOException { Limiter limiter = RequestLimiterBuilder.newBuilder() .named("limit_simulation") - .metricRegistry(new LimitMetricRegistry()) // - .blockOnLimit(true, 1000) // + .metricRegistry(new LimitMetricRegistry()) + .blockOnLimit(true, 1000) .build(); Channel channel = NettyChannelBuilder.forTarget("localhost:" + server.getPort()) - .usePlaintext() // - .intercept(new ClientRequestLimitInterceptor(limiter)) // + .usePlaintext() + .intercept(new ClientRequestLimitInterceptor(limiter)) .build(); AtomicLong counter = new AtomicLong(); - Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate( - () -> System.out.println(" " + counter.getAndSet(0) + " : " + limiter.toString()), 1, 1, TimeUnit.SECONDS - ); + Executors.newSingleThreadScheduledExecutor() + .scheduleAtFixedRate( + () -> System.out.println(" " + counter.getAndSet(0) + " : " + limiter.toString()), + 1, + 1, + TimeUnit.SECONDS); for (int i = 0; i < 10000000; i++) { counter.incrementAndGet(); diff --git a/ingester-grpc/src/test/java/io/greptime/rpc/StringMarshaller.java b/ingester-grpc/src/test/java/io/greptime/rpc/StringMarshaller.java index a9dd28b..58106ee 100644 --- a/ingester-grpc/src/test/java/io/greptime/rpc/StringMarshaller.java +++ b/ingester-grpc/src/test/java/io/greptime/rpc/StringMarshaller.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc; import io.greptime.common.util.StringBuilderHelper; @@ -36,7 +37,8 @@ public InputStream stream(String value) { @Override public String parse(InputStream stream) { try { - return toStringBuilder((new InputStreamReader(stream, StandardCharsets.UTF_8))).toString(); + return toStringBuilder((new InputStreamReader(stream, StandardCharsets.UTF_8))) + .toString(); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/ingester-grpc/src/test/resources/log4j2.xml b/ingester-grpc/src/test/resources/log4j2.xml index a015f76..0f2cba9 100644 --- a/ingester-grpc/src/test/resources/log4j2.xml +++ b/ingester-grpc/src/test/resources/log4j2.xml @@ -1,4 +1,21 @@ + diff --git a/ingester-protocol/pom.xml b/ingester-protocol/pom.xml index aa98f37..3872dd1 100644 --- a/ingester-protocol/pom.xml +++ b/ingester-protocol/pom.xml @@ -1,20 +1,31 @@ + 4.0.0 - greptimedb-ingester io.greptime + greptimedb-ingester 0.7.3 ingester-protocol - - 8 - 8 - UTF-8 - - ${project.groupId} diff --git a/ingester-protocol/src/main/java/io/greptime/CachedPojoObjectMapper.java b/ingester-protocol/src/main/java/io/greptime/CachedPojoObjectMapper.java index ae88966..7037163 100644 --- a/ingester-protocol/src/main/java/io/greptime/CachedPojoObjectMapper.java +++ b/ingester-protocol/src/main/java/io/greptime/CachedPojoObjectMapper.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import com.google.common.cache.CacheBuilder; @@ -35,8 +36,6 @@ /** * This utility class converts POJO objects into {@link Table} objects, * inspired by InfluxDB client-java. - * - * @author jiachun.fjc */ @SPI(priority = 9) public class CachedPojoObjectMapper implements PojoObjectMapper { @@ -48,15 +47,15 @@ public CachedPojoObjectMapper() { } public CachedPojoObjectMapper(int maxCachedPOJOs) { - this.classFieldCache = - CacheBuilder.newBuilder().maximumSize(maxCachedPOJOs) - .build(new CacheLoader, Map>() { - @SuppressWarnings("NullableProblems") - @Override - public Map load(Class key) { - return createMetricClass(key); - } - }); + this.classFieldCache = CacheBuilder.newBuilder() + .maximumSize(maxCachedPOJOs) + .build(new CacheLoader, Map>() { + @SuppressWarnings("NullableProblems") + @Override + public Map load(Class key) { + return createMetricClass(key); + } + }); } @Override @@ -115,9 +114,8 @@ private String getMetricName(Class metricType) { if (metricAnnotation != null) { return metricAnnotation.name(); } else { - String err = - String.format("Unable to determine Metric for '%s'." + " Does it have a @Metric annotation?", - metricType); + String err = String.format( + "Unable to determine Metric for '%s'. Does it have a @Metric annotation?", metricType); throw new PojoException(err); } } diff --git a/ingester-protocol/src/main/java/io/greptime/GreptimeDB.java b/ingester-protocol/src/main/java/io/greptime/GreptimeDB.java index 84044b7..5f7a527 100644 --- a/ingester-protocol/src/main/java/io/greptime/GreptimeDB.java +++ b/ingester-protocol/src/main/java/io/greptime/GreptimeDB.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import com.codahale.metrics.Counter; @@ -36,8 +37,6 @@ import io.greptime.rpc.RpcClient; import io.greptime.rpc.RpcFactoryProvider; import io.greptime.rpc.RpcOptions; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -48,11 +47,11 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * The GreptimeDB client. - * - * @author jiachun.fjc */ public class GreptimeDB implements Write, WriteObject, Lifecycle, Display { @@ -140,8 +139,8 @@ public void ensureInitialized() { } @Override - public CompletableFuture> writeObjects(Collection> objects, WriteOp writeOp, - Context ctx) { + public CompletableFuture> writeObjects( + Collection> objects, WriteOp writeOp, Context ctx) { List

rows = new ArrayList<>(objects.size()); for (List pojo : objects) { rows.add(POJO_OBJECT_MAPPER.mapToTable(pojo)); @@ -180,16 +179,16 @@ public StreamWriter streamWriter(int maxPointsPerSecond, Context @Override public void display(Printer out) { - out.println("--- GreptimeDB Client ---") // - .print("id=") // - .println(this.id) // - .print("version=") // - .println(VERSION) // - .print("endpoints=") // - .println(this.opts.getEndpoints()) // - .print("database=") // - .println(this.opts.getDatabase()) // - .print("rpcOptions=") // + out.println("--- GreptimeDB Client ---") + .print("id=") + .println(this.id) + .print("version=") + .println(VERSION) + .print("endpoints=") + .println(this.opts.getEndpoints()) + .print("database=") + .println(this.opts.getDatabase()) + .print("rpcOptions=") .println(this.opts.getRpcOptions()); if (this.routerClient != null) { @@ -207,19 +206,18 @@ public void display(Printer out) { @Override public String toString() { - return "GreptimeDB{" + // - "id=" + id + // - "version=" + VERSION + // - ", opts=" + opts + // - ", routerClient=" + routerClient + // - ", writeClient=" + writeClient + // - '}'; + return "GreptimeDB{" + "id=" + + id + "version=" + + VERSION + ", opts=" + + opts + ", routerClient=" + + routerClient + ", writeClient=" + + writeClient + '}'; } private Context attachCtx(Context ctx) { Context newCtx = ctx == null ? Context.newDefault() : ctx; - return newCtx.with(Keys.VERSION_KEY, VERSION) // - .with(Keys.NODE_KEY, NODE_ID) // + return newCtx.with(Keys.VERSION_KEY, VERSION) + .with(Keys.NODE_KEY, NODE_ID) .with(Keys.ID_KEY, this.id); } diff --git a/ingester-protocol/src/main/java/io/greptime/PojoObjectMapper.java b/ingester-protocol/src/main/java/io/greptime/PojoObjectMapper.java index 56b01e4..01e34cd 100644 --- a/ingester-protocol/src/main/java/io/greptime/PojoObjectMapper.java +++ b/ingester-protocol/src/main/java/io/greptime/PojoObjectMapper.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import io.greptime.models.Table; @@ -20,8 +21,6 @@ /** * Converts POJO objects into {@link Table} objects - * - * @author jiachun.fjc */ public interface PojoObjectMapper { diff --git a/ingester-protocol/src/main/java/io/greptime/Router.java b/ingester-protocol/src/main/java/io/greptime/Router.java index 8d13315..88b32af 100644 --- a/ingester-protocol/src/main/java/io/greptime/Router.java +++ b/ingester-protocol/src/main/java/io/greptime/Router.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import java.util.List; @@ -20,8 +21,6 @@ /** * RPC router for GreptimeDB. - * - * @author jiachun.fjc */ public interface Router { diff --git a/ingester-protocol/src/main/java/io/greptime/RouterClient.java b/ingester-protocol/src/main/java/io/greptime/RouterClient.java index ed00da0..ed7756f 100644 --- a/ingester-protocol/src/main/java/io/greptime/RouterClient.java +++ b/ingester-protocol/src/main/java/io/greptime/RouterClient.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import io.greptime.common.Display; @@ -24,20 +25,18 @@ import io.greptime.rpc.Context; import io.greptime.rpc.Observer; import io.greptime.rpc.RpcClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A route rpc client which cached the routing table information locally * and will auto refresh. - * - * @author jiachun.fjc */ public class RouterClient implements Lifecycle, Display { @@ -71,7 +70,9 @@ public boolean init(RouterOptions opts) { LOG.debug("Router cache refresh {}.", r ? "success" : "failed"); } }), - Util.randomInitialDelay(180), refreshPeriod, TimeUnit.SECONDS); + Util.randomInitialDelay(180), + refreshPeriod, + TimeUnit.SECONDS); LOG.info("Router cache refresher started."); } @@ -120,18 +121,23 @@ public CompletableFuture invoke(Endpoint endpoint, Req request CompletableFuture future = new CompletableFuture<>(); try { - this.rpcClient.invokeAsync(endpoint, request, ctx, new Observer() { - - @Override - public void onNext(Resp value) { - future.complete(value); - } + this.rpcClient.invokeAsync( + endpoint, + request, + ctx, + new Observer() { + + @Override + public void onNext(Resp value) { + future.complete(value); + } - @Override - public void onError(Throwable err) { - future.completeExceptionally(err); - } - }, timeoutMs); + @Override + public void onError(Throwable err) { + future.completeExceptionally(err); + } + }, + timeoutMs); } catch (Exception e) { future.completeExceptionally(e); @@ -151,7 +157,8 @@ public void onError(Throwable err) { * @param the response type */ @SuppressWarnings("unused") - public void invokeServerStreaming(Endpoint endpoint, Req request, Context ctx, Observer observer) { + public void invokeServerStreaming( + Endpoint endpoint, Req request, Context ctx, Observer observer) { try { this.rpcClient.invokeServerStreaming(endpoint, request, ctx, observer); } catch (Exception e) { @@ -170,8 +177,8 @@ public void invokeServerStreaming(Endpoint endpoint, Req request, Co * @param the request type * @param the response type */ - public Observer invokeClientStreaming(Endpoint endpoint, Req defaultReqIns, Context ctx, - Observer respObserver) { + public Observer invokeClientStreaming( + Endpoint endpoint, Req defaultReqIns, Context ctx, Observer respObserver) { try { return this.rpcClient.invokeClientStreaming(endpoint, defaultReqIns, ctx, respObserver); } catch (Exception e) { @@ -182,9 +189,7 @@ public Observer invokeClientStreaming(Endpoint endpoint, Req de @Override public void display(Printer out) { - out.println("--- RouterClient ---") // - .print("opts=") // - .println(this.opts); + out.println("--- RouterClient ---").print("opts=").println(this.opts); if (this.rpcClient != null) { out.println(""); @@ -196,11 +201,7 @@ public void display(Printer out) { @Override public String toString() { - return "RouterClient{" + // - "refresher=" + refresher + // - ", opts=" + opts + // - ", rpcClient=" + rpcClient + // - '}'; + return "RouterClient{" + "refresher=" + refresher + ", opts=" + opts + ", rpcClient=" + rpcClient + '}'; } /** diff --git a/ingester-protocol/src/main/java/io/greptime/RpcServiceRegister.java b/ingester-protocol/src/main/java/io/greptime/RpcServiceRegister.java index d6995ea..6426578 100644 --- a/ingester-protocol/src/main/java/io/greptime/RpcServiceRegister.java +++ b/ingester-protocol/src/main/java/io/greptime/RpcServiceRegister.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import io.greptime.rpc.MethodDescriptor; @@ -21,8 +22,6 @@ /** * The RPC service register. - * - * @author jiachun.fjc */ public class RpcServiceRegister { @@ -30,17 +29,21 @@ public class RpcServiceRegister { public static void registerAllService() { // register protobuf serializer - RpcFactoryProvider.getRpcFactory().register( - MethodDescriptor.of(String.format(METHOD_TEMPLATE, "Handle"), MethodDescriptor.MethodType.UNARY, 1), // - Database.GreptimeRequest.class, // - Database.GreptimeRequest.getDefaultInstance(), // - Database.GreptimeResponse.getDefaultInstance()); + RpcFactoryProvider.getRpcFactory() + .register( + MethodDescriptor.of( + String.format(METHOD_TEMPLATE, "Handle"), MethodDescriptor.MethodType.UNARY, 1), + Database.GreptimeRequest.class, + Database.GreptimeRequest.getDefaultInstance(), + Database.GreptimeResponse.getDefaultInstance()); - RpcFactoryProvider.getRpcFactory().register( - MethodDescriptor.of(String.format(METHOD_TEMPLATE, "HandleRequests"), - MethodDescriptor.MethodType.CLIENT_STREAMING), // - Database.GreptimeRequest.class, // - Database.GreptimeRequest.getDefaultInstance(), // - Database.GreptimeResponse.getDefaultInstance()); + RpcFactoryProvider.getRpcFactory() + .register( + MethodDescriptor.of( + String.format(METHOD_TEMPLATE, "HandleRequests"), + MethodDescriptor.MethodType.CLIENT_STREAMING), + Database.GreptimeRequest.class, + Database.GreptimeRequest.getDefaultInstance(), + Database.GreptimeResponse.getDefaultInstance()); } } diff --git a/ingester-protocol/src/main/java/io/greptime/Status.java b/ingester-protocol/src/main/java/io/greptime/Status.java index 702a0a9..657af8a 100644 --- a/ingester-protocol/src/main/java/io/greptime/Status.java +++ b/ingester-protocol/src/main/java/io/greptime/Status.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import java.util.HashMap; @@ -20,8 +21,6 @@ /** * Common status code for public API. - * - * @author jiachun.fjc */ public enum Status { // ====== Begin of common status code ============== @@ -57,14 +56,12 @@ public enum Status { // ====== Begin of catalog related status code ===== // Table already exists. TableAlreadyExists(4000), - // TableNotFound(4001), - // - TableColumnNotFound(4002), // - TableColumnExists(4003), // - DatabaseNotFound(4004), // - RegionNotFound(4005), // - RegionAlreadyExists(4006), // + TableColumnNotFound(4002), + TableColumnExists(4003), + DatabaseNotFound(4004), + RegionNotFound(4005), + RegionAlreadyExists(4006), RegionReadonly(4007), // ====== End of catalog related status code ======= @@ -95,8 +92,8 @@ public enum Status { AccessDenied(7005), // User is not authorized to perform the operation PermissionDenied(7006), - // ====== End of auth related status code ===== - ; +// ====== End of auth related status code ===== +; private static final Map DICT = new HashMap<>(); diff --git a/ingester-protocol/src/main/java/io/greptime/StreamWriter.java b/ingester-protocol/src/main/java/io/greptime/StreamWriter.java index aceec98..d8bc988 100644 --- a/ingester-protocol/src/main/java/io/greptime/StreamWriter.java +++ b/ingester-protocol/src/main/java/io/greptime/StreamWriter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import java.util.concurrent.CompletableFuture; @@ -22,8 +23,6 @@ * typically used in data import scenarios. After completion, * the stream needs to be closed(Call `StreamWriter#completed()`), * and the write result can be obtained from the database server. - * - * @author jiachun.fjc */ public interface StreamWriter { diff --git a/ingester-protocol/src/main/java/io/greptime/Util.java b/ingester-protocol/src/main/java/io/greptime/Util.java index e32d404..ce5a53d 100644 --- a/ingester-protocol/src/main/java/io/greptime/Util.java +++ b/ingester-protocol/src/main/java/io/greptime/Util.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import io.greptime.common.Display; @@ -25,7 +26,6 @@ import io.greptime.common.util.ThreadPoolUtil; import io.greptime.models.Err; import io.greptime.rpc.Observer; - import java.io.IOException; import java.util.Properties; import java.util.concurrent.CompletableFuture; @@ -37,26 +37,25 @@ /** * Util for GreptimeDB Ingester. - * - * @author jiachun */ public final class Util { - private static final AtomicBoolean RW_LOGGING; - private static final int REPORT_PERIOD_MIN; + private static final AtomicBoolean RW_LOGGING; + private static final int REPORT_PERIOD_MIN; private static final ScheduledExecutorService DISPLAY; static { RW_LOGGING = new AtomicBoolean(SystemPropertyUtil.getBool(Keys.RW_LOGGING, false)); REPORT_PERIOD_MIN = SystemPropertyUtil.getInt(Keys.REPORT_PERIOD, 30); DISPLAY = ThreadPoolUtil.newScheduledBuilder() - .poolName("display_self") // - .coreThreads(1) // - .enableMetric(true) // - .threadFactory(new NamedThreadFactory("display_self", true)) // - .rejectedHandler(new ThreadPoolExecutor.DiscardOldestPolicy()) // + .poolName("display_self") + .coreThreads(1) + .enableMetric(true) + .threadFactory(new NamedThreadFactory("display_self", true)) + .rejectedHandler(new ThreadPoolExecutor.DiscardOldestPolicy()) .build(); - Runtime.getRuntime().addShutdownHook(new Thread(() -> ExecutorServiceHelper.shutdownAndAwaitTermination(DISPLAY))); + Runtime.getRuntime() + .addShutdownHook(new Thread(() -> ExecutorServiceHelper.shutdownAndAwaitTermination(DISPLAY))); } /** @@ -110,12 +109,12 @@ public static SharedScheduledPool getSharedScheduledPool(String name, int worker @Override public ScheduledExecutorService create() { - return ThreadPoolUtil.newScheduledBuilder() // - .poolName(name) // - .coreThreads(workers) // - .enableMetric(true) // - .threadFactory(new NamedThreadFactory(name, true)) // - .rejectedHandler(new ThreadPoolExecutor.DiscardOldestPolicy()) // + return ThreadPoolUtil.newScheduledBuilder() + .poolName(name) + .coreThreads(workers) + .enableMetric(true) + .threadFactory(new NamedThreadFactory(name, true)) + .rejectedHandler(new ThreadPoolExecutor.DiscardOldestPolicy()) .build(); } @@ -139,7 +138,6 @@ public static CompletableFuture completedCf(U value) { return CompletableFuture.completedFuture(value); } - public static Observer toObserver(CompletableFuture future) { return new Observer() { @@ -178,7 +176,7 @@ public static boolean shouldRetry(Err err) { */ public static String clientVersion() { try { - return loadProps(Util.class.getClassLoader(), "client_version.properties") // + return loadProps(Util.class.getClassLoader(), "client_version.properties") .getProperty(Keys.VERSION_KEY, "Unknown version"); } catch (Exception ignored) { return "Unknown version(err)"; diff --git a/ingester-protocol/src/main/java/io/greptime/Write.java b/ingester-protocol/src/main/java/io/greptime/Write.java index 4fea986..2ba794e 100644 --- a/ingester-protocol/src/main/java/io/greptime/Write.java +++ b/ingester-protocol/src/main/java/io/greptime/Write.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import io.greptime.models.Err; @@ -20,15 +21,12 @@ import io.greptime.models.Table; import io.greptime.models.WriteOk; import io.greptime.rpc.Context; - import java.util.Arrays; import java.util.Collection; import java.util.concurrent.CompletableFuture; /** * Write API: writes data to the database. - * - * @author jiachun.fjc */ public interface Write { /** diff --git a/ingester-protocol/src/main/java/io/greptime/WriteClient.java b/ingester-protocol/src/main/java/io/greptime/WriteClient.java index 4cfc509..eb23659 100644 --- a/ingester-protocol/src/main/java/io/greptime/WriteClient.java +++ b/ingester-protocol/src/main/java/io/greptime/WriteClient.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import com.codahale.metrics.Histogram; @@ -45,17 +46,15 @@ import io.greptime.rpc.Observer; import io.greptime.v1.Common; import io.greptime.v1.Database; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.Collection; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Default Write API impl. - * - * @author jiachun.fjc */ public class WriteClient implements Write, Lifecycle, Display { @@ -90,35 +89,42 @@ public CompletableFuture> write(Collection
tables, W long startCall = Clock.defaultClock().getTick(); WriteTables writeTables = new WriteTables(tables, writeOp); - return this.writeLimiter.acquireAndDo(tables, () -> write0(writeTables, ctx, 0).whenCompleteAsync((r, e) -> { - InnerMetricHelper.writeQps().mark(); - if (r != null) { - if (Util.isRwLogging()) { - LOG.info("Write to {} with operation {}, duration={} ms, result={}.", - Keys.DB_NAME, - writeOp, - Clock.defaultClock().duration(startCall), - r - ); - } - if (r.isOk()) { - WriteOk ok = r.getOk(); - InnerMetricHelper.writeRowsSuccessNum(writeOp).update(ok.getSuccess()); - InnerMetricHelper.writeRowsFailureNum(writeOp).update(ok.getFailure()); - return; - } - } - InnerMetricHelper.writeFailureNum().mark(); - }, this.asyncPool)); + return this.writeLimiter.acquireAndDo(tables, () -> write0(writeTables, ctx, 0) + .whenCompleteAsync( + (r, e) -> { + InnerMetricHelper.writeQps().mark(); + if (r != null) { + if (Util.isRwLogging()) { + LOG.info( + "Write to {} with operation {}, duration={} ms, result={}.", + Keys.DB_NAME, + writeOp, + Clock.defaultClock().duration(startCall), + r); + } + if (r.isOk()) { + WriteOk ok = r.getOk(); + InnerMetricHelper.writeRowsSuccessNum(writeOp) + .update(ok.getSuccess()); + InnerMetricHelper.writeRowsFailureNum(writeOp) + .update(ok.getFailure()); + return; + } + } + InnerMetricHelper.writeFailureNum().mark(); + }, + this.asyncPool)); } @Override public StreamWriter streamWriter(int maxPointsPerSecond, Context ctx) { - int permitsPerSecond = maxPointsPerSecond > 0 ? maxPointsPerSecond : this.opts.getDefaultStreamMaxWritePointsPerSecond(); + int permitsPerSecond = + maxPointsPerSecond > 0 ? maxPointsPerSecond : this.opts.getDefaultStreamMaxWritePointsPerSecond(); CompletableFuture respFuture = new CompletableFuture<>(); - return this.routerClient.route() + return this.routerClient + .route() .thenApply(endpoint -> streamWriteTo(endpoint, ctx, Util.toObserver(respFuture))) .thenApply(reqObserver -> new RateLimitingStreamWriter(reqObserver, permitsPerSecond) { @@ -135,36 +141,41 @@ public CompletableFuture completed() { reqObserver.onCompleted(); return respFuture; } - }).join(); + }) + .join(); } private CompletableFuture> write0(WriteTables writeTables, Context ctx, int retries) { InnerMetricHelper.writeByRetries(retries).mark(); - return this.routerClient.route() - .thenComposeAsync(endpoint -> writeTo(endpoint, writeTables, ctx, retries), this.asyncPool) - .thenComposeAsync(r -> { - if (r.isOk()) { - LOG.debug("Success to write to {}, ok={}.", Keys.DB_NAME, r.getOk()); - return Util.completedCf(r); - } - - Err err = r.getErr(); - LOG.warn("Failed to write to {}, retries={}, err={}.", Keys.DB_NAME, retries, err); - if (retries + 1 > this.opts.getMaxRetries()) { - LOG.error("Retried {} times still failed.", retries); - return Util.completedCf(r); - } - - if (Util.shouldNotRetry(err)) { - return Util.completedCf(r); - } - - return write0(writeTables, ctx, retries + 1); - }, this.asyncPool); + return this.routerClient + .route() + .thenComposeAsync(endpoint -> writeTo(endpoint, writeTables, ctx, retries), this.asyncPool) + .thenComposeAsync( + r -> { + if (r.isOk()) { + LOG.debug("Success to write to {}, ok={}.", Keys.DB_NAME, r.getOk()); + return Util.completedCf(r); + } + + Err err = r.getErr(); + LOG.warn("Failed to write to {}, retries={}, err={}.", Keys.DB_NAME, retries, err); + if (retries + 1 > this.opts.getMaxRetries()) { + LOG.error("Retried {} times still failed.", retries); + return Util.completedCf(r); + } + + if (Util.shouldNotRetry(err)) { + return Util.completedCf(r); + } + + return write0(writeTables, ctx, retries + 1); + }, + this.asyncPool); } - private CompletableFuture> writeTo(Endpoint endpoint, WriteTables writeTables, Context ctx, int retries) { + private CompletableFuture> writeTo( + Endpoint endpoint, WriteTables writeTables, Context ctx, int retries) { // Some info will be set into the GreptimeDB Request header. String database = this.opts.getDatabase(); AuthInfo authInfo = this.opts.getAuthInfo(); @@ -174,45 +185,50 @@ private CompletableFuture> writeTo(Endpoint endpoint, Write CompletableFuture future = this.routerClient.invoke(endpoint, req, ctx); - return future.thenApplyAsync(resp -> { - Common.ResponseHeader header = resp.getHeader(); - Common.Status status = header.getStatus(); - int statusCode = status.getStatusCode(); - if (Status.isSuccess(statusCode)) { - int affectedRows = resp.getAffectedRows().getValue(); - return WriteOk.ok(affectedRows, 0).mapToResult(); - } else { - return Err.writeErr(statusCode, new ServerException(status.getErrMsg()), endpoint).mapToResult(); - } - }, this.asyncPool); + return future.thenApplyAsync( + resp -> { + Common.ResponseHeader header = resp.getHeader(); + Common.Status status = header.getStatus(); + int statusCode = status.getStatusCode(); + if (Status.isSuccess(statusCode)) { + int affectedRows = resp.getAffectedRows().getValue(); + return WriteOk.ok(affectedRows, 0).mapToResult(); + } else { + return Err.writeErr(statusCode, new ServerException(status.getErrMsg()), endpoint) + .mapToResult(); + } + }, + this.asyncPool); } private Observer streamWriteTo(Endpoint endpoint, Context ctx, Observer respObserver) { - Observer rpcObserver = - this.routerClient.invokeClientStreaming(endpoint, Database.GreptimeRequest.getDefaultInstance(), ctx, - new Observer() { - - @Override - public void onNext(Database.GreptimeResponse resp) { - int affectedRows = resp.getAffectedRows().getValue(); - Result ret = WriteOk.ok(affectedRows, 0).mapToResult(); - if (ret.isOk()) { - respObserver.onNext(ret.getOk()); - } else { - respObserver.onError(new StreamException(String.valueOf(ret.getErr()))); - } - } + Observer rpcObserver = this.routerClient.invokeClientStreaming( + endpoint, + Database.GreptimeRequest.getDefaultInstance(), + ctx, + new Observer() { - @Override - public void onError(Throwable err) { - respObserver.onError(err); - } + @Override + public void onNext(Database.GreptimeResponse resp) { + int affectedRows = resp.getAffectedRows().getValue(); + Result ret = WriteOk.ok(affectedRows, 0).mapToResult(); + if (ret.isOk()) { + respObserver.onNext(ret.getOk()); + } else { + respObserver.onError(new StreamException(String.valueOf(ret.getErr()))); + } + } - @Override - public void onCompleted() { - respObserver.onCompleted(); - } - }); + @Override + public void onError(Throwable err) { + respObserver.onError(err); + } + + @Override + public void onCompleted() { + respObserver.onCompleted(); + } + }); // Some info will be set into the GreptimeDB Request header. String database = this.opts.getDatabase(); @@ -240,20 +256,16 @@ public void onCompleted() { @Override public void display(Printer out) { - out.println("--- WriteClient ---") // - .print("maxRetries=") // - .println(this.opts.getMaxRetries()) // - .print("asyncPool=") // + out.println("--- WriteClient ---") + .print("maxRetries=") + .println(this.opts.getMaxRetries()) + .print("asyncPool=") .println(this.asyncPool); } @Override public String toString() { - return "WriteClient{" + // - "opts=" + opts + // - ", routerClient=" + routerClient + // - ", asyncPool=" + asyncPool + // - '}'; + return "WriteClient{" + "opts=" + opts + ", routerClient=" + routerClient + ", asyncPool=" + asyncPool + '}'; } static final class InnerMetricHelper { @@ -261,8 +273,8 @@ static final class InnerMetricHelper { static final Histogram DELETE_ROWS_SUCCESS_NUM = MetricsUtil.histogram("delete_rows_success_num"); static final Histogram INSERT_ROWS_FAILURE_NUM = MetricsUtil.histogram("insert_rows_failure_num"); static final Histogram DELETE_ROWS_FAILURE_NUM = MetricsUtil.histogram("delete_rows_failure_num"); - static final Timer WRITE_STREAM_LIMITER_ACQUIRE_WAIT_TIME = MetricsUtil - .timer("write_stream_limiter_acquire_wait_time"); + static final Timer WRITE_STREAM_LIMITER_ACQUIRE_WAIT_TIME = + MetricsUtil.timer("write_stream_limiter_acquire_wait_time"); static final Meter WRITE_FAILURE_NUM = MetricsUtil.meter("write_failure_num"); static final Meter WRITE_QPS = MetricsUtil.meter("write_qps"); @@ -319,17 +331,15 @@ public int calculatePermits(Collection
in) { @Override public Result rejected(Collection
in, RejectedState state) { - String errMsg = - String.format("Write limited by client, acquirePermits=%d, maxPermits=%d, availablePermits=%d.", // - state.acquirePermits(), // - state.maxPermits(), // - state.availablePermits()); + String errMsg = String.format( + "Write limited by client, acquirePermits=%d, maxPermits=%d, availablePermits=%d.", + state.acquirePermits(), state.maxPermits(), state.availablePermits()); return Result.err(Err.writeErr(Result.FLOW_CONTROL, new LimitedException(errMsg), null)); } } @SuppressWarnings("UnstableApiUsage") - static abstract class RateLimitingStreamWriter implements StreamWriter { + abstract static class RateLimitingStreamWriter implements StreamWriter { private final Observer observer; private final RateLimiter rateLimiter; diff --git a/ingester-protocol/src/main/java/io/greptime/WriteObject.java b/ingester-protocol/src/main/java/io/greptime/WriteObject.java index a309f78..70d6c84 100644 --- a/ingester-protocol/src/main/java/io/greptime/WriteObject.java +++ b/ingester-protocol/src/main/java/io/greptime/WriteObject.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import io.greptime.models.Err; import io.greptime.models.Result; import io.greptime.models.WriteOk; import io.greptime.rpc.Context; - import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -27,8 +27,6 @@ /** * Write POJO object API: writes data in POJO object format to the DB. - * - * @author jiachun.fjc */ public interface WriteObject { /** diff --git a/ingester-protocol/src/main/java/io/greptime/WriteOp.java b/ingester-protocol/src/main/java/io/greptime/WriteOp.java index 025b606..6a7225e 100644 --- a/ingester-protocol/src/main/java/io/greptime/WriteOp.java +++ b/ingester-protocol/src/main/java/io/greptime/WriteOp.java @@ -13,11 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; /** - * @author jiachun.fjc + * */ public enum WriteOp { - Insert, Delete, + Insert, + Delete, } diff --git a/ingester-protocol/src/main/java/io/greptime/errors/LimitedException.java b/ingester-protocol/src/main/java/io/greptime/errors/LimitedException.java index bfe5725..fa15d1a 100644 --- a/ingester-protocol/src/main/java/io/greptime/errors/LimitedException.java +++ b/ingester-protocol/src/main/java/io/greptime/errors/LimitedException.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.errors; /** * A flow control exception that can be thrown by AbortPolicy. - * - * @author jiachun.fjc */ public class LimitedException extends RuntimeException { diff --git a/ingester-protocol/src/main/java/io/greptime/errors/PojoException.java b/ingester-protocol/src/main/java/io/greptime/errors/PojoException.java index 0577f31..502437e 100644 --- a/ingester-protocol/src/main/java/io/greptime/errors/PojoException.java +++ b/ingester-protocol/src/main/java/io/greptime/errors/PojoException.java @@ -13,10 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.errors; /** - * @author jiachun.fjc + * */ public class PojoException extends RuntimeException { diff --git a/ingester-protocol/src/main/java/io/greptime/errors/ServerException.java b/ingester-protocol/src/main/java/io/greptime/errors/ServerException.java index 8ddb74d..ec1840d 100644 --- a/ingester-protocol/src/main/java/io/greptime/errors/ServerException.java +++ b/ingester-protocol/src/main/java/io/greptime/errors/ServerException.java @@ -13,10 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.errors; /** - * @author jiachun.fjc + * */ public class ServerException extends RuntimeException { diff --git a/ingester-protocol/src/main/java/io/greptime/errors/StreamException.java b/ingester-protocol/src/main/java/io/greptime/errors/StreamException.java index a0b861a..b6f23b2 100644 --- a/ingester-protocol/src/main/java/io/greptime/errors/StreamException.java +++ b/ingester-protocol/src/main/java/io/greptime/errors/StreamException.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.errors; /** * Error about stream-write. - * - * @author jiachun.fjc */ public class StreamException extends RuntimeException { diff --git a/ingester-protocol/src/main/java/io/greptime/limit/AbstractLimiter.java b/ingester-protocol/src/main/java/io/greptime/limit/AbstractLimiter.java index 40ad276..1bb5c88 100644 --- a/ingester-protocol/src/main/java/io/greptime/limit/AbstractLimiter.java +++ b/ingester-protocol/src/main/java/io/greptime/limit/AbstractLimiter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.limit; import com.codahale.metrics.Histogram; @@ -29,8 +30,6 @@ * total number of permits, we will allow this request under the condition * that the available permits are equal to the maximum number of permits, * i.e., there are no in-flight requests. - * - * @author jiachun.fjc */ public abstract class AbstractLimiter { diff --git a/ingester-protocol/src/main/java/io/greptime/limit/InFlightLimiter.java b/ingester-protocol/src/main/java/io/greptime/limit/InFlightLimiter.java index fa4f9da..7e109a7 100644 --- a/ingester-protocol/src/main/java/io/greptime/limit/InFlightLimiter.java +++ b/ingester-protocol/src/main/java/io/greptime/limit/InFlightLimiter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.limit; import com.codahale.metrics.Timer; @@ -24,8 +25,6 @@ /** * In-flight limiter. - * - * @author jiachun.fjc */ public class InFlightLimiter implements Limiter { diff --git a/ingester-protocol/src/main/java/io/greptime/limit/LimitedPolicy.java b/ingester-protocol/src/main/java/io/greptime/limit/LimitedPolicy.java index 038257b..a90a2ec 100644 --- a/ingester-protocol/src/main/java/io/greptime/limit/LimitedPolicy.java +++ b/ingester-protocol/src/main/java/io/greptime/limit/LimitedPolicy.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.limit; import io.greptime.errors.LimitedException; @@ -20,8 +21,6 @@ /** * A limited policy using a given {@code Limiter}. - * - * @author jiachun.fjc */ public interface LimitedPolicy { @@ -60,11 +59,9 @@ public boolean acquire(Limiter limiter, int permits) { return true; } - final String err = - String.format("Limited by `AbortPolicy`, acquirePermits=%d, maxPermits=%d, availablePermits=%d.", // - permits, // - limiter.maxPermits(), // - limiter.availablePermits()); + final String err = String.format( + "Limited by `AbortPolicy`, acquirePermits=%d, maxPermits=%d, availablePermits=%d.", + permits, limiter.maxPermits(), limiter.availablePermits()); throw new LimitedException(err); } } @@ -122,14 +119,10 @@ public boolean acquire(Limiter limiter, int permits) { return true; } - String err = - String.format("Limited by `AbortOnBlockingTimeoutPolicy[timeout=%d, unit=%s]`, acquirePermits=%d, " - + "maxPermits=%d, availablePermits=%d.", // - timeout(), // - unit(), // - permits, // - limiter.maxPermits(), // - limiter.availablePermits()); + String err = String.format( + "Limited by `AbortOnBlockingTimeoutPolicy[timeout=%d, unit=%s]`, acquirePermits=%d, " + + "maxPermits=%d, availablePermits=%d.", + timeout(), unit(), permits, limiter.maxPermits(), limiter.availablePermits()); throw new LimitedException(err); } } diff --git a/ingester-protocol/src/main/java/io/greptime/limit/Limiter.java b/ingester-protocol/src/main/java/io/greptime/limit/Limiter.java index e13b37e..931360c 100644 --- a/ingester-protocol/src/main/java/io/greptime/limit/Limiter.java +++ b/ingester-protocol/src/main/java/io/greptime/limit/Limiter.java @@ -13,14 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.limit; import java.util.concurrent.TimeUnit; /** * A rate limiter. - * - * @author jiachun.fjc */ public interface Limiter { diff --git a/ingester-protocol/src/main/java/io/greptime/limit/WriteLimiter.java b/ingester-protocol/src/main/java/io/greptime/limit/WriteLimiter.java index 77d32d4..3ec9024 100644 --- a/ingester-protocol/src/main/java/io/greptime/limit/WriteLimiter.java +++ b/ingester-protocol/src/main/java/io/greptime/limit/WriteLimiter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.limit; import io.greptime.models.Err; @@ -23,8 +24,6 @@ /** * Like rust: pub type WriteLimiter = AbstractLimiter> - * - * @author jiachun.fjc */ public abstract class WriteLimiter extends AbstractLimiter, Result> { diff --git a/ingester-protocol/src/main/java/io/greptime/models/AuthInfo.java b/ingester-protocol/src/main/java/io/greptime/models/AuthInfo.java index e5d27c4..74abf95 100644 --- a/ingester-protocol/src/main/java/io/greptime/models/AuthInfo.java +++ b/ingester-protocol/src/main/java/io/greptime/models/AuthInfo.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.models; import io.greptime.common.Into; @@ -20,8 +21,6 @@ /** * Greptime authentication information - * - * @author sunng87 */ public class AuthInfo implements Into { @@ -42,12 +41,10 @@ public static AuthInfo noAuthorization() { @Override public Common.AuthHeader into() { - Common.Basic basic = Common.Basic.newBuilder() // - .setUsername(this.username) // - .setPassword(this.password) // - .build(); - return Common.AuthHeader.newBuilder() // - .setBasic(basic) // + Common.Basic basic = Common.Basic.newBuilder() + .setUsername(this.username) + .setPassword(this.password) .build(); + return Common.AuthHeader.newBuilder().setBasic(basic).build(); } } diff --git a/ingester-protocol/src/main/java/io/greptime/models/Column.java b/ingester-protocol/src/main/java/io/greptime/models/Column.java index d2f74fb..b15bdd7 100644 --- a/ingester-protocol/src/main/java/io/greptime/models/Column.java +++ b/ingester-protocol/src/main/java/io/greptime/models/Column.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.models; import java.lang.annotation.ElementType; @@ -22,8 +23,6 @@ /** * This annotation is used to mapping POJO class into {@link Table}. - * - * @author jiachun.fjc */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) diff --git a/ingester-protocol/src/main/java/io/greptime/models/DataType.java b/ingester-protocol/src/main/java/io/greptime/models/DataType.java index 8fabf8f..5c2b711 100644 --- a/ingester-protocol/src/main/java/io/greptime/models/DataType.java +++ b/ingester-protocol/src/main/java/io/greptime/models/DataType.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.models; import io.greptime.common.Into; @@ -20,41 +21,41 @@ /** * GreptimeDB's data type. - * - * @author jiachun.fjc */ public enum DataType { - Bool, // - Int8, // - Int16, // - Int32, // - Int64, // - UInt8, // - UInt16, // - UInt32, // - UInt64, // - Float32, // - Float64, // - Binary, // - String, // - Date, // - DateTime, // - TimestampSecond, // - TimestampMillisecond, // - TimestampMicrosecond, // - TimestampNanosecond, // - TimeSecond, // - TimeMilliSecond, // - TimeMicroSecond, // - TimeNanoSecond, // - IntervalYearMonth, // - IntervalDayTime, // - IntervalMonthDayNano, // - Decimal128, // + Bool, + Int8, + Int16, + Int32, + Int64, + UInt8, + UInt16, + UInt32, + UInt64, + Float32, + Float64, + Binary, + String, + Date, + DateTime, + TimestampSecond, + TimestampMillisecond, + TimestampMicrosecond, + TimestampNanosecond, + TimeSecond, + TimeMilliSecond, + TimeMicroSecond, + TimeNanoSecond, + IntervalYearMonth, + IntervalDayTime, + IntervalMonthDayNano, + Decimal128, ; public boolean isTimestamp() { - return this == TimestampSecond || this == TimestampMillisecond || this == TimestampMicrosecond + return this == TimestampSecond + || this == TimestampMillisecond + || this == TimestampMicrosecond || this == TimestampNanosecond; } @@ -126,8 +127,8 @@ public static class DecimalTypeExtension implements Into Result mapToResult() { @Override public String toString() { - return "Err{" + // - "code=" + code + // - ", error='" + error + '\'' + // - ", errTo=" + errTo + // - '}'; + return "Err{" + "code=" + code + ", error='" + error + '\'' + ", errTo=" + errTo + '}'; } /** diff --git a/ingester-protocol/src/main/java/io/greptime/models/IntervalMonthDayNano.java b/ingester-protocol/src/main/java/io/greptime/models/IntervalMonthDayNano.java index 69e09d9..4e2557e 100644 --- a/ingester-protocol/src/main/java/io/greptime/models/IntervalMonthDayNano.java +++ b/ingester-protocol/src/main/java/io/greptime/models/IntervalMonthDayNano.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.models; import io.greptime.common.Into; import io.greptime.v1.Common; /** - * @author jiachun.fjc + * */ public class IntervalMonthDayNano implements Into { private final int months; @@ -34,10 +35,10 @@ public IntervalMonthDayNano(int months, int days, long nanoseconds) { @Override public Common.IntervalMonthDayNano into() { - return Common.IntervalMonthDayNano.newBuilder() // - .setMonths(this.months) // - .setDays(this.days) // - .setNanoseconds(this.nanoseconds) // + return Common.IntervalMonthDayNano.newBuilder() + .setMonths(this.months) + .setDays(this.days) + .setNanoseconds(this.nanoseconds) .build(); } } diff --git a/ingester-protocol/src/main/java/io/greptime/models/Metric.java b/ingester-protocol/src/main/java/io/greptime/models/Metric.java index e1e2e68..7d02da3 100644 --- a/ingester-protocol/src/main/java/io/greptime/models/Metric.java +++ b/ingester-protocol/src/main/java/io/greptime/models/Metric.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.models; import java.lang.annotation.ElementType; @@ -22,8 +23,6 @@ /** * This annotation is used to mapping POJO class into {@link Table}. - * - * @author jiachun.fjc */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) diff --git a/ingester-protocol/src/main/java/io/greptime/models/Result.java b/ingester-protocol/src/main/java/io/greptime/models/Result.java index d3e6c07..1349cab 100644 --- a/ingester-protocol/src/main/java/io/greptime/models/Result.java +++ b/ingester-protocol/src/main/java/io/greptime/models/Result.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.models; import io.greptime.common.util.Ensures; @@ -20,8 +21,6 @@ /** * `Result` is a type that represents either success ([`Ok`]) or failure ([`Err`]). - * - * @author jiachun.fjc */ public final class Result { diff --git a/ingester-protocol/src/main/java/io/greptime/models/RowHelper.java b/ingester-protocol/src/main/java/io/greptime/models/RowHelper.java index 046a025..15b1f3f 100644 --- a/ingester-protocol/src/main/java/io/greptime/models/RowHelper.java +++ b/ingester-protocol/src/main/java/io/greptime/models/RowHelper.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.models; import com.google.protobuf.ByteStringHelper; @@ -21,14 +22,13 @@ /** * A utility that handles some processing of row based data. - * - * @author jiachun.fjc */ public final class RowHelper { - public static void addValue(RowData.Row.Builder builder, // - Common.ColumnDataType dataType, // - Common.ColumnDataTypeExtension dataTypeExtension, // + public static void addValue( + RowData.Row.Builder builder, + Common.ColumnDataType dataType, + Common.ColumnDataTypeExtension dataTypeExtension, Object value) { RowData.Value.Builder valueBuilder = RowData.Value.newBuilder(); if (value == null) { diff --git a/ingester-protocol/src/main/java/io/greptime/models/SemanticType.java b/ingester-protocol/src/main/java/io/greptime/models/SemanticType.java index 9d25469..9f4c97d 100644 --- a/ingester-protocol/src/main/java/io/greptime/models/SemanticType.java +++ b/ingester-protocol/src/main/java/io/greptime/models/SemanticType.java @@ -13,17 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.models; import io.greptime.v1.Common; /** * The semantic type. - * - * @author jiachun.fjc */ public enum SemanticType { - Tag, Field, Timestamp; + Tag, + Field, + Timestamp; /** * Converts to the corresponding proto value. diff --git a/ingester-protocol/src/main/java/io/greptime/models/Table.java b/ingester-protocol/src/main/java/io/greptime/models/Table.java index af1b34d..cb2d636 100644 --- a/ingester-protocol/src/main/java/io/greptime/models/Table.java +++ b/ingester-protocol/src/main/java/io/greptime/models/Table.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.models; import io.greptime.common.Into; @@ -20,14 +21,11 @@ import io.greptime.v1.Common; import io.greptime.v1.Database; import io.greptime.v1.RowData; - import java.util.ArrayList; import java.util.List; /** * Data in row format, ready to be written to the DB. - * - * @author jiachun.fjc */ public interface Table { @@ -107,26 +105,29 @@ public Table build() { Ensures.ensure(columnCount > 0, "Empty column names"); Ensures.ensure(columnCount == semanticTypes.size(), "Column names size not equal to semantic types size"); Ensures.ensure(columnCount == dataTypes.size(), "Column names size not equal to data types size"); - Ensures.ensure(columnCount == dataTypeExtensions.size(), "Column names size not equal to data type extensions size"); + Ensures.ensure( + columnCount == dataTypeExtensions.size(), + "Column names size not equal to data type extensions size"); return buildTable(tableName, columnCount, columnNames, semanticTypes, dataTypes, dataTypeExtensions); } - private static Table buildTable(String tableName, // - int columnCount, // - List columnNames, // - List semanticTypes, // - List dataTypes, // - List dataTypeExtensions) { + private static Table buildTable( + String tableName, + int columnCount, + List columnNames, + List semanticTypes, + List dataTypes, + List dataTypeExtensions) { RowBasedTable table = new RowBasedTable(); table.tableName = tableName; table.columnSchemas = new ArrayList<>(columnCount); for (int i = 0; i < columnCount; i++) { RowData.ColumnSchema.Builder builder = RowData.ColumnSchema.newBuilder(); - builder.setColumnName(columnNames.get(i)) // - .setSemanticType(semanticTypes.get(i)) // - .setDatatype(dataTypes.get(i)) // + builder.setColumnName(columnNames.get(i)) + .setSemanticType(semanticTypes.get(i)) + .setDatatype(dataTypes.get(i)) .setDatatypeExtension(dataTypeExtensions.get(i)); table.columnSchemas.add(builder.build()); } @@ -189,25 +190,25 @@ public Table subRange(int fromIndex, int toIndex) { @Override public Database.RowInsertRequest intoRowInsertRequest() { - return Database.RowInsertRequest.newBuilder() // - .setTableName(this.tableName) // - .setRows(into()) // + return Database.RowInsertRequest.newBuilder() + .setTableName(this.tableName) + .setRows(into()) .build(); } @Override public Database.RowDeleteRequest intoRowDeleteRequest() { - return Database.RowDeleteRequest.newBuilder() // - .setTableName(this.tableName) // - .setRows(into()) // + return Database.RowDeleteRequest.newBuilder() + .setTableName(this.tableName) + .setRows(into()) .build(); } @Override public RowData.Rows into() { - return RowData.Rows.newBuilder() // - .addAllSchema(this.columnSchemas) // - .addAllRows(this.rows) // + return RowData.Rows.newBuilder() + .addAllSchema(this.columnSchemas) + .addAllRows(this.rows) .build(); } } diff --git a/ingester-protocol/src/main/java/io/greptime/models/TableHelper.java b/ingester-protocol/src/main/java/io/greptime/models/TableHelper.java index c029125..3342926 100644 --- a/ingester-protocol/src/main/java/io/greptime/models/TableHelper.java +++ b/ingester-protocol/src/main/java/io/greptime/models/TableHelper.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.models; import io.greptime.WriteOp; @@ -22,11 +23,12 @@ import java.util.Collection; /** - * @author jiachun.fjc + * */ public class TableHelper { - public static Database.GreptimeRequest toGreptimeRequest(WriteTables writeTables, String database, AuthInfo authInfo) { + public static Database.GreptimeRequest toGreptimeRequest( + WriteTables writeTables, String database, AuthInfo authInfo) { Common.RequestHeader.Builder headerBuilder = Common.RequestHeader.newBuilder(); if (database != null) { headerBuilder.setDbname(database); @@ -45,9 +47,9 @@ public static Database.GreptimeRequest toGreptimeRequest(WriteTables writeTables Ensures.ensure(t.pointCount() > 0, "No data to insert in table: %s", t.tableName()); insertBuilder.addInserts(t.intoRowInsertRequest()); } - return Database.GreptimeRequest.newBuilder() // - .setHeader(headerBuilder.build()) // - .setRowInserts(insertBuilder.build()) // + return Database.GreptimeRequest.newBuilder() + .setHeader(headerBuilder.build()) + .setRowInserts(insertBuilder.build()) .build(); case Delete: Database.RowDeleteRequests.Builder deleteBuilder = Database.RowDeleteRequests.newBuilder(); @@ -55,9 +57,9 @@ public static Database.GreptimeRequest toGreptimeRequest(WriteTables writeTables Ensures.ensure(t.pointCount() > 0, "No data to delete in table: %s", t.tableName()); deleteBuilder.addDeletes(t.intoRowDeleteRequest()); } - return Database.GreptimeRequest.newBuilder() // - .setHeader(headerBuilder.build()) // - .setRowDeletes(deleteBuilder.build()) // + return Database.GreptimeRequest.newBuilder() + .setHeader(headerBuilder.build()) + .setRowDeletes(deleteBuilder.build()) .build(); default: throw new IllegalArgumentException("Unsupported write operation: " + writeOp); diff --git a/ingester-protocol/src/main/java/io/greptime/models/TableSchema.java b/ingester-protocol/src/main/java/io/greptime/models/TableSchema.java index aabdba9..0839336 100644 --- a/ingester-protocol/src/main/java/io/greptime/models/TableSchema.java +++ b/ingester-protocol/src/main/java/io/greptime/models/TableSchema.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.models; import io.greptime.common.util.Ensures; @@ -27,8 +28,6 @@ * to prevent redundant creation. The responsibility of caching lies with the user, * as the `Ingester` client should strive to avoid managing the cache and excessive * memory consumption. - * - * @author jiachun.fjc */ public class TableSchema { @@ -102,8 +101,10 @@ public Builder addTag(String name, DataType dataType) { * @return this builder */ public Builder addTimestamp(String name, DataType dataType) { - Ensures.ensure(dataType.isTimestamp(), - "Invalid timestamp data type: %s, only support `DataType.TimestampXXX`", dataType); + Ensures.ensure( + dataType.isTimestamp(), + "Invalid timestamp data type: %s, only support `DataType.TimestampXXX`", + dataType); return addColumn(name, SemanticType.Timestamp, dataType); } @@ -151,17 +152,20 @@ public Builder addColumn(String name, SemanticType semanticType, DataType dataTy * @param decimalTypeExtension the decimal type extension of this column(only for `DataType.Decimal128`) * @return this builder */ - public Builder addColumn(String name, // - SemanticType semanticType, // - DataType dataType, // + public Builder addColumn( + String name, + SemanticType semanticType, + DataType dataType, DataType.DecimalTypeExtension decimalTypeExtension) { Ensures.ensureNonNull(name, "Null column name"); Ensures.ensureNonNull(semanticType, "Null semantic type"); Ensures.ensureNonNull(dataType, "Null data type"); if (semanticType == SemanticType.Timestamp) { - Ensures.ensure(dataType.isTimestamp(), - "Invalid timestamp data type: %s, only support `DataType.TimestampXXX`", dataType); + Ensures.ensure( + dataType.isTimestamp(), + "Invalid timestamp data type: %s, only support `DataType.TimestampXXX`", + dataType); } // Trim leading and trailing spaces @@ -174,8 +178,8 @@ public Builder addColumn(String name, // this.dataTypeExtensions.add(Common.ColumnDataTypeExtension.getDefaultInstance()); } else { Ensures.ensure(dataType == DataType.Decimal128, "Only decimal type can have decimal type extension"); - Common.ColumnDataTypeExtension ext = Common.ColumnDataTypeExtension.newBuilder() // - .setDecimalType(decimalTypeExtension.into()) // + Common.ColumnDataTypeExtension ext = Common.ColumnDataTypeExtension.newBuilder() + .setDecimalType(decimalTypeExtension.into()) .build(); this.dataTypeExtensions.add(ext); } @@ -196,10 +200,11 @@ public TableSchema build() { int columnCount = this.columnNames.size(); Ensures.ensure(columnCount > 0, "Empty column names"); - Ensures.ensure(columnCount == this.semanticTypes.size(), - "Column names size not equal to semantic types size"); + Ensures.ensure( + columnCount == this.semanticTypes.size(), "Column names size not equal to semantic types size"); Ensures.ensure(columnCount == this.dataTypes.size(), "Column names size not equal to data types size"); - Ensures.ensure(columnCount == this.dataTypeExtensions.size(), + Ensures.ensure( + columnCount == this.dataTypeExtensions.size(), "Column names size not equal to data type extensions size"); TableSchema tableSchema = new TableSchema(); diff --git a/ingester-protocol/src/main/java/io/greptime/models/ValueUtil.java b/ingester-protocol/src/main/java/io/greptime/models/ValueUtil.java index 20d7db0..5e17f76 100644 --- a/ingester-protocol/src/main/java/io/greptime/models/ValueUtil.java +++ b/ingester-protocol/src/main/java/io/greptime/models/ValueUtil.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.models; import io.greptime.common.util.Ensures; @@ -25,7 +26,7 @@ import java.util.Date; /** - * @author jiachun.fjc + * */ public class ValueUtil { @@ -81,7 +82,9 @@ static long getDateTimeValue(Object value) { } static Common.IntervalMonthDayNano getIntervalMonthDayNanoValue(Object value) { - Ensures.ensure(value instanceof IntervalMonthDayNano, "Expected type: `IntervalMonthDayNano`, actual: %s", + Ensures.ensure( + value instanceof IntervalMonthDayNano, + "Expected type: `IntervalMonthDayNano`, actual: %s", value.getClass()); return ((IntervalMonthDayNano) value).into(); } @@ -89,9 +92,9 @@ static Common.IntervalMonthDayNano getIntervalMonthDayNanoValue(Object value) { static Common.Decimal128 getDecimal128Value(Common.ColumnDataTypeExtension dataTypeExtension, Object value) { Ensures.ensure(value instanceof BigDecimal, "Expected type: `BigDecimal`, actual: %s", value.getClass()); Ensures.ensureNonNull(dataTypeExtension, "Null `dataTypeExtension`"); - Common.DecimalTypeExtension decimalTypeExtension = - dataTypeExtension.hasDecimalType() ? dataTypeExtension.getDecimalType() - : DataType.DecimalTypeExtension.DEFAULT.into(); + Common.DecimalTypeExtension decimalTypeExtension = dataTypeExtension.hasDecimalType() + ? dataTypeExtension.getDecimalType() + : DataType.DecimalTypeExtension.DEFAULT.into(); BigDecimal decimal = (BigDecimal) value; BigDecimal converted = decimal.setScale(decimalTypeExtension.getScale(), RoundingMode.HALF_UP); @@ -99,9 +102,6 @@ static Common.Decimal128 getDecimal128Value(Common.ColumnDataTypeExtension dataT long high64Bits = unscaledValue.shiftRight(64).longValue(); long low64Bits = unscaledValue.longValue(); - return Common.Decimal128.newBuilder() // - .setHi(high64Bits) // - .setLo(low64Bits) // - .build(); + return Common.Decimal128.newBuilder().setHi(high64Bits).setLo(low64Bits).build(); } } diff --git a/ingester-protocol/src/main/java/io/greptime/models/WriteOk.java b/ingester-protocol/src/main/java/io/greptime/models/WriteOk.java index 1c498de..0969eec 100644 --- a/ingester-protocol/src/main/java/io/greptime/models/WriteOk.java +++ b/ingester-protocol/src/main/java/io/greptime/models/WriteOk.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.models; /** * Contains the success value of write. - * - * @author jiachun.fjc */ public class WriteOk { @@ -48,10 +47,7 @@ public Result mapToResult() { @Override public String toString() { - return "WriteOk{" + // - "success=" + success + // - ", failure=" + failure + // - '}'; + return "WriteOk{" + "success=" + success + ", failure=" + failure + '}'; } /** diff --git a/ingester-protocol/src/main/java/io/greptime/models/WriteTables.java b/ingester-protocol/src/main/java/io/greptime/models/WriteTables.java index 9cae922..a2ceabb 100644 --- a/ingester-protocol/src/main/java/io/greptime/models/WriteTables.java +++ b/ingester-protocol/src/main/java/io/greptime/models/WriteTables.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.models; import io.greptime.WriteOp; @@ -20,7 +21,7 @@ import java.util.Collections; /** - * @author jiachun.fjc + * */ public class WriteTables { private final Collection
tables; diff --git a/ingester-protocol/src/main/java/io/greptime/options/GreptimeOptions.java b/ingester-protocol/src/main/java/io/greptime/options/GreptimeOptions.java index cc8a45c..f35d6b9 100644 --- a/ingester-protocol/src/main/java/io/greptime/options/GreptimeOptions.java +++ b/ingester-protocol/src/main/java/io/greptime/options/GreptimeOptions.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.options; import io.greptime.Router; @@ -32,8 +33,6 @@ /** * GreptimeDB client options. - * - * @author jiachun.fjc */ public class GreptimeOptions implements Copiable { private List endpoints; @@ -101,13 +100,12 @@ public GreptimeOptions copy() { @Override public String toString() { - return "GreptimeOptions{" + // - "endpoints=" + endpoints + // - ", rpcOptions=" + rpcOptions + // - ", routerOptions=" + routerOptions + // - ", writeOptions=" + writeOptions + // - ", database='" + database + '\'' + // - '}'; + return "GreptimeOptions{" + "endpoints=" + + endpoints + ", rpcOptions=" + + rpcOptions + ", routerOptions=" + + routerOptions + ", writeOptions=" + + writeOptions + ", database='" + + database + '\'' + '}'; } public static GreptimeOptions checkSelf(GreptimeOptions opts) { diff --git a/ingester-protocol/src/main/java/io/greptime/options/RouterOptions.java b/ingester-protocol/src/main/java/io/greptime/options/RouterOptions.java index 6b115dc..d5e578d 100644 --- a/ingester-protocol/src/main/java/io/greptime/options/RouterOptions.java +++ b/ingester-protocol/src/main/java/io/greptime/options/RouterOptions.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.options; import io.greptime.Router; @@ -23,8 +24,6 @@ /** * Router options. - * - * @author jiachun.fjc */ public class RouterOptions implements Copiable { @@ -81,10 +80,9 @@ public RouterOptions copy() { @Override public String toString() { - return "RouterOptions{" + // - "endpoints=" + endpoints + // - ", refreshPeriodSeconds=" + refreshPeriodSeconds + // - ", router=" + router + // - '}'; + return "RouterOptions{" + "endpoints=" + + endpoints + ", refreshPeriodSeconds=" + + refreshPeriodSeconds + ", router=" + + router + '}'; } } diff --git a/ingester-protocol/src/main/java/io/greptime/options/WriteOptions.java b/ingester-protocol/src/main/java/io/greptime/options/WriteOptions.java index 6449a94..dc92d1f 100644 --- a/ingester-protocol/src/main/java/io/greptime/options/WriteOptions.java +++ b/ingester-protocol/src/main/java/io/greptime/options/WriteOptions.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.options; import io.greptime.RouterClient; @@ -23,8 +24,6 @@ /** * Write options. - * - * @author jiachun.fjc */ public class WriteOptions implements Copiable { private String database; @@ -119,14 +118,13 @@ public WriteOptions copy() { @Override public String toString() { // Do not print auto info - return "WriteOptions{" + // - "database='" + database + '\'' + // - ", routerClient=" + routerClient + // - ", asyncPool=" + asyncPool + // - ", maxRetries=" + maxRetries + // - ", maxInFlightWritePoints=" + maxInFlightWritePoints + // - ", limitedPolicy=" + limitedPolicy + // - ", defaultStreamMaxWritePointsPerSecond=" + defaultStreamMaxWritePointsPerSecond + // - '}'; + return "WriteOptions{" + "database='" + + database + '\'' + ", routerClient=" + + routerClient + ", asyncPool=" + + asyncPool + ", maxRetries=" + + maxRetries + ", maxInFlightWritePoints=" + + maxInFlightWritePoints + ", limitedPolicy=" + + limitedPolicy + ", defaultStreamMaxWritePointsPerSecond=" + + defaultStreamMaxWritePointsPerSecond + '}'; } } diff --git a/ingester-protocol/src/main/java/io/greptime/signal/DisplaySignalHandler.java b/ingester-protocol/src/main/java/io/greptime/signal/DisplaySignalHandler.java index c4ab479..6030752 100644 --- a/ingester-protocol/src/main/java/io/greptime/signal/DisplaySignalHandler.java +++ b/ingester-protocol/src/main/java/io/greptime/signal/DisplaySignalHandler.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.signal; import io.greptime.GreptimeDB; @@ -22,8 +23,6 @@ import io.greptime.common.signal.FileSignalHelper; import io.greptime.common.signal.SignalHandler; import io.greptime.common.util.Files; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -31,11 +30,11 @@ import java.io.PrintWriter; import java.nio.charset.StandardCharsets; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A signal handler that can display all client instance's memory state. - * - * @author jiachun.fjc */ @SPI(priority = 98) public class DisplaySignalHandler implements SignalHandler { @@ -58,7 +57,9 @@ public void handle(String signalName) { try { File file = FileOutputHelper.getOutputFile(BASE_NAME); - LOG.info("Displaying GreptimeDB clients triggered by signal: {} to file: {}.", signalName, + LOG.info( + "Displaying GreptimeDB clients triggered by signal: {} to file: {}.", + signalName, file.getAbsoluteFile()); try (PrintWriter out = diff --git a/ingester-protocol/src/main/java/io/greptime/signal/MetricsSignalHandler.java b/ingester-protocol/src/main/java/io/greptime/signal/MetricsSignalHandler.java index 0c96685..993a39c 100644 --- a/ingester-protocol/src/main/java/io/greptime/signal/MetricsSignalHandler.java +++ b/ingester-protocol/src/main/java/io/greptime/signal/MetricsSignalHandler.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.signal; import io.greptime.common.SPI; @@ -22,17 +23,15 @@ import io.greptime.common.util.Files; import io.greptime.common.util.MetricReporter; import io.greptime.common.util.MetricsUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A signal handle that can write the metrics into a file. - * - * @author jiachun.fjc */ @SPI(priority = 97) public class MetricsSignalHandler implements SignalHandler { @@ -50,13 +49,15 @@ public void handle(String signalName) { try { File file = FileOutputHelper.getOutputFile(BASE_NAME); - LOG.info("Printing GreptimeDB clients metrics triggered by signal: {} to file: {}.", signalName, + LOG.info( + "Printing GreptimeDB clients metrics triggered by signal: {} to file: {}.", + signalName, file.getAbsoluteFile()); try (PrintStream out = new PrintStream(new FileOutputStream(file, true))) { - MetricReporter reporter = MetricReporter.forRegistry(MetricsUtil.metricRegistry()) // - .outputTo(out) // - .prefixedWith("-- GreptimeDB") // + MetricReporter reporter = MetricReporter.forRegistry(MetricsUtil.metricRegistry()) + .outputTo(out) + .prefixedWith("-- GreptimeDB") .build(); reporter.report(); out.flush(); diff --git a/ingester-protocol/src/main/java/io/greptime/signal/RwLoggingSignalHandler.java b/ingester-protocol/src/main/java/io/greptime/signal/RwLoggingSignalHandler.java index eb7d261..95489e4 100644 --- a/ingester-protocol/src/main/java/io/greptime/signal/RwLoggingSignalHandler.java +++ b/ingester-protocol/src/main/java/io/greptime/signal/RwLoggingSignalHandler.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.signal; import io.greptime.Util; @@ -25,8 +26,6 @@ /** * A signal handler that can reset RW_LOGGING by {@link Util#resetRwLogging()}. - * - * @author jiachun.fjc */ @SPI(priority = 95) public class RwLoggingSignalHandler implements SignalHandler { diff --git a/ingester-protocol/src/main/java/io/greptime/signal/ShowHelpSignalHandler.java b/ingester-protocol/src/main/java/io/greptime/signal/ShowHelpSignalHandler.java index 0238184..a698921 100644 --- a/ingester-protocol/src/main/java/io/greptime/signal/ShowHelpSignalHandler.java +++ b/ingester-protocol/src/main/java/io/greptime/signal/ShowHelpSignalHandler.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.signal; import io.greptime.common.SPI; @@ -25,8 +26,6 @@ /** * A signal handler that can show help info. - * - * @author jiachun.fjc */ @SPI(priority = 99) public class ShowHelpSignalHandler implements SignalHandler { diff --git a/ingester-protocol/src/main/resources/client_version.properties b/ingester-protocol/src/main/resources/client_version.properties index 1ec1e63..eea62a5 100644 --- a/ingester-protocol/src/main/resources/client_version.properties +++ b/ingester-protocol/src/main/resources/client_version.properties @@ -1 +1,15 @@ +# Copyright 2023 Greptime Team +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + client.version=0.7.3 diff --git a/ingester-protocol/src/test/java/io/greptime/PojoObjectMapperTest.java b/ingester-protocol/src/test/java/io/greptime/PojoObjectMapperTest.java index 191fbd4..43392e4 100644 --- a/ingester-protocol/src/test/java/io/greptime/PojoObjectMapperTest.java +++ b/ingester-protocol/src/test/java/io/greptime/PojoObjectMapperTest.java @@ -13,20 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import io.greptime.models.Column; import io.greptime.models.DataType; import io.greptime.models.Metric; import io.greptime.models.Table; -import org.junit.Assert; -import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Random; +import org.junit.Assert; +import org.junit.Test; /** - * @author jiachun.fjc + * */ public class PojoObjectMapperTest { @@ -41,7 +42,6 @@ public void testToTable() { Assert.assertEquals("pojo1", tp1.tableName()); Assert.assertEquals(50, tp1.pointCount()); - List pojos2 = new ArrayList<>(); for (int i = 0; i < 10; i++) { Pojo2Test pojo2 = createNewPojo2Test(); @@ -72,28 +72,32 @@ static Pojo2Test createNewPojo2Test() { } } - @Metric(name = "pojo1") class Pojo1Test { @Column(name = "a", dataType = DataType.String, tag = true) String a; + @Column(name = "b", dataType = DataType.Int8) int b; + @Column(name = "c", dataType = DataType.Int64) long c; + @Column(name = "d", dataType = DataType.Float64) double d; + @Column(name = "ts", dataType = DataType.TimestampMillisecond, timestamp = true) long ts; } - @Metric(name = "pojo2") class Pojo2Test { @Column(name = "pojo2", dataType = DataType.String, tag = true) String name; + @Column(name = "a", dataType = DataType.String) String a; + @Column(name = "ts", dataType = DataType.TimestampMillisecond, timestamp = true) long ts; } diff --git a/ingester-protocol/src/test/java/io/greptime/StatusTest.java b/ingester-protocol/src/test/java/io/greptime/StatusTest.java index 089327b..7e21d3a 100644 --- a/ingester-protocol/src/test/java/io/greptime/StatusTest.java +++ b/ingester-protocol/src/test/java/io/greptime/StatusTest.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import org.junit.Assert; import org.junit.Test; /** - * @author jiachun.fjc + * */ public class StatusTest { diff --git a/ingester-protocol/src/test/java/io/greptime/TestUtil.java b/ingester-protocol/src/test/java/io/greptime/TestUtil.java index 93a2431..7072dfd 100644 --- a/ingester-protocol/src/test/java/io/greptime/TestUtil.java +++ b/ingester-protocol/src/test/java/io/greptime/TestUtil.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import io.greptime.models.DataType; @@ -25,15 +26,15 @@ import java.util.Collections; /** - * @author jiachun.fjc + * */ public class TestUtil { public static Collection
testTable(String tableName, int rowCount) { - TableSchema tableSchema = TableSchema.newBuilder(tableName) // - .addTag("host", DataType.String) // - .addTimestamp("ts", DataType.TimestampMillisecond) // - .addField("cpu", DataType.Float64) // + TableSchema tableSchema = TableSchema.newBuilder(tableName) + .addTag("host", DataType.String) + .addTimestamp("ts", DataType.TimestampMillisecond) + .addField("cpu", DataType.Float64) .build(); Table table = Table.from(tableSchema); diff --git a/ingester-protocol/src/test/java/io/greptime/UtilTest.java b/ingester-protocol/src/test/java/io/greptime/UtilTest.java index 9565d9b..54edb81 100644 --- a/ingester-protocol/src/test/java/io/greptime/UtilTest.java +++ b/ingester-protocol/src/test/java/io/greptime/UtilTest.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import org.junit.Assert; import org.junit.Test; /** - * @author jiachun.fjc + * */ public class UtilTest { diff --git a/ingester-protocol/src/test/java/io/greptime/WriteClientTest.java b/ingester-protocol/src/test/java/io/greptime/WriteClientTest.java index b990def..d4b4271 100644 --- a/ingester-protocol/src/test/java/io/greptime/WriteClientTest.java +++ b/ingester-protocol/src/test/java/io/greptime/WriteClientTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import io.greptime.common.Endpoint; @@ -26,6 +27,9 @@ import io.greptime.options.WriteOptions; import io.greptime.v1.Common; import io.greptime.v1.Database; +import java.math.BigDecimal; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ForkJoinPool; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -34,16 +38,14 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.runners.MockitoJUnitRunner; -import java.math.BigDecimal; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ForkJoinPool; /** - * @author jiachun.fjc + * */ @RunWith(value = MockitoJUnitRunner.class) public class WriteClientTest { private WriteClient writeClient; + @Mock private RouterClient routerClient; @@ -65,64 +67,56 @@ public void after() { @Test public void testWriteSuccess() throws ExecutionException, InterruptedException { - TableSchema schema = TableSchema.newBuilder("test_table") // - .addTag("test_tag", DataType.String) // - .addTimestamp("test_ts", DataType.TimestampMillisecond) // - .addField("field1", DataType.Int8) // - .addField("field2", DataType.Int16) // - .addField("field3", DataType.Int32) // - .addField("field4", DataType.Int64) // - .addField("field5", DataType.UInt8) // - .addField("field6", DataType.UInt16) // - .addField("field7", DataType.UInt32) // - .addField("field8", DataType.UInt64) // - .addField("field9", DataType.Float32) // - .addField("field10", DataType.Float64) // - .addField("field11", DataType.Bool) // - .addField("field12", DataType.Binary) // - .addField("field13", DataType.Date) // - .addField("field14", DataType.DateTime) // - .addField("field15", DataType.TimestampSecond) // - .addField("field16", DataType.TimestampMillisecond) // - .addField("field17", DataType.TimestampMicrosecond) // - .addField("field18", DataType.TimestampNanosecond) // - .addField("field19", DataType.TimeSecond) // - .addField("field20", DataType.TimeMilliSecond) // - .addField("field21", DataType.TimeMicroSecond) // - .addField("field22", DataType.TimeNanoSecond) // - .addField("field23", DataType.IntervalYearMonth) // - .addField("field24", DataType.IntervalDayTime) // - .addField("field25", DataType.IntervalMonthDayNano) // - .addField("field26", DataType.Decimal128) // + TableSchema schema = TableSchema.newBuilder("test_table") + .addTag("test_tag", DataType.String) + .addTimestamp("test_ts", DataType.TimestampMillisecond) + .addField("field1", DataType.Int8) + .addField("field2", DataType.Int16) + .addField("field3", DataType.Int32) + .addField("field4", DataType.Int64) + .addField("field5", DataType.UInt8) + .addField("field6", DataType.UInt16) + .addField("field7", DataType.UInt32) + .addField("field8", DataType.UInt64) + .addField("field9", DataType.Float32) + .addField("field10", DataType.Float64) + .addField("field11", DataType.Bool) + .addField("field12", DataType.Binary) + .addField("field13", DataType.Date) + .addField("field14", DataType.DateTime) + .addField("field15", DataType.TimestampSecond) + .addField("field16", DataType.TimestampMillisecond) + .addField("field17", DataType.TimestampMicrosecond) + .addField("field18", DataType.TimestampNanosecond) + .addField("field19", DataType.TimeSecond) + .addField("field20", DataType.TimeMilliSecond) + .addField("field21", DataType.TimeMicroSecond) + .addField("field22", DataType.TimeNanoSecond) + .addField("field23", DataType.IntervalYearMonth) + .addField("field24", DataType.IntervalDayTime) + .addField("field25", DataType.IntervalMonthDayNano) + .addField("field26", DataType.Decimal128) .build(); Table table = Table.from(schema); long ts = System.currentTimeMillis(); - Object[] row1 = - new Object[] {"tag1", ts, 1, 2, 3, 4L, 5, 6, 7, 8L, 0.9F, 0.10D, true, new byte[0], 13L, 14L, 15L, 16L, - 17L, 18L, 19L, 20L, 21L, 22L, 23, 24L, new IntervalMonthDayNano(1, 2, 3), - BigDecimal.valueOf(123.456)}; - Object[] row2 = - new Object[] {"tag2", ts, 1, 2, 3, 4L, 5, 6, 7, 8L, 0.9F, 0.10D, true, new byte[0], 13L, 14L, 15L, 16L, - 17L, 18L, 19L, 20L, 21L, 22L, 23, 24L, new IntervalMonthDayNano(4, 5, 6), - BigDecimal.valueOf(123.456)}; - Object[] row3 = - new Object[] {"tag3", ts, 1, 2, 3, 4L, 5, 6, 7, 8L, 0.9F, 0.10D, true, new byte[0], 13L, 14L, 15L, 16L, - 17L, 18L, 19L, 20L, 21L, 22L, 23, 24L, new IntervalMonthDayNano(7, 8, 9), - BigDecimal.valueOf(123.456)}; + // spotless:off + Object[] row1 = new Object[]{"tag1", ts, 1, 2, 3, 4L, 5, 6, 7, 8L, 0.9F, 0.10D, true, new byte[0], 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23, 24L, new IntervalMonthDayNano(1, 2, 3), BigDecimal.valueOf(123.456)}; + Object[] row2 = new Object[]{"tag2", ts, 1, 2, 3, 4L, 5, 6, 7, 8L, 0.9F, 0.10D, true, new byte[0], 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23, 24L, new IntervalMonthDayNano(4, 5, 6), BigDecimal.valueOf(123.456)}; + Object[] row3 = new Object[]{"tag3", ts, 1, 2, 3, 4L, 5, 6, 7, 8L, 0.9F, 0.10D, true, new byte[0], 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23, 24L, new IntervalMonthDayNano(7, 8, 9), BigDecimal.valueOf(123.456)}; + // spotless:on + table.addRow(row1); table.addRow(row2); table.addRow(row3); Endpoint addr = Endpoint.parse("127.0.0.1:8081"); - Database.GreptimeResponse response = Database.GreptimeResponse.newBuilder() // - .setAffectedRows(Common.AffectedRows.newBuilder() // - .setValue(3)) // + Database.GreptimeResponse response = Database.GreptimeResponse.newBuilder() + .setAffectedRows(Common.AffectedRows.newBuilder().setValue(3)) .build(); - Mockito.when(this.routerClient.route()) // - .thenReturn(Util.completedCf(addr)); - Mockito.when(this.routerClient.invoke(Mockito.eq(addr), Mockito.any(), Mockito.any())) // + Mockito.when(this.routerClient.route()).thenReturn(Util.completedCf(addr)); + Mockito.when(this.routerClient.invoke(Mockito.eq(addr), Mockito.any(), Mockito.any())) .thenReturn(Util.completedCf(response)); Result res = this.writeClient.write(table).get(); diff --git a/ingester-protocol/src/test/java/io/greptime/WriteLimitTest.java b/ingester-protocol/src/test/java/io/greptime/WriteLimitTest.java index 791fe5f..274d7ac 100644 --- a/ingester-protocol/src/test/java/io/greptime/WriteLimitTest.java +++ b/ingester-protocol/src/test/java/io/greptime/WriteLimitTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime; import io.greptime.errors.LimitedException; @@ -22,16 +23,16 @@ import io.greptime.models.Result; import io.greptime.models.Table; import io.greptime.models.WriteOk; -import org.junit.Assert; -import org.junit.Test; import java.util.Collection; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; +import org.junit.Assert; +import org.junit.Test; /** - * @author jiachun.fjc + * */ public class WriteLimitTest { @@ -91,15 +92,16 @@ public void blockingWriteLimitTest() throws InterruptedException { @Test public void blockingTimeoutWriteLimitTest() throws ExecutionException, InterruptedException { int timeoutSecs = 2; - WriteLimiter limiter = new WriteClient.DefaultWriteLimiter(1, - new LimitedPolicy.BlockingTimeoutPolicy(timeoutSecs, TimeUnit.SECONDS)); + WriteLimiter limiter = new WriteClient.DefaultWriteLimiter( + 1, new LimitedPolicy.BlockingTimeoutPolicy(timeoutSecs, TimeUnit.SECONDS)); Collection
rows = TestUtil.testTable("test1", 1); // consume the permits limiter.acquireAndDo(rows, CompletableFuture::new); final long start = System.nanoTime(); - final Result ret = limiter.acquireAndDo(rows, this::emptyOk).get(); + final Result ret = + limiter.acquireAndDo(rows, this::emptyOk).get(); Assert.assertEquals(timeoutSecs, TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - start), 0.3); Assert.assertFalse(ret.isOk()); @@ -109,8 +111,8 @@ public void blockingTimeoutWriteLimitTest() throws ExecutionException, Interrupt @Test(expected = LimitedException.class) public void abortOnBlockingTimeoutWriteLimitTest() throws ExecutionException, InterruptedException { int timeoutSecs = 2; - WriteLimiter limiter = new WriteClient.DefaultWriteLimiter(1, - new LimitedPolicy.AbortOnBlockingTimeoutPolicy(timeoutSecs, TimeUnit.SECONDS)); + WriteLimiter limiter = new WriteClient.DefaultWriteLimiter( + 1, new LimitedPolicy.AbortOnBlockingTimeoutPolicy(timeoutSecs, TimeUnit.SECONDS)); Collection
rows = TestUtil.testTable("test1", 1); // consume the permits diff --git a/ingester-protocol/src/test/java/io/greptime/limit/InFlightLimiterTest.java b/ingester-protocol/src/test/java/io/greptime/limit/InFlightLimiterTest.java index edace9d..e31eb63 100644 --- a/ingester-protocol/src/test/java/io/greptime/limit/InFlightLimiterTest.java +++ b/ingester-protocol/src/test/java/io/greptime/limit/InFlightLimiterTest.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.limit; import org.junit.Assert; import org.junit.Test; /** - * @author jiachun.fjc + * */ public class InFlightLimiterTest { diff --git a/ingester-protocol/src/test/java/io/greptime/models/ErrTest.java b/ingester-protocol/src/test/java/io/greptime/models/ErrTest.java index 93d108d..d2bda56 100644 --- a/ingester-protocol/src/test/java/io/greptime/models/ErrTest.java +++ b/ingester-protocol/src/test/java/io/greptime/models/ErrTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.models; import io.greptime.common.Endpoint; @@ -20,7 +21,7 @@ import org.junit.Test; /** - * @author jiachun.fjc + * */ public class ErrTest { diff --git a/ingester-protocol/src/test/java/io/greptime/models/ResultTest.java b/ingester-protocol/src/test/java/io/greptime/models/ResultTest.java index a05020b..02db39f 100644 --- a/ingester-protocol/src/test/java/io/greptime/models/ResultTest.java +++ b/ingester-protocol/src/test/java/io/greptime/models/ResultTest.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.models; import org.junit.Assert; import org.junit.Test; /** - * @author jiachun.fjc + * */ public class ResultTest { diff --git a/ingester-protocol/src/test/java/io/greptime/models/TableSchemaTest.java b/ingester-protocol/src/test/java/io/greptime/models/TableSchemaTest.java index 97155df..ed50483 100644 --- a/ingester-protocol/src/test/java/io/greptime/models/TableSchemaTest.java +++ b/ingester-protocol/src/test/java/io/greptime/models/TableSchemaTest.java @@ -13,31 +13,32 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.models; import io.greptime.TestUtil; import io.greptime.v1.RowData; +import java.math.BigDecimal; import org.junit.Assert; import org.junit.Test; -import java.math.BigDecimal; /** - * @author jiachun.fjc + * */ public class TableSchemaTest { @Test public void testNonNull() { - TableSchema schema = TableSchema.newBuilder("test_table") // - .addTag("col1", DataType.String) // - .addTag("col2", DataType.String) // - .addField("col3", DataType.Int32) // - .addColumn("col4", SemanticType.Field, DataType.Decimal128, new DataType.DecimalTypeExtension(39, 9)) // + TableSchema schema = TableSchema.newBuilder("test_table") + .addTag("col1", DataType.String) + .addTag("col2", DataType.String) + .addField("col3", DataType.Int32) + .addColumn("col4", SemanticType.Field, DataType.Decimal128, new DataType.DecimalTypeExtension(39, 9)) .build(); Table.RowBasedTable table = (Table.RowBasedTable) Table.from(schema); - table.addRow("1", "11", 111, new BigDecimal("0.1")) // - .addRow("2", "22", 222, new BigDecimal("0.2")) // + table.addRow("1", "11", 111, new BigDecimal("0.1")) + .addRow("2", "22", 222, new BigDecimal("0.2")) .addRow("3", "33", 333, new BigDecimal("0.3")); Assert.assertEquals(3, table.rowCount()); @@ -45,26 +46,27 @@ public void testNonNull() { Assert.assertEquals(111, rawRows.getRows(0).getValues(2).getI32Value()); Assert.assertEquals(222, rawRows.getRows(1).getValues(2).getI32Value()); Assert.assertEquals(333, rawRows.getRows(2).getValues(2).getI32Value()); - Assert.assertEquals(new BigDecimal("0.100000000"), + Assert.assertEquals( + new BigDecimal("0.100000000"), TestUtil.getDecimal(rawRows.getRows(0).getValues(3).getDecimal128Value(), 9)); - Assert.assertEquals(new BigDecimal("0.200000000"), + Assert.assertEquals( + new BigDecimal("0.200000000"), TestUtil.getDecimal(rawRows.getRows(1).getValues(3).getDecimal128Value(), 9)); - Assert.assertEquals(new BigDecimal("0.300000000"), + Assert.assertEquals( + new BigDecimal("0.300000000"), TestUtil.getDecimal(rawRows.getRows(2).getValues(3).getDecimal128Value(), 9)); } @Test public void testSomeNull() { - TableSchema schema = TableSchema.newBuilder("test_table") // - .addTag("col1", DataType.String) // - .addTag("col2", DataType.String) // - .addField("col3", DataType.Int32) // + TableSchema schema = TableSchema.newBuilder("test_table") + .addTag("col1", DataType.String) + .addTag("col2", DataType.String) + .addField("col3", DataType.Int32) .build(); Table.RowBasedTable table = (Table.RowBasedTable) Table.from(schema); - table.addRow("1", "11", 111) // - .addRow("2", null, 222) // - .addRow("3", "33", null); + table.addRow("1", "11", 111).addRow("2", null, 222).addRow("3", "33", null); Assert.assertEquals(3, table.rowCount()); RowData.Rows rawRows = table.into(); @@ -74,12 +76,11 @@ public void testSomeNull() { Assert.assertFalse(rawRows.getRows(1).getValues(1).hasStringValue()); } - @Test public void testNotSupportTimestamp() { - TableSchema.Builder builder = TableSchema.newBuilder("test_table") // - .addTag("col1", DataType.String) // - .addTag("col2", DataType.String) // + TableSchema.Builder builder = TableSchema.newBuilder("test_table") + .addTag("col1", DataType.String) + .addTag("col2", DataType.String) .addField("col3", DataType.Int32); try { @@ -92,9 +93,9 @@ public void testNotSupportTimestamp() { @Test public void testNotSupportDecimalExtension() { - TableSchema.Builder builder = TableSchema.newBuilder("test_table") // - .addTag("col1", DataType.String) // - .addTag("col2", DataType.String) // + TableSchema.Builder builder = TableSchema.newBuilder("test_table") + .addTag("col1", DataType.String) + .addTag("col2", DataType.String) .addField("col3", DataType.Int32); try { diff --git a/ingester-protocol/src/test/java/io/greptime/models/ValueUtilTest.java b/ingester-protocol/src/test/java/io/greptime/models/ValueUtilTest.java index af11761..cc92426 100644 --- a/ingester-protocol/src/test/java/io/greptime/models/ValueUtilTest.java +++ b/ingester-protocol/src/test/java/io/greptime/models/ValueUtilTest.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.models; import io.greptime.TestUtil; import io.greptime.v1.Common; -import org.junit.Assert; -import org.junit.Test; import java.math.BigDecimal; import java.math.BigInteger; import java.time.Instant; @@ -26,9 +25,11 @@ import java.util.Calendar; import java.util.Random; import java.util.TimeZone; +import org.junit.Assert; +import org.junit.Test; /** - * @author jiachun.fjc + * */ public class ValueUtilTest { @@ -79,8 +80,8 @@ public void testGetIntervalMonthDayNanoValue() { ValueUtil.getIntervalMonthDayNanoValue(1); Assert.fail(); } catch (IllegalArgumentException e) { - Assert.assertEquals("Expected type: `IntervalMonthDayNano`, actual: class java.lang.Integer", - e.getMessage()); + Assert.assertEquals( + "Expected type: `IntervalMonthDayNano`, actual: class java.lang.Integer", e.getMessage()); } } @@ -89,12 +90,12 @@ public void testGetDecimal128Value() { final int precision = 38; final int scale = 9; - Common.DecimalTypeExtension decimalTypeExtension = Common.DecimalTypeExtension.newBuilder() // - .setPrecision(precision) // - .setScale(scale) // + Common.DecimalTypeExtension decimalTypeExtension = Common.DecimalTypeExtension.newBuilder() + .setPrecision(precision) + .setScale(scale) .build(); - Common.ColumnDataTypeExtension dataTypeExtension = Common.ColumnDataTypeExtension.newBuilder() // - .setDecimalType(decimalTypeExtension) // + Common.ColumnDataTypeExtension dataTypeExtension = Common.ColumnDataTypeExtension.newBuilder() + .setDecimalType(decimalTypeExtension) .build(); for (int i = 0; i < 1000; i++) { diff --git a/ingester-protocol/src/test/java/io/greptime/options/GreptimeOptionsTest.java b/ingester-protocol/src/test/java/io/greptime/options/GreptimeOptionsTest.java index d86d270..a5b10b8 100644 --- a/ingester-protocol/src/test/java/io/greptime/options/GreptimeOptionsTest.java +++ b/ingester-protocol/src/test/java/io/greptime/options/GreptimeOptionsTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.options; import io.greptime.Router; @@ -21,14 +22,14 @@ import io.greptime.models.AuthInfo; import io.greptime.rpc.RpcOptions; import io.greptime.rpc.TlsOptions; -import org.junit.Assert; -import org.junit.Test; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; +import org.junit.Assert; +import org.junit.Test; /** - * @author jiachun.fjc + * */ public class GreptimeOptionsTest { @@ -47,27 +48,30 @@ public void testAllOptions() { Router router = createTestRouter(); TlsOptions tlsOptions = new TlsOptions(); - GreptimeOptions opts = GreptimeOptions.newBuilder(endpoints, database) // - .asyncPool(asyncPool) // - .rpcOptions(rpcOptions) // - .tlsOptions(tlsOptions) // - .writeMaxRetries(writeMaxRetries) // - .maxInFlightWritePoints(maxInFlightWritePoints) // - .writeLimitedPolicy(limitedPolicy) // - .defaultStreamMaxWritePointsPerSecond(defaultStreamMaxWritePointsPerSecond) // - .routeTableRefreshPeriodSeconds(routeTableRefreshPeriodSeconds) // - .authInfo(authInfo) // - .router(router) // + GreptimeOptions opts = GreptimeOptions.newBuilder(endpoints, database) + .asyncPool(asyncPool) + .rpcOptions(rpcOptions) + .tlsOptions(tlsOptions) + .writeMaxRetries(writeMaxRetries) + .maxInFlightWritePoints(maxInFlightWritePoints) + .writeLimitedPolicy(limitedPolicy) + .defaultStreamMaxWritePointsPerSecond(defaultStreamMaxWritePointsPerSecond) + .routeTableRefreshPeriodSeconds(routeTableRefreshPeriodSeconds) + .authInfo(authInfo) + .router(router) .build(); Assert.assertEquals(database, opts.getDatabase()); - Assert.assertArrayEquals(endpoints, opts.getEndpoints().stream().map(Endpoint::toString).toArray()); + Assert.assertArrayEquals( + endpoints, opts.getEndpoints().stream().map(Endpoint::toString).toArray()); Assert.assertEquals(rpcOptions, opts.getRpcOptions()); Assert.assertEquals(tlsOptions, opts.getRpcOptions().getTlsOptions()); RouterOptions routerOptions = opts.getRouterOptions(); Assert.assertNotNull(routerOptions); - Assert.assertArrayEquals(endpoints, routerOptions.getEndpoints().stream().map(Endpoint::toString).toArray()); + Assert.assertArrayEquals( + endpoints, + routerOptions.getEndpoints().stream().map(Endpoint::toString).toArray()); Assert.assertEquals(router, routerOptions.getRouter()); Assert.assertEquals(routeTableRefreshPeriodSeconds, routerOptions.getRefreshPeriodSeconds()); @@ -77,7 +81,8 @@ public void testAllOptions() { Assert.assertEquals(writeMaxRetries, writeOptions.getMaxRetries()); Assert.assertEquals(maxInFlightWritePoints, writeOptions.getMaxInFlightWritePoints()); Assert.assertEquals(limitedPolicy, writeOptions.getLimitedPolicy()); - Assert.assertEquals(defaultStreamMaxWritePointsPerSecond, writeOptions.getDefaultStreamMaxWritePointsPerSecond()); + Assert.assertEquals( + defaultStreamMaxWritePointsPerSecond, writeOptions.getDefaultStreamMaxWritePointsPerSecond()); Assert.assertEquals(authInfo, writeOptions.getAuthInfo()); } diff --git a/ingester-rpc/pom.xml b/ingester-rpc/pom.xml index 13bbb1d..874adba 100644 --- a/ingester-rpc/pom.xml +++ b/ingester-rpc/pom.xml @@ -1,25 +1,35 @@ + 4.0.0 - greptimedb-ingester io.greptime + greptimedb-ingester 0.7.3 ingester-rpc - - 8 - 8 - UTF-8 - - ${project.groupId} ingester-common - diff --git a/ingester-rpc/src/main/java/io/greptime/rpc/Context.java b/ingester-rpc/src/main/java/io/greptime/rpc/Context.java index 7246750..b057e92 100644 --- a/ingester-rpc/src/main/java/io/greptime/rpc/Context.java +++ b/ingester-rpc/src/main/java/io/greptime/rpc/Context.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc; import io.greptime.common.Copiable; @@ -23,8 +24,6 @@ /** * Invoke context, it can pass some additional information to the * database server in the form of KV. - * - * @author jiachun.fjc */ @SuppressWarnings({"unchecked", "unused"}) public class Context implements Copiable { diff --git a/ingester-rpc/src/main/java/io/greptime/rpc/MethodDescriptor.java b/ingester-rpc/src/main/java/io/greptime/rpc/MethodDescriptor.java index 0d40f5b..3bb51cd 100644 --- a/ingester-rpc/src/main/java/io/greptime/rpc/MethodDescriptor.java +++ b/ingester-rpc/src/main/java/io/greptime/rpc/MethodDescriptor.java @@ -13,14 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc; import java.util.Objects; /** * Description of a remote method. - * - * @author jiachun.fjc */ public class MethodDescriptor { private final String name; @@ -72,11 +71,7 @@ public int hashCode() { @Override public String toString() { - return "MethodDescriptor{" + // - "name='" + name + '\'' + // - ", type=" + type + // - ", limitPercent=" + limitPercent + // - '}'; + return "MethodDescriptor{" + "name='" + name + '\'' + ", type=" + type + ", limitPercent=" + limitPercent + '}'; } public enum MethodType { diff --git a/ingester-rpc/src/main/java/io/greptime/rpc/Observer.java b/ingester-rpc/src/main/java/io/greptime/rpc/Observer.java index 2f527b5..bd73bff 100644 --- a/ingester-rpc/src/main/java/io/greptime/rpc/Observer.java +++ b/ingester-rpc/src/main/java/io/greptime/rpc/Observer.java @@ -13,14 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc; import java.util.concurrent.Executor; /** * Receives notifications from an observable stream of messages. - * - * @author jiachun.fjc */ public interface Observer { diff --git a/ingester-rpc/src/main/java/io/greptime/rpc/RpcClient.java b/ingester-rpc/src/main/java/io/greptime/rpc/RpcClient.java index 68af38f..d899183 100644 --- a/ingester-rpc/src/main/java/io/greptime/rpc/RpcClient.java +++ b/ingester-rpc/src/main/java/io/greptime/rpc/RpcClient.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc; import io.greptime.common.Display; @@ -21,8 +22,6 @@ /** * A common RPC client interface. - * - * @author jiachun.fjc */ public interface RpcClient extends Lifecycle, Display { @@ -80,11 +79,7 @@ interface ConnectionObserver { * @param the response message type */ @SuppressWarnings("unused") - default void invokeAsync( - Endpoint endpoint, - Req request, - Observer observer, - long timeoutMs) { + default void invokeAsync(Endpoint endpoint, Req request, Observer observer, long timeoutMs) { invokeAsync(endpoint, request, null, observer, timeoutMs); } @@ -99,12 +94,7 @@ default void invokeAsync( * @param the request message type * @param the response message type */ - void invokeAsync( - Endpoint endpoint, - Req request, - Context ctx, - Observer observer, - long timeoutMs); + void invokeAsync(Endpoint endpoint, Req request, Context ctx, Observer observer, long timeoutMs); /** * Executes a server-streaming call with a response {@link Observer}. @@ -118,11 +108,7 @@ void invokeAsync( * @param the request message type * @param the response message type */ - void invokeServerStreaming( - Endpoint endpoint, - Req request, - Context ctx, - Observer observer); + void invokeServerStreaming(Endpoint endpoint, Req request, Context ctx, Observer observer); /** * Executes a client-streaming call with a request {@link Observer} @@ -137,8 +123,5 @@ void invokeServerStreaming( * @return request {@link Observer}. */ Observer invokeClientStreaming( - Endpoint endpoint, - Req defaultReqIns, - Context ctx, - Observer respObserver); + Endpoint endpoint, Req defaultReqIns, Context ctx, Observer respObserver); } diff --git a/ingester-rpc/src/main/java/io/greptime/rpc/RpcFactory.java b/ingester-rpc/src/main/java/io/greptime/rpc/RpcFactory.java index 63ee335..6a9f1a4 100644 --- a/ingester-rpc/src/main/java/io/greptime/rpc/RpcFactory.java +++ b/ingester-rpc/src/main/java/io/greptime/rpc/RpcFactory.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc; /** * GreptimeDB's RPC service factory. - * - * @author jiachun.fjc */ @SuppressWarnings("unused") public interface RpcFactory { @@ -31,10 +30,7 @@ public interface RpcFactory { * @param defaultReqIns default request instance * @param defaultRespIns default response instance */ - void register(MethodDescriptor method, - Class reqCls, - Object defaultReqIns, - Object defaultRespIns); + void register(MethodDescriptor method, Class reqCls, Object defaultReqIns, Object defaultRespIns); /** * Creates a RPC client. diff --git a/ingester-rpc/src/main/java/io/greptime/rpc/RpcFactoryProvider.java b/ingester-rpc/src/main/java/io/greptime/rpc/RpcFactoryProvider.java index 929c508..1fc0eb5 100644 --- a/ingester-rpc/src/main/java/io/greptime/rpc/RpcFactoryProvider.java +++ b/ingester-rpc/src/main/java/io/greptime/rpc/RpcFactoryProvider.java @@ -13,21 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc; import io.greptime.common.util.ServiceLoader; /** * A factory to create {@link RpcClient} based on SPI. - * - * @author jiachun.fjc */ public class RpcFactoryProvider { /** * SPI RPC factory, default is GrpcFactory */ - private static final RpcFactory RPC_FACTORY = ServiceLoader.load(RpcFactory.class).first(); + private static final RpcFactory RPC_FACTORY = + ServiceLoader.load(RpcFactory.class).first(); /** * Gets the {@link RpcFactory} impl, base on SPI. diff --git a/ingester-rpc/src/main/java/io/greptime/rpc/RpcOptions.java b/ingester-rpc/src/main/java/io/greptime/rpc/RpcOptions.java index d1d92c1..9b63c5c 100644 --- a/ingester-rpc/src/main/java/io/greptime/rpc/RpcOptions.java +++ b/ingester-rpc/src/main/java/io/greptime/rpc/RpcOptions.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc; import io.greptime.common.Copiable; @@ -20,8 +21,6 @@ /** * RPC client options. - * - * @author jiachun.fjc */ @SuppressWarnings("unused") public class RpcOptions implements Copiable { @@ -267,25 +266,24 @@ public RpcOptions copy() { @Override public String toString() { - return "RpcOptions{" + // - "useRpcSharedPool=" + useRpcSharedPool + // - ", defaultRpcTimeout=" + defaultRpcTimeout + // - ", maxInboundMessageSize=" + maxInboundMessageSize + // - ", flowControlWindow=" + flowControlWindow + // - ", idleTimeoutSeconds=" + idleTimeoutSeconds + // - ", keepAliveTimeSeconds=" + keepAliveTimeSeconds + // - ", keepAliveTimeoutSeconds=" + keepAliveTimeoutSeconds + // - ", keepAliveWithoutCalls=" + keepAliveWithoutCalls + // - ", limitKind=" + limitKind + // - ", initialLimit=" + initialLimit + // - ", maxLimit=" + maxLimit + // - ", longRttWindow=" + longRttWindow + // - ", smoothing=" + smoothing + // - ", blockOnLimit=" + blockOnLimit + // - ", logOnLimitChange=" + logOnLimitChange + // - ", enableMetricInterceptor=" + enableMetricInterceptor + // - ", tlsOptions=" + tlsOptions + // - '}'; + return "RpcOptions{" + "useRpcSharedPool=" + + useRpcSharedPool + ", defaultRpcTimeout=" + + defaultRpcTimeout + ", maxInboundMessageSize=" + + maxInboundMessageSize + ", flowControlWindow=" + + flowControlWindow + ", idleTimeoutSeconds=" + + idleTimeoutSeconds + ", keepAliveTimeSeconds=" + + keepAliveTimeSeconds + ", keepAliveTimeoutSeconds=" + + keepAliveTimeoutSeconds + ", keepAliveWithoutCalls=" + + keepAliveWithoutCalls + ", limitKind=" + + limitKind + ", initialLimit=" + + initialLimit + ", maxLimit=" + + maxLimit + ", longRttWindow=" + + longRttWindow + ", smoothing=" + + smoothing + ", blockOnLimit=" + + blockOnLimit + ", logOnLimitChange=" + + logOnLimitChange + ", enableMetricInterceptor=" + + enableMetricInterceptor + ", tlsOptions=" + + tlsOptions + '}'; } public static RpcOptions newDefault() { diff --git a/ingester-rpc/src/main/java/io/greptime/rpc/TlsOptions.java b/ingester-rpc/src/main/java/io/greptime/rpc/TlsOptions.java index 3abc187..8f87913 100644 --- a/ingester-rpc/src/main/java/io/greptime/rpc/TlsOptions.java +++ b/ingester-rpc/src/main/java/io/greptime/rpc/TlsOptions.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc; import io.greptime.common.Copiable; @@ -21,8 +22,6 @@ /** * GreptimeDB secure connection options - * - * @author Ning Sun */ public class TlsOptions implements Copiable { @@ -80,11 +79,10 @@ public void setRootCerts(File rootCerts) { @Override public String toString() { - return "TlsOptions{" + // - "clientCertChain=" + clientCertChain + // - ", privateKey=" + privateKey + // - ", privateKeyPassword='" + getPrivateKeyPassword().map((v) -> "****") + '\'' + // - ", rootCerts=" + rootCerts + // - '}'; + return "TlsOptions{" + "clientCertChain=" + + clientCertChain + ", privateKey=" + + privateKey + ", privateKeyPassword='" + + getPrivateKeyPassword().map((v) -> "****") + '\'' + ", rootCerts=" + + rootCerts + '}'; } } diff --git a/ingester-rpc/src/main/java/io/greptime/rpc/errors/ConnectFailException.java b/ingester-rpc/src/main/java/io/greptime/rpc/errors/ConnectFailException.java index 03e67a2..5351228 100644 --- a/ingester-rpc/src/main/java/io/greptime/rpc/errors/ConnectFailException.java +++ b/ingester-rpc/src/main/java/io/greptime/rpc/errors/ConnectFailException.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc.errors; /** * Connect failed error. - * - * @author jiachun.fjc */ public class ConnectFailException extends RuntimeException { diff --git a/ingester-rpc/src/main/java/io/greptime/rpc/errors/OnlyErrorMessage.java b/ingester-rpc/src/main/java/io/greptime/rpc/errors/OnlyErrorMessage.java index 935604b..b15bc8f 100644 --- a/ingester-rpc/src/main/java/io/greptime/rpc/errors/OnlyErrorMessage.java +++ b/ingester-rpc/src/main/java/io/greptime/rpc/errors/OnlyErrorMessage.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.greptime.rpc.errors; /** * Takes some additional error message, no stack trace, can be added to an exists Exception. - * - * @author jiachun.fjc */ public class OnlyErrorMessage extends Exception { diff --git a/licenserc.toml b/licenserc.toml new file mode 100644 index 0000000..309f996 --- /dev/null +++ b/licenserc.toml @@ -0,0 +1,19 @@ +# Copyright 2023 Greptime Team +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +headerPath = "Apache-2.0.txt" + +[properties] +inceptionYear = 2023 +copyrightOwner = "Greptime Team" diff --git a/pom.xml b/pom.xml index 1e552d7..5158e56 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,21 @@ + 4.0.0 @@ -54,18 +71,31 @@ - 32.0.1-jre - 1.20 - 4.8.2 - 4.13.1 - 2.17.1 - ${user.dir} + 8 8 - 1.9.5 UTF-8 + + + 32.0.1-jre 3.21.12 1.7.36 + + + 1.9.5 + 1.20 + 4.8.2 + 4.13.1 + 2.17.1 + + + 3.8.0 + 1.6 + 2.9.1 + 3.0.1 + 1.6.8 + 2.41.0 + 2.43.0 @@ -110,7 +140,7 @@ ${slf4j.version} - + org.apache.logging.log4j log4j-api @@ -169,91 +199,66 @@ - org.apache.maven.plugins - maven-compiler-plugin - 3.8.0 + com.diffplug.spotless + spotless-maven-plugin + ${spotless-plugin.version} - ${maven.compiler.source} - ${maven.compiler.target} - ${project.build.sourceEncoding} - true - true - - - - - com.googlecode.maven-java-formatter-plugin - maven-java-formatter-plugin - 0.4 - - - - format - - - - - ${main.user.dir}/tools/codestyle/formatter.xml - ${project.build.sourceEncoding} - - **/v1/** - - - - - - com.github.ekryd.sortpom - sortpom-maven-plugin - 2.4.0 - - - sort-pom - compile - - sort - - - - - 4 - true - true - ${project.build.sourceEncoding} + + + + *.md + .gitignore + pom.xml + + + + + true + 4 + + + + + + + ${palantir-java-format.version} + + + + \#| + + + + + + true + 4 + + + + + + + false + true + 4 + + + - com.mycila - license-maven-plugin - 3.0 - - - generate-sources - - remove - format - - - + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} - true -
${main.user.dir}/tools/codestyle/HEADER
- - **/src/main/java/** - **/src/test/java/** - - - **/v1/** - - true - - SLASHSTAR_STYLE - + true + true
- release @@ -262,7 +267,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.8 + ${nexus-staging-maven-plugin.version} true ossrh @@ -273,14 +278,14 @@ org.apache.maven.plugins maven-gpg-plugin - 1.6 + ${maven-gpg-plugin.version} sign-artifacts - verify sign + verify --pinentry-mode @@ -293,7 +298,7 @@ org.apache.maven.plugins maven-source-plugin - 3.0.1 + ${maven-source-plugin.version} attach-sources @@ -306,14 +311,14 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.9.1 + ${maven-javadoc-plugin.version} attach-javadocs - package jar + package -Xdoclint:none diff --git a/tools/check_format.sh b/tools/check_format.sh deleted file mode 100644 index fa636f2..0000000 --- a/tools/check_format.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -# make sure git has no un commit files -if [ -n "$(git status --untracked-files=no --porcelain)" ]; then - echo "Please commit your change before run this shell, un commit files:" - git status --untracked-files=no --porcelain - exit -1 -fi diff --git a/tools/codestyle/HEADER b/tools/codestyle/HEADER deleted file mode 100644 index e3d20e6..0000000 --- a/tools/codestyle/HEADER +++ /dev/null @@ -1,13 +0,0 @@ -Copyright 2023 Greptime Team - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. \ No newline at end of file diff --git a/tools/codestyle/formatter.xml b/tools/codestyle/formatter.xml deleted file mode 100644 index dd74843..0000000 --- a/tools/codestyle/formatter.xml +++ /dev/null @@ -1,337 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file