mirror of
https://github.com/minio/minio.git
synced 2025-11-09 21:49:46 -05:00
allow dynamically changing max_object_versions per object (#19265)
This commit is contained in:
@@ -55,6 +55,7 @@ type apiConfig struct {
|
||||
gzipObjects bool
|
||||
rootAccess bool
|
||||
syncEvents bool
|
||||
objectMaxVersions int
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -186,6 +187,7 @@ func (t *apiConfig) init(cfg api.Config, setDriveCounts []int) {
|
||||
t.gzipObjects = cfg.GzipObjects
|
||||
t.rootAccess = cfg.RootAccess
|
||||
t.syncEvents = cfg.SyncEvents
|
||||
t.objectMaxVersions = cfg.ObjectMaxVersions
|
||||
}
|
||||
|
||||
func (t *apiConfig) odirectEnabled() bool {
|
||||
@@ -386,3 +388,15 @@ func (t *apiConfig) isSyncEventsEnabled() bool {
|
||||
|
||||
return t.syncEvents
|
||||
}
|
||||
|
||||
func (t *apiConfig) getObjectMaxVersions() int {
|
||||
t.mu.RLock()
|
||||
defer t.mu.RUnlock()
|
||||
|
||||
if t.objectMaxVersions <= 0 {
|
||||
// defaults to 'maxObjectVersions' when unset.
|
||||
return maxObjectVersions
|
||||
}
|
||||
|
||||
return t.objectMaxVersions
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -38,31 +37,12 @@ import (
|
||||
"github.com/minio/minio/internal/config/storageclass"
|
||||
xhttp "github.com/minio/minio/internal/http"
|
||||
"github.com/minio/minio/internal/logger"
|
||||
"github.com/minio/pkg/v2/env"
|
||||
"github.com/tinylib/msgp/msgp"
|
||||
)
|
||||
|
||||
// Reject creating new versions when a single object is cross maxObjectVersions
|
||||
var maxObjectVersions = 10000
|
||||
|
||||
func init() {
|
||||
v := env.Get("_MINIO_OBJECT_MAX_VERSIONS", "")
|
||||
if v != "" {
|
||||
maxv, err := strconv.Atoi(v)
|
||||
if err != nil {
|
||||
logger.Info("invalid _MINIO_OBJECT_MAX_VERSIONS value: %s, defaulting to '10000'", v)
|
||||
maxObjectVersions = 10000
|
||||
} else {
|
||||
if maxv < 10 {
|
||||
logger.Info("invalid _MINIO_OBJECT_MAX_VERSIONS value: %s, minimum allowed is '10' defaulting to '10000'", v)
|
||||
maxObjectVersions = 10000
|
||||
} else {
|
||||
maxObjectVersions = maxv
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
// XL header specifies the format
|
||||
xlHeader = [4]byte{'X', 'L', '2', ' '}
|
||||
@@ -1112,7 +1092,7 @@ func (x *xlMetaV2) addVersion(ver xlMetaV2Version) error {
|
||||
}
|
||||
|
||||
// returns error if we have exceeded maxObjectVersions
|
||||
if len(x.versions)+1 > maxObjectVersions {
|
||||
if len(x.versions)+1 > globalAPIConfig.getObjectMaxVersions() {
|
||||
return errMaxVersionsExceeded
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user