forked from pingcap/tidb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is an automated cherry-pick of pingcap#52127
Signed-off-by: ti-chi-bot <[email protected]>
- Loading branch information
1 parent
3c02c2a
commit b9b1a77
Showing
9 changed files
with
340 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright 2024 PingCAP, Inc. Licensed under Apache-2.0. | ||
package config | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/docker/go-units" | ||
) | ||
|
||
type ConfigTerm[T uint | uint64] struct { | ||
Value T | ||
Modified bool | ||
} | ||
|
||
type KVConfig struct { | ||
ImportGoroutines ConfigTerm[uint] | ||
MergeRegionSize ConfigTerm[uint64] | ||
MergeRegionKeyCount ConfigTerm[uint64] | ||
} | ||
|
||
func ParseImportThreadsFromConfig(resp []byte) (uint, error) { | ||
type importer struct { | ||
Threads uint `json:"num-threads"` | ||
} | ||
|
||
type config struct { | ||
Import importer `json:"import"` | ||
} | ||
var c config | ||
e := json.Unmarshal(resp, &c) | ||
if e != nil { | ||
return 0, e | ||
} | ||
|
||
return c.Import.Threads, nil | ||
} | ||
|
||
func ParseMergeRegionSizeFromConfig(resp []byte) (uint64, uint64, error) { | ||
type coprocessor struct { | ||
RegionSplitSize string `json:"region-split-size"` | ||
RegionSplitKeys uint64 `json:"region-split-keys"` | ||
} | ||
|
||
type config struct { | ||
Cop coprocessor `json:"coprocessor"` | ||
} | ||
var c config | ||
e := json.Unmarshal(resp, &c) | ||
if e != nil { | ||
return 0, 0, e | ||
} | ||
rs, e := units.RAMInBytes(c.Cop.RegionSplitSize) | ||
if e != nil { | ||
return 0, 0, e | ||
} | ||
urs := uint64(rs) | ||
return urs, c.Cop.RegionSplitKeys, nil | ||
} | ||
|
||
func ParseLogBackupEnableFromConfig(resp []byte) (bool, error) { | ||
type logbackup struct { | ||
Enable bool `json:"enable"` | ||
} | ||
|
||
type config struct { | ||
LogBackup logbackup `json:"log-backup"` | ||
} | ||
var c config | ||
e := json.Unmarshal(resp, &c) | ||
if e != nil { | ||
return false, e | ||
} | ||
return c.LogBackup.Enable, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.