diff --git a/cmd/asbackup/readme.md b/cmd/asbackup/readme.md index 11f31b47..3ae82503 100644 --- a/cmd/asbackup/readme.md +++ b/cmd/asbackup/readme.md @@ -67,8 +67,8 @@ Backup Flags: -L, --records-per-second int Limit total returned records per second (rps). Do not apply rps limit if records-per-second is zero. --max-retries int Maximum number of retries before aborting the current transaction. (default 5) - --total-timeout int Total socket timeout in milliseconds. 0 - no timeout. - --socket-timeout int Socket timeout in milliseconds. If this value is 0, its set to total-timeout. If both are 0, + --total-timeout int Total transaction timeout in milliseconds. 0 - no timeout. + --socket-timeout int Socket timeout in milliseconds. If this value is 0, it's set to total-timeout. If both are 0, there is no socket idle time limit (default 10000) -N, --nice int The limits for read/write storage bandwidth in MiB/s -r, --remove-files Remove existing backup file (-o) or files (-d). @@ -76,7 +76,7 @@ Backup Flags: -o, --output-file string Backup to a single backup file. Use - for stdout. Required, unless -d or -e is used. -q, --output-file-prefix string When using directory parameter, prepend a prefix to the names of the generated files. -F, --file-limit int Rotate backup files, when their size crosses the given - value (in bytes) Only used when backing up to a Directory. + value (in bytes) Only used when backing up to a Directory. (default 262144000) -x, --no-bins Do not include bin data in the backup. Use this flag for data sampling or troubleshooting. On restore all records, that don't contain bin data will be skipped. --no-ttl-only Only include records that have no ttl set (persistent records). diff --git a/cmd/asrestore/readme.md b/cmd/asrestore/readme.md index 41028590..305cb46f 100644 --- a/cmd/asrestore/readme.md +++ b/cmd/asrestore/readme.md @@ -59,12 +59,12 @@ Restore Flags: -R, --no-records Don't restore any records. -I, --no-indexes Don't restore any secondary indexes. --no-udfs Don't restore any UDFs. - -w, --parallel int The number of restore threads. (default 1) + -w, --parallel int The number of restore threads. (default - the number of available CPUs) -L, --records-per-second int Limit total returned records per second (rps). Do not apply rps limit if records-per-second is zero. --max-retries int Maximum number of retries before aborting the current transaction. (default 5) - --total-timeout int Total socket timeout in milliseconds. 0 - no timeout. - --socket-timeout int Socket timeout in milliseconds. If this value is 0, its set to total-timeout. If both are 0, + --total-timeout int Total transaction timeout in milliseconds. 0 - no timeout. (default 10000) + --socket-timeout int Socket timeout in milliseconds. If this value is 0, it's set to total-timeout. If both are 0, there is no socket idle time limit (default 10000) -N, --nice int The limits for read/write storage bandwidth in MiB/s -i, --input-file string Restore from a single backup file. Use - for stdin. @@ -95,7 +95,7 @@ Restore Flags: Default is 128 with batch writes enabled, or 16 without batch writes. (default 128) --extra-ttl int For records with expirable void-times, add N seconds of extra-ttl to the recorded void-time. - -T, --timeout int Set the timeout (ms) for commands. (default 10000) + -T, --timeout int Set the timeout (ms) for info commands. (default 10000) --retry-base-timeout int Set the initial delay between retry attempts in milliseconds (default 1000) --retry-multiplier float retry-multiplier is used to increase the delay between subsequent retry attempts. The actual delay is calculated as: retry-base-timeout * (retry-multiplier ^ attemptNumber) (default 1) diff --git a/cmd/internal/app/asbackup.go b/cmd/internal/app/asbackup.go index ee0de2cd..ac1caf36 100644 --- a/cmd/internal/app/asbackup.go +++ b/cmd/internal/app/asbackup.go @@ -30,7 +30,7 @@ type ASBackup struct { backupClient *backup.Client backupConfig *backup.BackupConfig writer backup.Writer - // reader is used to read state file. + // reader is used to read a state file. reader backup.StreamingReader // Additional params. isEstimate bool diff --git a/cmd/internal/app/reports.go b/cmd/internal/app/reports.go index 6eb32744..04089f6a 100644 --- a/cmd/internal/app/reports.go +++ b/cmd/internal/app/reports.go @@ -48,7 +48,7 @@ func printRestoreReport(stats *bModels.RestoreStats) { fmt.Printf("Expired Records: %d\n", stats.GetRecordsExpired()) fmt.Printf("Skipped Records: %d\n", stats.GetRecordsSkipped()) fmt.Printf("Ignored Records: %d\n", stats.GetRecordsIgnored()) - fmt.Printf("Freasher Records: %d\n", stats.GetRecordsFresher()) + fmt.Printf("Fresher Records: %d\n", stats.GetRecordsFresher()) fmt.Printf("Existed Records: %d\n", stats.GetRecordsExisted()) fmt.Printf("Inserted Records: %d\n", stats.GetRecordsInserted()) fmt.Printf("Total Bytes Read: %d\n", stats.GetTotalBytesRead()) diff --git a/cmd/internal/flags/backup.go b/cmd/internal/flags/backup.go index a293bc2e..3c9da880 100644 --- a/cmd/internal/flags/backup.go +++ b/cmd/internal/flags/backup.go @@ -44,9 +44,9 @@ func (f *Backup) NewFlagSet() *pflag.FlagSet { "When using directory parameter, prepend a prefix to the names of the generated files.") flagSet.Int64VarP(&f.FileLimit, "file-limit", "F", - 0, + 262144000, // 250 MB "Rotate backup files, when their size crosses the given\n"+ - "value (in bytes) Only used when backing up to a Directory.") + "value (in bytes) Only used when backing up to a Directory. 0 - no limit.") flagSet.BoolVarP(&f.NoBins, "no-bins", "x", false, "Do not include bin data in the backup. Use this flag for data sampling or troubleshooting.\n"+ diff --git a/cmd/internal/flags/backup_test.go b/cmd/internal/flags/backup_test.go index 089c39f8..1dff9bcc 100644 --- a/cmd/internal/flags/backup_test.go +++ b/cmd/internal/flags/backup_test.go @@ -80,7 +80,7 @@ func TestBackup_NewFlagSet_DefaultValues(t *testing.T) { result := backup.GetBackup() assert.Equal(t, "", result.OutputFile, "The default value for output-file should be an empty string") - assert.Equal(t, int64(0), result.FileLimit, "The default value for file-limit should be 0") + assert.Equal(t, int64(262144000), result.FileLimit, "The default value for file-limit should be 0") assert.Equal(t, "", result.AfterDigest, "The default value for after-digest should be an empty string") assert.Equal(t, "", result.ModifiedBefore, "The default value for modified-before should be an empty string") assert.Equal(t, "", result.ModifiedAfter, "The default value for modified-after should be an empty string") diff --git a/cmd/internal/flags/common.go b/cmd/internal/flags/common.go index 04dbc7db..0fd039b2 100644 --- a/cmd/internal/flags/common.go +++ b/cmd/internal/flags/common.go @@ -15,6 +15,8 @@ package flags import ( + "runtime" + "github.com/aerospike/backup-go/cmd/internal/models" "github.com/spf13/pflag" ) @@ -54,6 +56,9 @@ const ( "filter cannot be parallelized individually, so you may only achieve as much parallelism as there are\n" + "partition filters." descParallelRestore = "The number of restore threads." + + defaultTotalTimeoutBackup = 0 + defaultTotalTimeoutRestore = 10000 ) type Common struct { @@ -69,7 +74,11 @@ func NewCommon(operation int) *Common { func (f *Common) NewFlagSet() *pflag.FlagSet { flagSet := &pflag.FlagSet{} - var descNamespace, descSetList, descBinList, descNoRecords, descNoIndexes, descNoUDFs, descParallel string + var ( + descNamespace, descSetList, descBinList, descNoRecords, descNoIndexes, descNoUDFs, descParallel string + defaultTotalTimeout int64 + defaultParallel int + ) switch f.operation { case OperationBackup: @@ -80,6 +89,8 @@ func (f *Common) NewFlagSet() *pflag.FlagSet { descNoIndexes = descNoIndexesBackup descNoUDFs = descNoUDFsBackup descParallel = descParallelBackup + defaultTotalTimeout = defaultTotalTimeoutBackup + defaultParallel = 1 case OperationRestore: descNamespace = descNamespaceRestore descSetList = descSetListRestore @@ -88,6 +99,8 @@ func (f *Common) NewFlagSet() *pflag.FlagSet { descNoIndexes = descNoIndexesRestore descNoUDFs = descNoUDFsRestore descParallel = descParallelRestore + defaultTotalTimeout = defaultTotalTimeoutRestore + defaultParallel = runtime.NumCPU() } flagSet.StringVarP(&f.Directory, "directory", "d", @@ -112,7 +125,7 @@ func (f *Common) NewFlagSet() *pflag.FlagSet { false, descNoUDFs) flagSet.IntVarP(&f.Parallel, "parallel", "w", - 1, + defaultParallel, descParallel) flagSet.IntVarP(&f.RecordsPerSecond, "records-per-second", "L", 0, @@ -122,8 +135,8 @@ func (f *Common) NewFlagSet() *pflag.FlagSet { 5, "Maximum number of retries before aborting the current transaction.") flagSet.Int64Var(&f.TotalTimeout, "total-timeout", - 0, - "Total socket timeout in milliseconds. 0 - no timeout.") + defaultTotalTimeout, + "Total transaction timeout in milliseconds. 0 - no timeout.") flagSet.Int64Var(&f.SocketTimeout, "socket-timeout", 10000, "Socket timeout in milliseconds. If this value is 0, its set to total-timeout. If both are 0,\n"+ diff --git a/cmd/internal/flags/common_test.go b/cmd/internal/flags/common_test.go index 876c9811..09fe53f2 100644 --- a/cmd/internal/flags/common_test.go +++ b/cmd/internal/flags/common_test.go @@ -15,6 +15,7 @@ package flags import ( + "runtime" "testing" "github.com/stretchr/testify/assert" @@ -77,11 +78,11 @@ func TestCommon_NewFlagSet_DefaultValues(t *testing.T) { assert.Equal(t, "", result.SetList, "The default value for set-list should be nil") assert.Equal(t, 0, result.RecordsPerSecond, "The default value for records-per-second should be 0") assert.Equal(t, "", result.BinList, "The default value for bin-list should be nil") - assert.Equal(t, 1, result.Parallel, "The default value for parallel should be 1") + assert.Equal(t, runtime.NumCPU(), result.Parallel, "The default value for parallel should be 1") assert.False(t, result.NoRecords, "The default value for no-records should be false") assert.False(t, result.NoIndexes, "The default value for no-indexes should be false") assert.False(t, result.NoUDFs, "The default value for no-udfs should be false") assert.Equal(t, 5, result.MaxRetries, "The default value for max-retries should be 5") - assert.Equal(t, int64(0), result.TotalTimeout, "The default value for total-timeout should be 0") + assert.Equal(t, int64(10000), result.TotalTimeout, "The default value for total-timeout should be 0") assert.Equal(t, int64(10000), result.SocketTimeout, "The default value for socket-timeout should be 10000") } diff --git a/cmd/internal/flags/restore.go b/cmd/internal/flags/restore.go index 95cbd641..347cea34 100644 --- a/cmd/internal/flags/restore.go +++ b/cmd/internal/flags/restore.go @@ -74,7 +74,7 @@ func (f *Restore) NewFlagSet() *pflag.FlagSet { flagSet.Int64VarP(&f.TimeOut, "timeout", "T", 10000, - "Set the timeout (ms) for commands.") + "Set the timeout (ms) for info commands.") flagSet.Int64Var(&f.RetryBaseTimeout, "retry-base-timeout", 1000, "Set the initial delay between retry attempts in milliseconds") diff --git a/internal/asinfo/info_client.go b/internal/asinfo/info_client.go index 7af5df33..017171a2 100644 --- a/internal/asinfo/info_client.go +++ b/internal/asinfo/info_client.go @@ -619,7 +619,7 @@ func parseInfoKVPair(pair, kvSep string) (key, val string, err error) { return "", "", fmt.Errorf("invalid key-value pair: %s", pair) } - // make keys case insensitive + // make keys case-insensitive // to help with different version compatibility key = strings.ToLower(kv[0]) val = kv[1] diff --git a/io/encoding/asb/decode.go b/io/encoding/asb/decode.go index ef76db6d..ab990698 100644 --- a/io/encoding/asb/decode.go +++ b/io/encoding/asb/decode.go @@ -319,7 +319,7 @@ func (r *Decoder) readGlobals() (any, error) { } // readSindex is used to read secondary index lines in the global section of the asb file. -// readSindex expects that r has been advanced past the secondary index global line markter '* i' +// readSindex expects that r has been advanced past the secondary index global line marker '* i' func (r *Decoder) readSIndex() (*models.SIndex, error) { var res models.SIndex diff --git a/io/sized/writer.go b/io/sized/writer.go index 0ec7e27c..9c9e28d8 100644 --- a/io/sized/writer.go +++ b/io/sized/writer.go @@ -34,7 +34,7 @@ type Writer struct { saveCommandChan chan int } -// NewWriter creates a new Writer writer with a size limit. +// NewWriter creates a new Writer with a size limit. // limit must be greater than 0. func NewWriter(ctx context.Context, n int, saveCommandChan chan int, limit int64, open func(context.Context) (io.WriteCloser, error)) (*Writer, error) {