Go client for TiKV
Go to file
tangenta 837c06ce52
apicodec: do not decode empty key for codec v2 (#1734)
Signed-off-by: tangenta <tangenta@126.com>
2025-08-15 09:26:06 +00:00
.github ci: add next-gen integration tests (#1661) 2025-06-17 13:13:51 +00:00
config pd client: add valid function for pd client config (#1699) 2025-07-07 06:56:24 +00:00
error Replace etcd safe point with txn safe point for read safety check (#1634) 2025-06-09 07:39:40 +00:00
examples region cache: do not invalidate the valid region cache when new region cache is loaded (#1698) 2025-07-07 06:38:42 +00:00
integration_tests txn: Set "CommitRequest.UseAsyncCommit" for async commit (#1730) 2025-08-01 15:12:33 +00:00
internal apicodec: do not decode empty key for codec v2 (#1734) 2025-08-15 09:26:06 +00:00
kv support redact key in logs (#1612) 2025-04-01 07:17:12 +00:00
metrics Make the txn safe point polling support falling back to old version of PD (#1727) 2025-07-30 08:44:49 +00:00
oracle enable ts validation for normal read (#1619) 2025-04-25 08:56:04 +00:00
rawkv Fix backoff lose info when forked (#1627) 2025-04-21 02:21:14 +00:00
testutils fix license (#267) 2021-08-15 01:48:01 +08:00
tikv Public UpdateTxnSafePointCache again to be used in tests in TiDB (#1732) 2025-08-15 02:59:42 +00:00
tikvrpc txnkv: prevent some actions from being interrupted by kill (#1665) 2025-06-27 07:41:09 +00:00
txnkv txn: Set "CommitRequest.UseAsyncCommit" for async commit (#1730) 2025-08-01 15:12:33 +00:00
util apicodec: do not decode empty key for codec v2 (#1734) 2025-08-15 09:26:06 +00:00
.gitignore rechange to retry when tikv disk full (#302) 2021-09-15 13:01:35 +08:00
.golangci.yml use slices.Sort to eliminate bounds check (#1128) 2024-01-23 11:24:15 +08:00
CONTRIBUTING.md add contributing (#94) 2021-06-19 04:01:45 +08:00
LICENSE
OWNERS OWNERS: Auto Sync OWNERS files from community membership (#1576) 2025-02-14 06:46:00 +00:00
README.md Update README.md (#571) 2022-08-25 11:10:36 +08:00
go.mod txn: Set "CommitRequest.UseAsyncCommit" for async commit (#1730) 2025-08-01 15:12:33 +00:00
go.sum txn: Set "CommitRequest.UseAsyncCommit" for async commit (#1730) 2025-08-01 15:12:33 +00:00

README.md

TiKV Go Client

TiKV Go Client provides support for interacting with the TiKV server in the form of a Go library.

Stability Active Go Reference

Unit Test Integration Test Compatibility Test

Package versions

There are 2 major versions of the client-go package.

  • v2 is the latest stable version. This version was extracted from pingcap/tidb and it includes new TiKV features like Follower Read, 1PC, Async Commit. The development of this version is on the master branch. The documentation for this version is below.

  • v1 is the previous stable version and is only maintained for bug fixes. You can read the documentation here.

Usage/Examples

  # valid versions be like @latest, @e5f932ae270887550b0cd221343dbd6b870b6c8f, @v2.0.0, @v2.0.1...
  go get github.com/tikv/client-go/v2@COMMIT_HASH_OR_TAG_VERSION

Explanation of related concepts and sample code can be found in the Client-Go Wiki. There are also executable examples in examples directory.

Contributing to client-go

Pull Requests and issues are welcomed. Please check CONTRIBUTING.md.

Developing

Running Tests

Note: All the following tests are included in the CI and you can submit a Pull Request directly to hand over the work.

To run unit tests, use following command

go test ./...

To run code linter, make sure golangci-lint is installed. Then use following command

golangci-lint run

integration_tests can run against a real TiKV cluster. Here is an example:

./pd-server &
sleep 5
./tikv-server &
sleep 10
cd integration_tests
go test --with-tikv

Test with TiDB

It is a common task to update client-go and then test it with TiDB.

If you only need to test locally, you can directly use the modified client-go on the same host by replacing:

go mod edit -replace=github.com/tikv/client-go/v2=/path/to/client-go

If you want to push your TiDB code to GitHub for running CI or for code review, you need to change the client-go used by TiDB to your developing branch using the following steps:

go get -d github.com/GITHUB_USERNAME/client-go/v2@DEV_BRANCH
# Output:
# go get: github.com/GITHUB_USERNAME/client-go/v2@none updating to
#         github.com/GITHUB_USERNAME/client-go/v2@v2.0.0-XXXXXXXXXXXXXX-XXXXXXXXXXXX: parsing go.mod:
#         module declares its path as: github.com/tikv/client-go/v2
#                 but was required as: github.com/GITHUB_USERNAME/client-go/v2
go mod edit -replace=github.com/tikv/client-go/v2=github.com/GITHUB_USERNAME/client-go/v2@v2.0.0-XXXXXXXXXXXXXX-XXXXXXXXXXXX
go mod download github.com/tikv/client-go/v2

Used By

client-go is used by the following projects:

  • TiDB: TiDB is an open source distributed HTAP database compatible with the MySQL protocol
  • BR: A command-line tool for distributed backup and restoration of the TiDB cluster data
  • TiCDC: Change data capture for TiDB
  • go-ycsb: A Go port of Yahoo! Cloud Serving Benchmark (YCSB)
  • JuiceFS: JuiceFS is a distributed POSIX file system built on top of Redis and S3
  • tcli: A CLI tool for TiKV, for human being :)

License

Apache License 2.0