Skip to content
Draft
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
74c5b70
transaction: Support file based transaction
pingyu Jun 9, 2026
5560ce5
fix build error
pingyu Jun 9, 2026
8db1362
fix CI errors
pingyu Jun 10, 2026
6c02671
Merge branch 'master' into txn-file-cse
pingyu Jul 6, 2026
f558577
address comments
pingyu Jul 6, 2026
44fa212
prepareTxnFileCommitTS
pingyu Jul 13, 2026
a209cbe
bo
pingyu Jul 14, 2026
d50071d
handle binlog
pingyu Jul 14, 2026
26bd55b
undetermined
pingyu Jul 14, 2026
70cee6e
resource group tag
pingyu Jul 15, 2026
b15c470
note for skip case
pingyu Jul 15, 2026
dd46c19
register metrics
pingyu Jul 15, 2026
06541e7
validate config
pingyu Jul 15, 2026
ace38d1
comment for GetMaxStartKey/GetMinEndKey
pingyu Jul 15, 2026
4f653f2
require -> assert
pingyu Jul 15, 2026
ad49ae2
Merge branch 'master' into txn-file-cse
pingyu Jul 15, 2026
c522a3e
Merge branch 'master' into txn-file-cse
pingyu Jul 28, 2026
707c2cf
fix CI
pingyu Jul 28, 2026
43e4d24
txn-file: Add integration tests
pingyu Aug 1, 2026
733133b
fix
pingyu Aug 1, 2026
9218e1e
address comment
pingyu Aug 1, 2026
8b878c4
always get resource group tag
pingyu Aug 6, 2026
b30dcc8
handle primary not first
pingyu Aug 6, 2026
83ca973
no pipeline txn
pingyu Aug 6, 2026
88763ff
handle shared lock
pingyu Aug 6, 2026
46861ab
add lock_test
pingyu Aug 6, 2026
d82de8f
cleanup ctx
pingyu Aug 6, 2026
ebab9a9
MaxTxnChunkSizeInParallel
pingyu Aug 6, 2026
fdca77b
resource control
pingyu Aug 6, 2026
b8b8131
skip valid config
pingyu Aug 6, 2026
0d12389
txn file split region
pingyu Aug 6, 2026
9b6b05c
no txn file for shared lock
pingyu Aug 7, 2026
f0a60e9
handle assertion level
pingyu Aug 7, 2026
ae6b452
Merge remote-tracking branch 'upstream/master' into txn-file-cse
pingyu Aug 7, 2026
acdd288
Merge branch 'txn-file-cse' into txn-file-it
pingyu Aug 7, 2026
f683df4
shared lock test
pingyu Aug 7, 2026
fd46635
txn file assertion
pingyu Aug 7, 2026
0bb1ee0
accouting error
pingyu Aug 7, 2026
8cf5a02
rollback key error
pingyu Aug 7, 2026
98432af
http close
pingyu Aug 7, 2026
1825891
discard value
pingyu Aug 7, 2026
4f577d4
Merge branch 'txn-file-cse' into txn-file-it
pingyu Aug 7, 2026
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
37 changes: 37 additions & 0 deletions config/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ type TiKVClient struct {

// RUV2 is the RU v2 TiKV-side weights used to calculate TiKV RU values from ExecDetailsV2.RuV2.
RUV2 RUV2TiKVConfig `toml:"ru-v2" json:"ru-v2"`

// TxnChunkWriterAddr is the address of the txn chunk writer for file-based txn.
TxnChunkWriterAddr string `toml:"txn-chunk-writer-addr" json:"txn-chunk-writer-addr"`
// TxnChunkWriterConcurrency is the concurrency to request the txn chunk writer for file-based txn.
TxnChunkWriterConcurrency uint `toml:"txn-chunk-writer-concurrency" json:"txn-chunk-writer-concurrency"`
// TxnChunkMaxSize is the maximum size of a txn chunk of file-based txn.
TxnChunkMaxSize uint64 `toml:"txn-chunk-max-size" json:"txn-chunk-max-size"`
// TxnFileMinMutationSize is the minimum size of mutations to use file-based txn.
TxnFileMinMutationSize uint64 `toml:"txn-file-min-mutation-size" json:"txn-file-min-mutation-size"`
// TxnFileRUDiscountRatio is the discount ratio of resource unit for file-based txn.
// Will be ignored if it's <= 0 or >= 1.
TxnFileRUDiscountRatio float64 `toml:"txn-file-ru-discount-ratio" json:"txn-file-ru-discount-ratio"`
// TxnFileRequestSourceWhitelist is the whitelist of request source types (RequestSource.RequestSourceType) that can use file-based txn.
// For internal requests only. External requests can always use file-based txn.
TxnFileRequestSourceWhitelist []string `toml:"txn-file-request-source-whitelist" json:"txn-file-request-source-whitelist"`
}

