Add gradle build documents (#59)

This commit is contained in:
birdstorm 2019-04-10 14:17:05 +08:00 committed by Zhexuan Yang
parent 67112a9eca
commit daca5d23f2
7 changed files with 193 additions and 135 deletions

View File

@ -9,28 +9,59 @@ It is supposed to:
## How to build
### Gradle
Alternatively, you can build `tikv-client-java` with gradle.
The following command will build the project.
```
gradle init
gradle clean build -x test
```
To make a jar with dependencies
```
gradle clean fatJar -x test
```
The jar can be found in `./build/libs/`
### 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/`
### Bazel
Alternatively, you can use `bazel` for much faster build. When you try this approach, you should run `git submodule update --init --recursive` before you build project.
Making a uber jar:
```
make uber_jar
```
run Main class:
```
make run
```
run test cases:
```
make test
```
@ -39,8 +70,9 @@ this project is designed to hook with `pd` and `tikv` which you can find in `Pin
When you work with this project, you have to communicate with `pd` and `tikv`. Please run TiKV and PD in advance.
## Raw TiKV-Client in Java
Java Implementation of Raw TiKV-Client
## Component: Raw Ti-Client in Java
Java Implementation of Raw TiKV-Client to support RawKVClient commands.
Demo is avaliable in [KVRawClientTest](https://github.com/birdstorm/KVRawClientTest/)
@ -49,8 +81,16 @@ Demo is avaliable in [KVRawClientTest](https://github.com/birdstorm/KVRawClientT
mvn clean install -Dmaven.test.skip=true
```
### Use as maven dependency
After building, add following lines into your `pom.xml`
### 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
```xml
<dependency>
<groupId>org.tikv</groupId>
@ -60,68 +100,75 @@ After building, add following lines into your `pom.xml`
```
### Entrance
`com.pingcap.tikv.RawKVClient`
`org.tikv.raw.RawKVClient`
### Create a RawKVClient
```java
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 = session.createRawKVClient();
}
}
```
### API
```java
/**
* create a RawKVClient using specific pd addresses
*
* @param address pd addresses(comma seperated)
*/
static RawKVClient create(String address)
```
```java
/**
/**
* Put a raw key-value pair to TiKV
*
* @param key raw key
* @param value raw value
*/
void put(ByteString key, ByteString value)
void put(ByteString key, ByteString value)
```
```java
/**
/**
* 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)
ByteString get(ByteString key)
```
```java
/**
/**
* Scan raw key-value pairs from TiKV in range [startKey, endKey)
*
* @param startKey raw start key, inclusive
* @param endKey raw end key, exclusive
* @return list of key-value pairs in range
*/
List<Kvrpcpb.KvPair> scan(ByteString startKey, ByteString endKey)
List<Kvrpcpb.KvPair> scan(ByteString startKey, ByteString endKey)
```
```java
/**
/**
* Scan raw key-value pairs from TiKV in range [startKey, endKey)
*
* @param startKey raw start key, inclusive
* @param limit limit of key-value pairs
* @return list of key-value pairs in range
*/
List<Kvrpcpb.KvPair> scan(ByteString startKey, int limit)
List<Kvrpcpb.KvPair> scan(ByteString startKey, int limit)
```
```java
/**
/**
* Delete a raw key-value pair from TiKV if key exists
*
* @param key raw key to be deleted
*/
void delete(ByteString key)
void delete(ByteString key)
```

View File

@ -17,8 +17,8 @@ tasks.withType(JavaCompile) {
idea {
module {
// Marks the already(!) added srcDir as "generated"
generatedSourceDirs += file('target/generated-sources/protobuf/java')
generatedSourceDirs += file('target/generated-sources/protobuf/grpc-java')
generatedSourceDirs += file('target/generated-sources/main/java')
generatedSourceDirs += file('target/generated-sources/main/grpc-java')
}
}
@ -39,12 +39,12 @@ sourceSets {
}
java {
// include self written and generated code
srcDirs 'src/main/java', 'target/generated-sources/protobuf/java' , 'target/generated-sources/protobuf/grpc-java'
srcDirs 'src/main/java', 'target/generated-sources/main/java' , 'target/generated-sources/main/grpc-java'
}
}
test {
java {
srcDirs 'src/test/java', 'target/generated-sources/protobuf/java' , 'target/generated-sources/protobuf/grpc-java'
srcDirs 'src/test/java', 'target/generated-sources/main/java' , 'target/generated-sources/main/grpc-java'
}
}
// remove the test configuration - at least in your example you don't have a special test proto file
@ -92,6 +92,7 @@ protobuf {
clean {
delete protobuf.generatedFilesBaseDir
delete project.buildDir
}
repositories {
@ -151,5 +152,16 @@ task copyResources(type: Copy) {
}
}
//create a single Jar with all dependencies
task fatJar(type: Jar) {
manifest {
attributes 'Title': project.name,
'Version': version
}
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
compileJava.dependsOn copyResources
copyResources.dependsOn updateProtoModule

View File

@ -16,7 +16,6 @@
package org.tikv.common;
import com.google.common.collect.ImmutableList;
import java.io.Serializable;
import java.net.URI;
import java.util.ArrayList;

View File

@ -17,7 +17,6 @@ package org.tikv.common.util;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import java.net.URI;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

View File

@ -86,7 +86,7 @@ public class ConcreteBackOffer implements BackOffer {
BackOffFunction backOffFunction = null;
switch (funcType) {
case BoUpdateLeader:
//fix: reference from go client
// fix: reference from go client
backOffFunction = BackOffFunction.create(1, 10, BackOffStrategy.NoJitter);
break;
case BoTxnLockFast:
@ -96,7 +96,7 @@ public class ConcreteBackOffer implements BackOffer {
backOffFunction = BackOffFunction.create(2000, 10000, BackOffStrategy.EqualJitter);
break;
case BoRegionMiss:
//fix: reference from go client
// fix: reference from go client
// change base time to 2ms, because it may recover soon.
backOffFunction = BackOffFunction.create(2, 500, BackOffStrategy.NoJitter);
break;
@ -108,7 +108,7 @@ public class ConcreteBackOffer implements BackOffer {
backOffFunction = BackOffFunction.create(500, 3000, BackOffStrategy.EqualJitter);
break;
case BoTiKVRPC:
//fix: reference from go client
// fix: reference from go client
backOffFunction = BackOffFunction.create(100, 2000, BackOffStrategy.EqualJitter);
break;
case BoStoreNotMatch:

View File

@ -33,10 +33,10 @@ import org.tikv.common.key.Key;
import org.tikv.common.region.TiRegion;
import org.tikv.kvproto.Coprocessor;
import org.tikv.kvproto.Errorpb;
import org.tikv.kvproto.Errorpb.EpochNotMatch;
import org.tikv.kvproto.Errorpb.Error;
import org.tikv.kvproto.Errorpb.NotLeader;
import org.tikv.kvproto.Errorpb.ServerIsBusy;
import org.tikv.kvproto.Errorpb.EpochNotMatch;
import org.tikv.kvproto.Kvrpcpb;
import org.tikv.kvproto.Kvrpcpb.Context;
import org.tikv.kvproto.TikvGrpc;

View File

@ -89,7 +89,8 @@ public class PDClientTest {
session = TiSession.create(conf);
try (PDClient client = session.getPDClient()) {
client.switchLeader(ImmutableList.of("http://" + LOCAL_ADDR_IPV6 + ":" + (server.port + 2)));
assertEquals(client.getLeaderWrapper().getLeaderInfo(), LOCAL_ADDR_IPV6 + ":" + (server.port + 2));
assertEquals(
client.getLeaderWrapper().getLeaderInfo(), LOCAL_ADDR_IPV6 + ":" + (server.port + 2));
}
}