local: Limit concurrent backend operations

Use a limit of 2 similar to the filereader concurrency in the archiver.
This commit is contained in:
Michael Eischer 2021-08-07 19:50:00 +02:00
parent 0b258cc054
commit cd783358d3
7 changed files with 88 additions and 32 deletions

View file

@ -11,6 +11,15 @@ import (
type Config struct {
Path string
Layout string `option:"layout" help:"use this backend directory layout (default: auto-detect)"`
Connections uint `option:"connections" help:"set a limit for the number of concurrent operations (default: 2)"`
}
// NewConfig returns a new config with default options applied.
func NewConfig() Config {
return Config{
Connections: 2,
}
}
func init() {
@ -18,10 +27,12 @@ func init() {
}
// ParseConfig parses a local backend config.
func ParseConfig(cfg string) (interface{}, error) {
if !strings.HasPrefix(cfg, "local:") {
func ParseConfig(s string) (interface{}, error) {
if !strings.HasPrefix(s, "local:") {
return nil, errors.New(`invalid format, prefix "local" not found`)
}
return Config{Path: cfg[6:]}, nil
cfg := NewConfig()
cfg.Path = s[6:]
return cfg, nil
}