Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions pkg/meta/tkv_tikv.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ import (
"github.com/tikv/client-go/v2/tikv"
"github.com/tikv/client-go/v2/txnkv"
"github.com/tikv/client-go/v2/txnkv/txnutil"
"github.com/tikv/client-go/v2/util"
"github.com/tikv/pd/client/opt"
"go.uber.org/zap"
)

func init() {
Register("tikv", newKVMeta)
drivers["tikv"] = newTikvClient

}

func newTikvClient(addr string) (tkvClient, error) {
Expand Down Expand Up @@ -86,8 +86,8 @@ func newTikvClient(addr string) (tkvClient, error) {
dur = time.Hour
}
interval = dur
logger.Infof("TiKV gc interval is set to %s", interval)
}
logger.Infof("TiKV gc interval is set to %s", interval)

client, err := txnkv.NewClient(strings.Split(tUrl.Host, ","))
if err != nil {
Expand Down Expand Up @@ -115,7 +115,7 @@ func newTikvClient(addr string) (tkvClient, error) {
}

prefix := strings.TrimLeft(tUrl.Path, "/")
return withPrefix(&tikvClient{client: client.KVStore, gcInterval: interval, changeLogShards: tiKVChangeLogShards()}, append([]byte(prefix), 0xFD)), nil
return withPrefix(&tikvClient{client: client.KVStore, gcInterval: interval, changeLogShards: tiKVChangeLogShards(), volume: prefix}, append([]byte(prefix), 0xFD)), nil
}

type tikvTxn struct {
Expand Down Expand Up @@ -310,6 +310,7 @@ type tikvClient struct {
client *tikv.KVStore
gcInterval time.Duration
changeLogShards int
volume string
}

func (c *tikvClient) name() string {
Expand Down Expand Up @@ -337,6 +338,7 @@ func (c *tikvClient) simpleTxn(ctx context.Context, f func(*kvTxn) error, retry
if err != nil {
return errors.Wrap(err, "failed to begin transaction")
}
tx.SetRequestSourceType(c.volume)
defer func() {
if r := recover(); r != nil {
if e, ok := r.(error); ok {
Expand Down Expand Up @@ -365,6 +367,7 @@ func (c *tikvClient) txn(ctx context.Context, f func(*kvTxn) error, retry int) (
if err != nil {
return err
}
tx.SetRequestSourceType(c.volume)
defer func() {
if r := recover(); r != nil {
fe, ok := r.(error)
Expand Down Expand Up @@ -396,6 +399,7 @@ OUT:
return err
}
snap := c.client.GetSnapshot(ts)
snap.SetRequestSourceType(c.volume)
snap.SetScanBatchSize(10240)
snap.SetNotFillCache(true)
snap.SetPriority(txnutil.PriorityLow)
Expand Down Expand Up @@ -442,7 +446,9 @@ func (c *tikvClient) gc() {
return
}

safePoint, err := c.client.GC(context.Background(), oracle.GoTimeToTS(oracle.GetTimeFromTS(currentTs).Add(-c.gcInterval)))
// Set request source to `internal_gc` instead of the default `unknown`.
ctx := util.WithInternalSourceType(context.Background(), util.InternalTxnGC)
safePoint, err := c.client.GC(ctx, oracle.GoTimeToTS(oracle.GetTimeFromTS(currentTs).Add(-c.gcInterval)))
if err == nil {
logger.Debugf("TiKV GC returns new safe point: %d (%s)", safePoint, oracle.GetTimeFromTS(safePoint))
} else {
Expand Down
Loading