-
Notifications
You must be signed in to change notification settings - Fork 101
backup: support explicitly set sst compression type #404
Changes from 6 commits
67d0793
3591bb1
5cdd6d0
3669199
28003a7
c02c5e8
02ef270
0b6bb3e
60a5bef
550b868
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 | ||||
---|---|---|---|---|---|---|
|
@@ -28,9 +28,10 @@ import ( | |||||
) | ||||||
|
||||||
const ( | ||||||
flagBackupTimeago = "timeago" | ||||||
flagBackupTS = "backupts" | ||||||
flagLastBackupTS = "lastbackupts" | ||||||
flagBackupTimeago = "timeago" | ||||||
flagBackupTS = "backupts" | ||||||
flagLastBackupTS = "lastbackupts" | ||||||
flagCompressionType = "compression-type" | ||||||
|
||||||
flagGCTTL = "gcttl" | ||||||
|
||||||
|
@@ -42,10 +43,11 @@ const ( | |||||
type BackupConfig struct { | ||||||
Config | ||||||
|
||||||
TimeAgo time.Duration `json:"time-ago" toml:"time-ago"` | ||||||
BackupTS uint64 `json:"backup-ts" toml:"backup-ts"` | ||||||
LastBackupTS uint64 `json:"last-backup-ts" toml:"last-backup-ts"` | ||||||
GCTTL int64 `json:"gc-ttl" toml:"gc-ttl"` | ||||||
TimeAgo time.Duration `json:"time-ago" toml:"time-ago"` | ||||||
BackupTS uint64 `json:"backup-ts" toml:"backup-ts"` | ||||||
LastBackupTS uint64 `json:"last-backup-ts" toml:"last-backup-ts"` | ||||||
GCTTL int64 `json:"gc-ttl" toml:"gc-ttl"` | ||||||
CompressionType kvproto.CompressionType `json:"compression-type" toml:"compression-type"` | ||||||
} | ||||||
|
||||||
// DefineBackupFlags defines common flags for the backup command. | ||||||
|
@@ -60,6 +62,7 @@ func DefineBackupFlags(flags *pflag.FlagSet) { | |||||
flags.String(flagBackupTS, "", "the backup ts support TSO or datetime,"+ | ||||||
" e.g. '400036290571534337', '2018-05-11 01:42:23'") | ||||||
flags.Int64(flagGCTTL, backup.DefaultBRGCSafePointTTL, "the TTL (in seconds) that PD holds for BR's GC safepoint") | ||||||
flags.String(flagCompressionType, "", "backup sst file compression algorithm, value can be one of 'lz4|zstd|snappy'") | ||||||
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. provide a default value?
Suggested change
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. the default value should be default, which means the compression type will be determined by tikv. In currently logic, tikv will choose the fastest algorithm and in most case it will be 'lz4'. 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. the default is called "unknown" though 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. e, so we should change the name in kv-proto to default? 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. We should provide a validate default value, "zstd" looks good to me. 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. Ok. Then I think we can set default to |
||||||
} | ||||||
|
||||||
// ParseFromFlags parses the backup-related flags from the flag set. | ||||||
|
@@ -90,6 +93,16 @@ func (cfg *BackupConfig) ParseFromFlags(flags *pflag.FlagSet) error { | |||||
} | ||||||
cfg.GCTTL = gcTTL | ||||||
|
||||||
compressionStr, err := flags.GetString(flagCompressionType) | ||||||
if err != nil { | ||||||
return errors.Trace(err) | ||||||
} | ||||||
compressionType, err := parseCompressionType(compressionStr) | ||||||
if err != nil { | ||||||
return errors.Trace(err) | ||||||
} | ||||||
cfg.CompressionType = compressionType | ||||||
|
||||||
if err = cfg.Config.ParseFromFlags(flags); err != nil { | ||||||
return errors.Trace(err) | ||||||
} | ||||||
|
@@ -140,10 +153,11 @@ func RunBackup(c context.Context, g glue.Glue, cmdName string, cfg *BackupConfig | |||||
isIncrementalBackup := cfg.LastBackupTS > 0 | ||||||
|
||||||
req := kvproto.BackupRequest{ | ||||||
StartVersion: cfg.LastBackupTS, | ||||||
EndVersion: backupTS, | ||||||
RateLimit: cfg.RateLimit, | ||||||
Concurrency: defaultBackupConcurrency, | ||||||
StartVersion: cfg.LastBackupTS, | ||||||
EndVersion: backupTS, | ||||||
RateLimit: cfg.RateLimit, | ||||||
Concurrency: defaultBackupConcurrency, | ||||||
CompressionType: cfg.CompressionType, | ||||||
} | ||||||
|
||||||
ranges, backupSchemas, err := backup.BuildBackupRangeAndSchema( | ||||||
|
@@ -295,3 +309,20 @@ func parseTSString(ts string) (uint64, error) { | |||||
} | ||||||
return variable.GoTimeToTS(t1), nil | ||||||
} | ||||||
|
||||||
func parseCompressionType(s string) (kvproto.CompressionType, error) { | ||||||
var ct kvproto.CompressionType | ||||||
switch s { | ||||||
case "lz4": | ||||||
ct = kvproto.CompressionType_LZ4 | ||||||
case "snappy": | ||||||
ct = kvproto.CompressionType_SNAPPY | ||||||
case "zstd": | ||||||
ct = kvproto.CompressionType_ZSTD | ||||||
case "": | ||||||
ct = kvproto.CompressionType_UNKNOWN | ||||||
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.
Suggested change
|
||||||
default: | ||||||
return kvproto.CompressionType_UNKNOWN, errors.Errorf("invalid compression type '%s'", s) | ||||||
} | ||||||
return ct, 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.