Skip to content

Commit

Permalink
Merge pull request #2070 from GoogleCloudPlatform/master
Browse files Browse the repository at this point in the history
Merge master into CLI_config_parity_release
  • Loading branch information
kislaykishore authored Jun 27, 2024
2 parents ebe610c + b8aa8dc commit 2a6fb30
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func TestParallelDownloads(t *testing.T) {
}
for _, tc := range tbl {
t.Run(tc.name, func(t *testing.T) {
tc := tc
t.Parallel()
cache, cacheDir := configureCache(t, 2*tc.objectSize)
storageHandle := configureFakeStorage(t)
Expand Down
5 changes: 5 additions & 0 deletions internal/config/config_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package config
import (
"fmt"
"math"
"runtime"
"time"
)

Expand Down Expand Up @@ -112,3 +113,7 @@ func ListCacheTtlSecsToDuration(secs int64) time.Duration {

return time.Duration(secs * int64(time.Second))
}

func DefaultMaxParallelDownloads() int {
return max(16, 2*runtime.NumCPU())
}
4 changes: 4 additions & 0 deletions internal/config/config_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,7 @@ func Test_ListCacheTtlSecsToDuration_InvalidCall(t *testing.T) {
// Calling with invalid argument to trigger panic.
ListCacheTtlSecsToDuration(-3)
}

func Test_DefaultMaxParallelDownloads(t *testing.T) {
assert.GreaterOrEqual(t, DefaultMaxParallelDownloads(), 16)
}
3 changes: 1 addition & 2 deletions internal/config/mount_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ const (
DefaultEnableParallelDownloads = false
DefaultDownloadChunkSizeMB = 25
DefaultParallelDownloadsPerFile = 10
DefaultMaxParallelDownloads = -1
)

type WriteConfig struct {
Expand Down Expand Up @@ -187,7 +186,7 @@ func NewMountConfig() *MountConfig {
MaxSizeMB: DefaultFileCacheMaxSizeMB,
EnableParallelDownloads: DefaultEnableParallelDownloads,
ParallelDownloadsPerFile: DefaultParallelDownloadsPerFile,
MaxParallelDownloads: DefaultMaxParallelDownloads,
MaxParallelDownloads: DefaultMaxParallelDownloads(),
DownloadChunkSizeMB: DefaultDownloadChunkSizeMB,
EnableCRC: DefaultEnableCRC,
}
Expand Down
2 changes: 1 addition & 1 deletion internal/config/yaml_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func validateDefaultConfig(t *testing.T, mountConfig *MountConfig) {
assert.False(t, mountConfig.FileCacheConfig.CacheFileForRangeRead)
assert.False(t, mountConfig.FileCacheConfig.EnableParallelDownloads)
assert.Equal(t, 10, mountConfig.FileCacheConfig.ParallelDownloadsPerFile)
assert.Equal(t, -1, mountConfig.FileCacheConfig.MaxParallelDownloads)
assert.GreaterOrEqual(t, mountConfig.FileCacheConfig.MaxParallelDownloads, 16)
assert.Equal(t, 25, mountConfig.FileCacheConfig.DownloadChunkSizeMB)
assert.True(t, mountConfig.FileCacheConfig.EnableCRC)
assert.Equal(t, 1, mountConfig.GCSConnection.GRPCConnPoolSize)
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 2a6fb30

Please sign in to comment.