-
Notifications
You must be signed in to change notification settings - Fork 269
transaction: Support file based transaction #1998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
74c5b70
5560ce5
8db1362
6c02671
f558577
44fa212
a209cbe
d50071d
26bd55b
70cee6e
b15c470
dd46c19
06541e7
ace38d1
4f653f2
ad49ae2
c522a3e
707c2cf
8b878c4
b30dcc8
83ca973
88763ff
46861ab
d82de8f
ebab9a9
fdca77b
b8b8131
0d12389
9b6b05c
f0a60e9
ae6b452
fd46635
0bb1ee0
8cf5a02
98432af
1825891
77facf4
3c5576b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,8 @@ const ( | |
| DefGrpcInitialConnWindowSize = 1 << 27 // 128MiB | ||
| DefMaxConcurrencyRequestLimit = math.MaxInt64 | ||
| DefBatchPolicy = BatchPolicyStandard | ||
| // MaxTxnChunkSizeInParallel is the maximum total size of transaction chunks processed in parallel. | ||
| MaxTxnChunkSizeInParallel uint64 = 4 << 30 // 4GB | ||
| ) | ||
|
|
||
| const ( | ||
|
|
@@ -121,6 +123,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. | ||
|
|
@@ -232,6 +249,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{}, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -246,6 +269,29 @@ 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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Could txn-file validation be skipped while the feature is disabled?
An existing caller that constructs Would it make sense to validate these txn-file-only fields only when
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed by b8b8131 |
||
| } | ||
|
|
||
| func validateTxnFileConfig(config *TiKVClient) error { | ||
| if config.TxnChunkWriterAddr == "" { | ||
| // Skip validation when txn file is not enabled. | ||
| return nil | ||
| } | ||
| if config.TxnChunkMaxSize == 0 { | ||
| return fmt.Errorf("txn-chunk-max-size should be greater than 0") | ||
| } | ||
| if config.TxnChunkMaxSize > math.MaxInt { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Should reject chunk sizes that make the parallelism limit zero This validation still accepts TxnChunkMaxSize values greater than MaxTxnChunkSizeInParallel (4 GiB). For such a valid value, 4 GiB / TxnChunkMaxSize becomes 0 and NewRateLimit(0) deadlocks the multi-secondary path. Please reject values above the parallel budget and defensively clamp the calculated rate limit to at least 1.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed by ebab9a9 |
||
| return fmt.Errorf("txn-chunk-max-size should not exceed %d, but got %d", math.MaxInt, config.TxnChunkMaxSize) | ||
| } | ||
| if config.TxnChunkMaxSize > MaxTxnChunkSizeInParallel { | ||
| return fmt.Errorf("txn-chunk-max-size should not exceed %d, but got %d", MaxTxnChunkSizeInParallel, 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 | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should validate the new txn-file config values before accepting them, especially
TxnChunkMaxSize > 0? If this is set to0, the txn-file path can divide by zero when calculating chunk counts or parallelism, so rejecting or normalizing it inValid()would make the failure mode clearer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 06541e7.