-
Notifications
You must be signed in to change notification settings - Fork 225
API V2
client-go has fully supported API V2 for both RawKV and TxnKV, however, it's not entirely GA yet. If you want to try the features like keyspace, you should enable API V2 for the whole TiKV cluster. This Wiki page will introduce the basic configuration to enable the API V2 in a TiKV cluster.
First, you might enable API V2 in TiKV with the following config:
[storage]
api-version = 2
enable-ttl = true
By default, there is a pre-defined keyspace called DEFAULT
with keyspace id: 0 in the newly created V2 cluster.
For example, you could create a V2 client with the following code:
// create a rawkv client
cli, err := rawkv.NewClientWithOpts(context.Background(), addrs, rawkv.WithAPIVersion(kvrpcpb.APIVersion_V2))
// using `cli` do some stuff
// or create a txnkv client
cli, err := txn.NewClient(addrs, txn.WithAPIVersion(kvrpcpb.APIVersion_V2))
This client will read/write from/to the data located in keyspace DEFAULT
, any other keyspace client could not access them.
If you want to access keyspaces other than DEFAULT
, there are two ways to achieve this:
- config pre-defined keyspaces in PD with the following config:
[keyspace]
pre-alloc = ["a", "b", "c"]
This config will create 3 keyspaces while the cluster bootstraps.
Then, you could create a client with the keyspace options:
// create a rawkv client
cli, err := rawkv.NewClientWithOpts(context.Background(), addrs, rawkv.WithAPIVersion(kvrpcpb.APIVersion_V2), rawkv.WithKeyspace("a"))
// using `cli` do some stuff
// or create a txnkv client
cli, err := txn.NewClient(addrs, txn.WithAPIVersion(kvrpcpb.APIVersion_V2), rawkv.WithKeyspace("a"))
- call PD's API manually
// with HTTPie
> http post http://127.0.0.1:2379/pd/api/v2/keyspaces name=<keyspace-name>
Feel free to help improving! Minor changes are warmly welcomed. Just simply click edit!
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Contents
- Client-Go Wiki
- Compatibility
- API V2
- Transactional API
- RawKV API
- Configurations
- Utilities