TiKV Java Client
Go to file
Ti Chi Robot 57ce457f4e
fix CI (#741) (#745)
2023-05-24 11:33:47 +08:00
.ci [to #526] Add codecov on Github Action (#524) (#533) 2022-02-21 15:32:54 +08:00
.github fix CI (#741) (#745) 2023-05-24 11:33:47 +08:00
config [to #526] Add codecov on Github Action (#524) (#533) 2022-02-21 15:32:54 +08:00
dev [to #421] add a python script to analyze slow log stats (#527) (#534) 2022-02-22 16:47:12 +08:00
metrics/grafana [to #556] metrics: attach cluster label to metrics (#558) (#579) 2022-03-29 21:17:12 +08:00
scripts [to #421] add a python script to analyze slow log stats (#527) (#534) 2022-02-22 16:47:12 +08:00
src [to #556] metrics: attach cluster label to metrics (#558) (#579) 2022-03-29 21:17:12 +08:00
.gitignore Fix gradle build (#50) 2019-02-27 14:57:55 +08:00
LICENSE init 2018-11-15 17:11:42 +08:00
Makefile add Makeflie to simplify build/test/format tasks (#346) (#355) 2021-12-09 22:03:09 +08:00
README.md [to #526] Add codecov on Github Action (#524) (#533) 2022-02-21 15:32:54 +08:00
pom.xml [close #567] upgrade jackson-databind to 2.13.2.2 to fix CVE-2020-36518 (#584) (#585) 2022-04-07 19:27:45 +08:00

README.md

Maven Central Slack codecov

TiKV JAVA Client

A Java client for TiDB/TiKV. It is supposed to:

  • Communicate via gRPC
  • Talk to Placement Driver searching for a region
  • Talk to TiKV for reading/writing data and the resulted data is encoded/decoded just like what we do in TiDB.
  • Talk to Coprocessor for calculation pushdown

How to build

Maven

The alternative way to build a usable jar for testing will be

mvn clean install -Dmaven.test.skip=true

The following command can install dependencies for you.

mvn package

The jar can be found in ./target/

Usage

This project is designed to hook with [pd](https://github.com/tikv/pd) and [tikv](https://github.com/tikv/tikv).

When you work with this project, you have to communicate with pd and tikv. Please run TiKV and PD in advance.

Component: Raw Ti-Client in Java

Java Implementation of Raw TiKV-Client to support RawKVClient commands.

Demo is avaliable in KVRawClientTest

Build

mvn clean install -Dmaven.test.skip=true

Add to dependency

Use jar for binary

Add your jar built with all dependencies into you project's library to use tikv-client-java as dependency

Use as maven dependency

After building, add following lines into your pom.xml if you are using Maven

<dependency>
	<groupId>org.tikv</groupId>
	<artifactId>tikv-client-java</artifactId>
	<version>3.1.0</version>
</dependency>

Entrance

org.tikv.raw.RawKVClient

Create a RawKVClient

import org.tikv.common.TiConfiguration;
import org.tikv.common.TiSession;
import org.tikv.raw.RawKVClient;

public class Main {
	public static void main() {
		// You MUST create a raw configuration if you are using RawKVClient.
		TiConfiguration conf = TiConfiguration.createRawDefault(YOUR_PD_ADDRESSES);
		TiSession session = TiSession.create(conf);
		RawKVClient client = session.createRawClient();
	}
}

Java Client Configuration Parameter

JVM Parameter

The following includes JVM related parameters.

tikv.pd.addresses

  • pd addresses, separated by comma
  • default: 127.0.0.1:2379

tikv.grpc.timeout_in_ms

  • timeout of grpc request
  • default: 600ms

tikv.grpc.scan_timeout_in_ms

  • timeout of scan/delete range grpc request
  • default: 20s

Metrics Parameter

tikv.metrics.enable

  • whether to enable metrics exporting
  • default: false

tikv.metrics.port

  • the metrics exporting http port
  • default: 3140

ThreadPool Parameter

The following includes ThreadPool related parameters, which can be passed in through JVM parameters.

tikv.batch_get_concurrency

  • the thread pool size of batchGet on client side
  • default: 20

tikv.batch_put_concurrency

  • the thread pool size of batchPut on client side
  • default: 20

tikv.batch_delete_concurrency

  • the thread pool size of batchDelete on client side
  • default: 20

tikv.batch_scan_concurrency

  • the thread pool size of batchScan on client side
  • default: 5

tikv.delete_range_concurrency

  • the thread pool size of deleteRange on client side
  • default: 20

tikv.rawkv.default_backoff_in_ms

  • RawKV default backoff in milliseconds
  • default: 20000 (20 seconds)

tikv.rawkv.read_timeout_in_ms

  • RawKV read timeout in milliseconds. This parameter controls the timeout of get getKeyTTL.
  • default: 2000 (2 seconds)

tikv.rawkv.write_timeout_in_ms

  • RawKV write timeout in milliseconds. This parameter controls the timeout of put putAtomic putIfAbsent delete deleteAtomic.
  • default: 2000 (2 seconds)

tikv.rawkv.batch_read_timeout_in_ms

  • RawKV batch read timeout in milliseconds. This parameter controls the timeout of batchGet.
  • default: 2000 (2 seconds)

tikv.rawkv.batch_write_timeout_in_ms

  • RawKV batch write timeout in milliseconds. This parameter controls the timeout of batchPut batchDelete batchDeleteAtomic.
  • default: 2000 (2 seconds)

tikv.rawkv.scan_timeout_in_ms

  • RawKV scan timeout in milliseconds. This parameter controls the timeout of batchScan scan scanPrefix.
  • default: 10000 (10 seconds)

tikv.rawkv.clean_timeout_in_ms

  • RawKV clean timeout in milliseconds. This parameter controls the timeout of deleteRange deletePrefix.
  • default: 600000 (10 minutes)

Metrics

Client Java supports exporting metrics to Prometheus using poll mode and viewing on Grafana. The following steps shows how to enable this function.

Step 1: Enable metrics exporting

  • set the config tikv.metrics.enable to true
  • call TiConfiguration.setMetricsEnable(true)

Step 2: Set the metrics port

  • set the config tikv.metrics.port
  • call TiConfiguration.setMetricsPort

Default port is 3140.

Step 3: Config Prometheus

Add the following config to conf/prometheus.yml and restart Prometheus.

- job_name: "tikv-client"
    honor_labels: true
    static_configs:
    - targets:
        - '127.0.0.1:3140'
        - '127.0.0.2:3140'
        - '127.0.0.3:3140'

Step 4: Config Grafana

Import the Client-Java-Summary dashboard config to Grafana.

License

Apache 2.0 license. See the LICENSE file for details.