Skip to content

Commit

Permalink
use global variable instead of config (#458)
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Yu <jackysp@gmail.com>
  • Loading branch information
jackysp authored Mar 29, 2022
1 parent 8489c3e commit 6bf6951
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
4 changes: 0 additions & 4 deletions config/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ import (
const (
// DefStoreLivenessTimeout is the default value for store liveness timeout.
DefStoreLivenessTimeout = "1s"
// DefTxnCommitBatchSize recommends each RPC packet should be less than ~1MB
DefTxnCommitBatchSize = 16 * 1024
)

// TiKVClient is the config for tikv client.
Expand Down Expand Up @@ -86,7 +84,6 @@ type TiKVClient struct {
// TTLRefreshedTxnSize controls whether a transaction should update its TTL or not.
TTLRefreshedTxnSize int64 `toml:"ttl-refreshed-txn-size" json:"ttl-refreshed-txn-size"`
ResolveLockLiteThreshold uint64 `toml:"resolve-lock-lite-threshold" json:"resolve-lock-lite-threshold"`
TxnCommitBatchSize uint `toml:"txn-commit-batch-size" json:"txn-commit-batch-size"`
}

// AsyncCommit is the config for the async commit feature. The switch to enable it is a system variable.
Expand Down Expand Up @@ -155,7 +152,6 @@ func DefaultTiKVClient() TiKVClient {
},

ResolveLockLiteThreshold: 16,
TxnCommitBatchSize: DefTxnCommitBatchSize,
}
}

Expand Down
11 changes: 11 additions & 0 deletions kv/store_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ import (
// StoreLimit will update from config reload and global variable set.
var StoreLimit atomic.Int64

// DefTxnCommitBatchSize is the default value of TxnCommitBatchSize.
const DefTxnCommitBatchSize uint64 = 16 * 1024

// TxnCommitBatchSize controls the batch size of transaction commit related requests sent by client to TiKV,
// TiKV recommends each RPC packet should be less than ~1MB.
var TxnCommitBatchSize atomic.Uint64

func init() {
TxnCommitBatchSize.Store(DefTxnCommitBatchSize)
}

// ReplicaReadType is the type of replica to read data from
type ReplicaReadType byte

Expand Down
4 changes: 2 additions & 2 deletions txnkv/transaction/2pc.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ func txnLockTTL(startTime time.Time, txnSize int) uint64 {
// When writeSize is less than 256KB, the base ttl is defaultTTL (3s);
// When writeSize is 1MiB, 4MiB, or 10MiB, ttl is 6s, 12s, 20s correspondingly;
lockTTL := defaultLockTTL
if txnSize >= int(config.GetGlobalConfig().TiKVClient.TxnCommitBatchSize) {
if txnSize >= int(kv.TxnCommitBatchSize.Load()) {
sizeMiB := float64(txnSize) / bytesPerMiB
lockTTL = uint64(float64(ttlFactor) * math.Sqrt(sizeMiB))
if lockTTL < defaultLockTTL {
Expand Down Expand Up @@ -875,7 +875,7 @@ func (c *twoPhaseCommitter) doActionOnGroupMutations(bo *retry.Backoffer, action
batchBuilder := newBatched(c.primary())
for _, group := range groups {
batchBuilder.appendBatchMutationsBySize(group.region, group.mutations, sizeFunc,
int(config.GetGlobalConfig().TiKVClient.TxnCommitBatchSize))
int(kv.TxnCommitBatchSize.Load()))
}
firstIsPrimary := batchBuilder.setPrimary()

Expand Down
4 changes: 2 additions & 2 deletions txnkv/transaction/test_probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (
"sync/atomic"
"time"

"github.com/tikv/client-go/v2/config"
"github.com/tikv/client-go/v2/internal/locate"
"github.com/tikv/client-go/v2/internal/retry"
"github.com/tikv/client-go/v2/internal/unionstore"
"github.com/tikv/client-go/v2/kv"
"github.com/tikv/client-go/v2/tikvrpc"
"github.com/tikv/client-go/v2/txnkv/txnsnapshot"
)
Expand Down Expand Up @@ -330,7 +330,7 @@ type ConfigProbe struct{}

// GetTxnCommitBatchSize returns the batch size to commit txn.
func (c ConfigProbe) GetTxnCommitBatchSize() uint64 {
return uint64(config.GetGlobalConfig().TiKVClient.TxnCommitBatchSize)
return kv.TxnCommitBatchSize.Load()
}

// GetPessimisticLockMaxBackoff returns pessimisticLockMaxBackoff
Expand Down

0 comments on commit 6bf6951

Please # to comment.