set max versions to be IntMax to avoid premature failures (#19360)

let users/customers set relevant values make default value
to be non-applicable.
This commit is contained in:
Harshavardhana 2024-03-27 18:08:07 -07:00 committed by GitHub
parent 4a02189ba0
commit 3e38fa54a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 19 deletions

View File

@ -18,6 +18,7 @@
package cmd package cmd
import ( import (
"math"
"net/http" "net/http"
"os" "os"
"runtime" "runtime"
@ -55,7 +56,7 @@ type apiConfig struct {
gzipObjects bool gzipObjects bool
rootAccess bool rootAccess bool
syncEvents bool syncEvents bool
objectMaxVersions int objectMaxVersions int64
} }
const ( const (
@ -393,13 +394,13 @@ func (t *apiConfig) isSyncEventsEnabled() bool {
return t.syncEvents return t.syncEvents
} }
func (t *apiConfig) getObjectMaxVersions() int { func (t *apiConfig) getObjectMaxVersions() int64 {
t.mu.RLock() t.mu.RLock()
defer t.mu.RUnlock() defer t.mu.RUnlock()
if t.objectMaxVersions <= 0 { if t.objectMaxVersions <= 0 {
// defaults to 'maxObjectVersions' when unset. // defaults to 'IntMax' when unset.
return maxObjectVersions return math.MaxInt64
} }
return t.objectMaxVersions return t.objectMaxVersions

View File

@ -40,9 +40,6 @@ import (
"github.com/tinylib/msgp/msgp" "github.com/tinylib/msgp/msgp"
) )
// Reject creating new versions when a single object is cross maxObjectVersions
var maxObjectVersions = 10000
var ( var (
// XL header specifies the format // XL header specifies the format
xlHeader = [4]byte{'X', 'L', '2', ' '} xlHeader = [4]byte{'X', 'L', '2', ' '}
@ -1091,8 +1088,8 @@ func (x *xlMetaV2) addVersion(ver xlMetaV2Version) error {
return err return err
} }
// returns error if we have exceeded maxObjectVersions // returns error if we have exceeded configured object max versions
if len(x.versions)+1 > globalAPIConfig.getObjectMaxVersions() { if int64(len(x.versions)+1) > globalAPIConfig.getObjectMaxVersions() {
return errMaxVersionsExceeded return errMaxVersionsExceeded
} }

View File

@ -21,6 +21,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"math"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -155,7 +156,7 @@ var (
}, },
config.KV{ config.KV{
Key: apiObjectMaxVersions, Key: apiObjectMaxVersions,
Value: "10000", Value: "9223372036854775807",
}, },
} }
) )
@ -178,7 +179,7 @@ type Config struct {
GzipObjects bool `json:"gzip_objects"` GzipObjects bool `json:"gzip_objects"`
RootAccess bool `json:"root_access"` RootAccess bool `json:"root_access"`
SyncEvents bool `json:"sync_events"` SyncEvents bool `json:"sync_events"`
ObjectMaxVersions int `json:"object_max_versions"` ObjectMaxVersions int64 `json:"object_max_versions"`
} }
// UnmarshalJSON - Validate SS and RRS parity when unmarshalling JSON. // UnmarshalJSON - Validate SS and RRS parity when unmarshalling JSON.
@ -317,16 +318,20 @@ func LookupConfig(kvs config.KVS) (cfg Config, err error) {
maxVerStr := env.Get(EnvAPIObjectMaxVersions, "") maxVerStr := env.Get(EnvAPIObjectMaxVersions, "")
if maxVerStr == "" { if maxVerStr == "" {
maxVerStr = env.Get(EnvAPIObjectMaxVersionsLegacy, kvs.GetWithDefault(apiObjectMaxVersions, DefaultKVS)) maxVerStr = env.Get(EnvAPIObjectMaxVersionsLegacy, kvs.Get(apiObjectMaxVersions))
} }
maxVersions, err := strconv.Atoi(maxVerStr) if maxVerStr != "" {
if err != nil { maxVersions, err := strconv.ParseInt(maxVerStr, 10, 64)
return cfg, err if err != nil {
return cfg, err
}
if maxVersions <= 0 {
return cfg, fmt.Errorf("invalid object max versions value: %v", maxVersions)
}
cfg.ObjectMaxVersions = maxVersions
} else {
cfg.ObjectMaxVersions = math.MaxInt64
} }
if maxVersions <= 0 {
return cfg, fmt.Errorf("invalid object max versions value: %v", maxVersions)
}
cfg.ObjectMaxVersions = maxVersions
return cfg, nil return cfg, nil
} }