Error When Operating TiKV Cluster with Java

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: Java操作tikv集群报错

| username: tikv-lu

Using tikv-client-java to operate the TiKV cluster, it initially works fine and can normally operate the TiKV cluster, but then suddenly it cannot connect, and the error is as follows:
Caused by: java.lang.IllegalArgumentException: null
at org.tikv.shade.com.google.common.base.Preconditions.checkArgument(Preconditions.java:127)
at org.tikv.common.codec.Codec$BytesCodec.readBytes(Codec.java:316)
at org.tikv.common.codec.Codec$BytesCodec.readBytes(Codec.java:283)
at org.tikv.common.region.TiRegion.decodeRegion(TiRegion.java:103)
at org.tikv.common.region.TiRegion.(TiRegion.java:65)
at org.tikv.common.PDClient.getRegionByKey(PDClient.java:250)
at org.tikv.common.region.RegionManager$RegionCache.getRegionByKey(RegionManager.java:278)
at org.tikv.common.region.RegionManager.getRegionStorePairByKey(RegionManager.java:149)
at org.tikv.common.region.RegionManager.getRegionStorePairByKey(RegionManager.java:144)
at org.tikv.common.region.RegionStoreClient$RegionStoreClientBuilder.build(RegionStoreClient.java:1310)
at org.tikv.common.region.RegionStoreClient$RegionStoreClientBuilder.build(RegionStoreClient.java:1305)
at org.tikv.raw.RawKVClient.get(RawKVClient.java:245)

| username: 我是咖啡哥 | Original post link

It’s too advanced, I haven’t tried it :grinning:

| username: redgame | Original post link

Ensure that the tikv-client-java version is compatible with the TiKV cluster version.

| username: 有猫万事足 | Original post link

Please provide the client-java version and the TiKV version information.

At least for now, the master branch on GitHub does not show the org.tikv.shade package. Moreover, the next line in the exception stack Codec.java:316

is directly a }.

Most likely, if you use the correct client version, the problem will be resolved. The solution suggested above is worth trying.

| username: ShawnYan | Original post link

Next time you ask a question, please include the versions of TiKV and the client Java, otherwise, with only partial error messages, it is difficult to make a reasonable judgment. Also, check the TiKV logs again.

| username: TiDBer_iCdTOZ1r | Original post link

Learned.

| username: tikv-lu | Original post link

TiKV cluster version v5.0.1, TiKV-client-java version 3.1.0. I started using Java to operate the cluster a month ago, and there were no issues initially. Suddenly, this happened yesterday.

| username: tikv-lu | Original post link

TiKV cluster version v5.0.1, tikv-client-java version 3.1.0. I started using Java to operate the cluster a month ago, and there were no issues initially. Suddenly, this happened yesterday.

| username: xfworld | Original post link

Are other operations normal?

| username: tikv-lu | Original post link

It doesn’t work now. Calling the get and put methods will both report this error.

| username: ShawnYan | Original post link

Is it a local testing environment? Check if there are enough resources, and also check the TiKV logs for any errors.

| username: tikv-lu | Original post link

There are only some warning messages in pd.log. I checked the server resources, and there are no issues.

| username: tikv-lu | Original post link

The log of tikv also only contains info information.

| username: ShawnYan | Original post link

“failed to get tidb schema version”

Has there been any change in the PD network?

| username: tikv-lu | Original post link

I pinged the PD server address, and it has always been like this.
1

| username: xfworld | Original post link

Then you need to check if the cluster is functioning properly…

It seems that the network and PD processing performance are insufficient…

| username: tikv-lu | Original post link

The cluster status is normal when using the command.

| username: ShawnYan | Original post link

Looking at the screenshot of your cluster information, the PD leader is on 87, not 80.

| username: tikv-lu | Original post link

How to solve this situation?

| username: xfworld | Original post link

The PD leader can be manually switched.