// RUV2TiKVConfig is the configuration for RU v2 TiKV-side weight calculation.
Expand Down Expand Up @@ -232,6 +247,12 @@ func DefaultTiKVClient() TiKVClient {
MaxConcurrencyRequestLimit: DefMaxConcurrencyRequestLimit,
EnableReplicaSelectorV2: true,
RUV2: DefaultRUV2TiKVConfig(),

TxnChunkWriterConcurrency: 4,
TxnChunkMaxSize: 128 * 1024 * 1024,
TxnFileMinMutationSize: 16 * 1024 * 1024,
TxnFileRUDiscountRatio: 0.125, // filed-based txn costs 1/8 RU of normal txn.
TxnFileRequestSourceWhitelist: []string{},
}
}

Expand All @@ -246,6 +267,22 @@ func (config *TiKVClient) Valid() error {
if config.GetGrpcKeepAliveTimeout() < time.Millisecond*50 {
return fmt.Errorf("grpc-keepalive-timeout should be at least 0.05, but got %f", config.GrpcKeepAliveTimeout)
}
return validateTxnFileConfig(config)
}

func validateTxnFileConfig(config *TiKVClient) error {
if config.TxnChunkMaxSize == 0 {
return fmt.Errorf("txn-chunk-max-size should be greater than 0")
}
if config.TxnChunkMaxSize > math.MaxInt {
return fmt.Errorf("txn-chunk-max-size should not exceed %d, but got %d", math.MaxInt, config.TxnChunkMaxSize)
}
if config.TxnChunkWriterConcurrency == 0 {
return fmt.Errorf("txn-chunk-writer-concurrency should be greater than 0")
}
if config.TxnChunkWriterConcurrency > math.MaxInt {
return fmt.Errorf("txn-chunk-writer-concurrency should not exceed %d, but got %d", math.MaxInt, config.TxnChunkWriterConcurrency)
}
return nil
}

Expand Down
69 changes: 69 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
package config

import (
"fmt"
"math"
"testing"
"time"

Expand Down Expand Up @@ -89,3 +91,70 @@ func TestValidateGRPCKeepAliveTimeout(t *testing.T) {
assert.NotNil(t, cfg.Valid())
assert.Equal(t, "grpc-keepalive-timeout should be at least 0.05, but got 0.040000", cfg.Valid().Error())
}

func TestValidateTxnFileConfig(t *testing.T) {
maxInt := uint64(math.MaxInt)
tests := []struct {
name string
configure func(*TiKVClient)
err string
}{
{
name: "default",
},
{
name: "zero chunk size",
configure: func(cfg *TiKVClient) {
cfg.TxnChunkMaxSize = 0
},
err: "txn-chunk-max-size should be greater than 0",
},
{
name: "maximum chunk size",
configure: func(cfg *TiKVClient) {
cfg.TxnChunkMaxSize = maxInt
},
},
{
name: "chunk size exceeds int",
configure: func(cfg *TiKVClient) {
cfg.TxnChunkMaxSize = maxInt + 1
},
err: fmt.Sprintf("txn-chunk-max-size should not exceed %d, but got %d", maxInt, maxInt+1),
},
{
name: "zero writer concurrency",
configure: func(cfg *TiKVClient) {
cfg.TxnChunkWriterConcurrency = 0
},
err: "txn-chunk-writer-concurrency should be greater than 0",
},
{
name: "maximum writer concurrency",
configure: func(cfg *TiKVClient) {
cfg.TxnChunkWriterConcurrency = uint(maxInt)
},
},
{
name: "writer concurrency exceeds int",
configure: func(cfg *TiKVClient) {
cfg.TxnChunkWriterConcurrency = uint(maxInt) + 1
},
err: fmt.Sprintf("txn-chunk-writer-concurrency should not exceed %d, but got %d", maxInt, uint(maxInt)+1),
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
cfg := DefaultTiKVClient()
if test.configure != nil {
test.configure(&cfg)
}
if test.err == "" {
assert.NoError(t, cfg.Valid())
return
}
assert.EqualError(t, cfg.Valid(), test.err)
})
}
}
Loading
Loading