TiKV Java Client
Go to file
birdstorm c6d7f0478c
fix scan exception when the start key is empty (lower_bound) (#199)
Signed-off-by: birdstorm <samuelwyf@hotmail.com>
2021-06-17 15:56:20 +08:00
.ci fix error on new ci (#185) 2021-06-04 19:00:29 +08:00
.github fix-bug-report template (#188) 2021-06-08 11:20:37 +08:00
config refactor follower read (#126) 2021-03-26 11:45:51 +08:00
dev Reform java client to combine with TiSpark's java client (#91) 2020-10-21 19:10:18 +08:00
scripts improve build scripts (#186) 2021-06-07 17:50:51 +08:00
src fix scan exception when the start key is empty (lower_bound) (#199) 2021-06-17 15:56:20 +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
README.md update readme (#197) 2021-06-16 15:31:05 +08:00
pom.xml Allow building on JDK9+ by getting rid of DirectByteBuffer dependency (#155) 2021-04-07 12:54:52 +08:00
shell.nix fix build issue in `nix-shell --pure` (#190) 2021-06-09 09:48:21 +08:00

README.md

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.0.1</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();
	}
}

API

/**
 * Put a raw key-value pair to TiKV
 *
 * @param key raw key
 * @param value raw value
 */
void put(ByteString key, ByteString value)
/**
 * Get a raw key-value pair from TiKV if key exists
 *
 * @param key raw key
 * @return a ByteString value if key exists, ByteString.EMPTY if key does not exist
 */
ByteString get(ByteString key)
/**
 * Scan raw key-value pairs from TiKV in range [startKey, endKey)
 *
 * @param startKey raw start key, inclusive
 * @param endKey raw end key, exclusive
 * @param limit limit of key-value pairs scanned, should be less than {@link #MAX_RAW_SCAN_LIMIT}
 * @return list of key-value pairs in range
 */
List<Kvrpcpb.KvPair> scan(ByteString startKey, ByteString endKey, int limit)
/**
 * Scan raw key-value pairs from TiKV in range [startKey, endKey)
 *
 * @param startKey raw start key, inclusive
 * @param limit limit of key-value pairs scanned, should be less than {@link #MAX_RAW_SCAN_LIMIT}
 * @return list of key-value pairs in range
 */
List<Kvrpcpb.KvPair> scan(ByteString startKey, int limit)
/**
 * Delete a raw key-value pair from TiKV if key exists
 *
 * @param key raw key to be deleted
 */
void delete(ByteString key)

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

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

License

Apache 2.0 license. See the LICENSE file for details.