Skip to content

Commit

Permalink
Set default max-parallel-downloads in new config (#2072)
Browse files Browse the repository at this point in the history
  • Loading branch information
kislaykishore authored Jun 27, 2024
1 parent ef2179c commit b8aa8dc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net/url"
"time"

"github.com/googlecloudplatform/gcsfuse/v2/internal/config"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -560,7 +561,7 @@ func BindFlags(flagSet *pflag.FlagSet) error {
return err
}

flagSet.IntP("max-parallel-downloads", "", -1, "Sets an uber limit of number of concurrent file download requests that are made across all files.")
flagSet.IntP("max-parallel-downloads", "", config.DefaultMaxParallelDownloads(), "Sets an uber limit of number of concurrent file download requests that are made across all files.")

err = viper.BindPFlag("file-cache.max-parallel-downloads", flagSet.Lookup("max-parallel-downloads"))
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ func TestValidConfig(t *testing.T) {
assert.Nil(t, cmd.Execute())
}

func TestDefaultMaxParallelDownloads(t *testing.T) {
var actual cfg.Config
cmd, err := NewRootCmd(func(c cfg.Config) error {
actual = c
return nil
})
require.Nil(t, err)
cmd.SetArgs([]string{"abc", "pqr"})

if assert.Nil(t, cmd.Execute()) {
assert.LessOrEqual(t, int64(16), actual.FileCache.MaxParallelDownloads)
}
}

func TestTooManyCobraArgs(t *testing.T) {
tests := []struct {
name string
Expand Down
1 change: 1 addition & 0 deletions tools/config-gen/config.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"time"
"net/url"

"github.com/googlecloudplatform/gcsfuse/v2/internal/config"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)
Expand Down
2 changes: 1 addition & 1 deletion tools/config-gen/params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@
config-path: "file-cache.max-parallel-downloads"
type: "int"
usage: "Sets an uber limit of number of concurrent file download requests that are made across all files."
default: "-1"
default: "config.DefaultMaxParallelDownloads()"

- flag-name: "download-chunk-size-mb"
config-path: "file-cache.download-chunk-size-mb"
Expand Down

0 comments on commit b8aa8dc

Please sign in to comment.