Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make max inline blob size configurable #375

Merged
merged 2 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion configs/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ redis_pool_size: 10000
redis_idle_timeout: 0
redis_max_retries: 3
redis_min_retry_backoff: "8ms"
redis_max_retry_backoff: "512ms"
redis_max_retry_backoff: "512ms"

blob_max_inline_size: 65536
14 changes: 7 additions & 7 deletions internal/app/server/open_saves.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import (
// TODO(hongalex): make this a configurable field for users.
const (
maxRecordSizeToCache int = 10 * 1024 * 1024 // 10 MB
maxInlineBlobSize int = 64 * 1024 // 64 KiB
streamBufferSize int = 1 * 1024 * 1024 // 1 MiB
chunkSizeLimit int = 1 * 1024 * 1024 * 1024 // 1 GiB
)
Expand All @@ -52,6 +51,7 @@ type openSavesServer struct {
blobStore blob.BlobStore
metaDB *metadb.MetaDB
cacheStore *cache.Cache
config.ServiceConfig

pb.UnimplementedOpenSavesServer
}
Expand All @@ -78,10 +78,11 @@ func newOpenSavesServer(ctx context.Context, cfg *config.ServiceConfig) (*openSa
}
cache := cache.New(redis.NewRedisWithConfig(&cfg.RedisConfig), &cfg.CacheConfig)
server := &openSavesServer{
cloud: cfg.ServerConfig.Cloud,
blobStore: gcs,
metaDB: metadb,
cacheStore: cache,
cloud: cfg.ServerConfig.Cloud,
blobStore: gcs,
metaDB: metadb,
cacheStore: cache,
ServiceConfig: *cfg,
}
return server, nil
default:
Expand Down Expand Up @@ -396,8 +397,7 @@ func (s *openSavesServer) CreateBlob(stream pb.OpenSaves_CreateBlobServer) error
log.Debugf("Got metadata from stream: store(%s), record(%s), blob size(%d)\n",
meta.GetStoreKey(), meta.GetRecordKey(), meta.GetSize())

// TODO(yuryu): Make the threshold configurable
if meta.GetSize() <= int64(maxInlineBlobSize) {
if meta.GetSize() <= int64(s.BlobConfig.MaxInlineSize) {
return s.insertInlineBlob(ctx, stream, meta)
}
return s.insertExternalBlob(ctx, stream, meta)
Expand Down
5 changes: 5 additions & 0 deletions internal/pkg/config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,14 @@ func Load(path string) (*ServiceConfig, error) {
IdleTimeout: time.Duration(viper.GetUint(RedisIdleTimeout)) * time.Second,
}

blobConfig := BlobConfig{
MaxInlineSize: viper.GetInt(BlobMaxInlineSize),
}

return &ServiceConfig{
ServerConfig: serverConfig,
CacheConfig: cacheConfig,
RedisConfig: redisConfig,
BlobConfig: blobConfig,
}, nil
}
8 changes: 8 additions & 0 deletions internal/pkg/config/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ const (
RedisMaxRetries = "redis_max_retries"
RedisMinRetryBackoff = "redis_min_retry_backoff"
RedisMaxRetryBackoff = "redis_max_retry_backoff"

BlobMaxInlineSize = "blob_max_inline_size"
)

type ServiceConfig struct {
ServerConfig
CacheConfig
RedisConfig
BlobConfig
}

// ServerConfig defines common fields needed to start Open Saves.
Expand Down Expand Up @@ -66,3 +69,8 @@ type RedisConfig struct {
PoolSize int
IdleTimeout time.Duration
}

// BlobConfig has Open Saves blob related configurations.
type BlobConfig struct {
MaxInlineSize int
}