Implement batch-expiration for objects (#17946)

Based on an initial PR from -
https://github.com/minio/minio/pull/17792

But fully completes it with newer finalized YAML spec.
This commit is contained in:
Krishnan Parthasarathi
2023-12-02 02:51:33 -08:00
committed by GitHub
parent 69294cf98a
commit a50f26b7f5
22 changed files with 3037 additions and 112 deletions

View File

@@ -0,0 +1,160 @@
// Copyright (c) 2015-2023 MinIO, Inc.
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package batch
import (
"sync"
"time"
"github.com/minio/minio/internal/config"
"github.com/minio/pkg/env"
)
// Batch job environment variables
const (
ReplicationWorkersWait = "replication_workers_wait"
KeyRotationWorkersWait = "keyrotation_workers_wait"
ExpirationWorkersWait = "expiration_workers_wait"
EnvReplicationWorkersWait = "MINIO_BATCH_REPLICATION_WORKERS_WAIT"
EnvKeyRotationWorkersWait = "MINIO_BATCH_KEYROTATION_WORKERS_WAIT"
EnvKeyExpirationWorkersWait = "MINIO_BATCH_EXPIRATION_WORKERS_WAIT"
)
var configMu sync.RWMutex
// Config represents the batch job settings.
type Config struct {
ReplicationWorkersWait time.Duration `json:"replicationWorkersWait"`
KeyRotationWorkersWait time.Duration `json:"keyRotationWorkersWait"`
ExpirationWorkersWait time.Duration `json:"expirationWorkersWait"`
}
// ExpirationWait returns the duration for which a batch expiration worker
// would wait before working on next object.
func (opts Config) ExpirationWait() time.Duration {
configMu.RLock()
defer configMu.RUnlock()
return opts.ExpirationWorkersWait
}
// ReplicationWait returns the duration for which a batch replication worker
// would wait before working on next object.
func (opts Config) ReplicationWait() time.Duration {
configMu.RLock()
defer configMu.RUnlock()
return opts.ReplicationWorkersWait
}
// KeyRotationWait returns the duration for which a batch key-rotation worker
// would wait before working on next object.
func (opts Config) KeyRotationWait() time.Duration {
configMu.RLock()
defer configMu.RUnlock()
return opts.KeyRotationWorkersWait
}
// Clone returns a copy of Config value
func (opts Config) Clone() Config {
configMu.RLock()
defer configMu.RUnlock()
return Config{
ReplicationWorkersWait: opts.ReplicationWorkersWait,
KeyRotationWorkersWait: opts.KeyRotationWorkersWait,
ExpirationWorkersWait: opts.ExpirationWorkersWait,
}
}
// Update updates opts with nopts
func (opts *Config) Update(nopts Config) {
configMu.Lock()
defer configMu.Unlock()
opts.ReplicationWorkersWait = nopts.ReplicationWorkersWait
opts.KeyRotationWorkersWait = nopts.KeyRotationWorkersWait
opts.ExpirationWorkersWait = nopts.ExpirationWorkersWait
}
// DefaultKVS - default KV config for batch job settings
var DefaultKVS = config.KVS{
config.KV{
Key: ReplicationWorkersWait,
Value: "0ms", // No wait by default between each replication attempts.
},
config.KV{
Key: KeyRotationWorkersWait,
Value: "0ms", // No wait by default between each key rotation attempts.
},
config.KV{
Key: ExpirationWorkersWait,
Value: "0ms", // No wait by default between each expiration attempts.
},
}
// LookupConfig - lookup config and override with valid environment settings if any.
func LookupConfig(kvs config.KVS) (cfg Config, err error) {
if err = config.CheckValidKeys(config.BatchSubSys, kvs, DefaultKVS); err != nil {
return cfg, err
}
cfg.ReplicationWorkersWait = 0
cfg.KeyRotationWorkersWait = 0
cfg.ExpirationWorkersWait = 0
rduration, err := time.ParseDuration(env.Get(EnvReplicationWorkersWait, kvs.GetWithDefault(ReplicationWorkersWait, DefaultKVS)))
if err != nil {
return cfg, err
}
if rduration < 0 {
return cfg, config.ErrInvalidBatchReplicationWorkersWait(nil)
}
kduration, err := time.ParseDuration(env.Get(EnvKeyRotationWorkersWait, kvs.GetWithDefault(KeyRotationWorkersWait, DefaultKVS)))
if err != nil {
return cfg, err
}
if kduration < 0 {
return cfg, config.ErrInvalidBatchKeyRotationWorkersWait(nil)
}
eduration, err := time.ParseDuration(env.Get(EnvKeyExpirationWorkersWait, kvs.GetWithDefault(ExpirationWorkersWait, DefaultKVS)))
if err != nil {
return cfg, err
}
if eduration < 0 {
return cfg, config.ErrInvalidBatchExpirationWorkersWait(nil)
}
if rduration > 0 {
cfg.ReplicationWorkersWait = rduration
}
if kduration > 0 {
cfg.KeyRotationWorkersWait = kduration
}
if eduration > 0 {
cfg.ExpirationWorkersWait = eduration
}
return cfg, nil
}

View File

@@ -0,0 +1,49 @@
// Copyright (c) 2015-2023 MinIO, Inc.
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package batch
import "github.com/minio/minio/internal/config"
// Help template for batch feature.
var (
defaultHelpPostfix = func(key string) string {
return config.DefaultHelpPostfix(DefaultKVS, key)
}
// Help provides help for config values
Help = config.HelpKVS{
config.HelpKV{
Key: ReplicationWorkersWait,
Description: `maximum sleep duration between objects to slow down batch replication operation` + defaultHelpPostfix(ReplicationWorkersWait),
Optional: true,
Type: "duration",
},
config.HelpKV{
Key: KeyRotationWorkersWait,
Description: `maximum sleep duration between objects to slow down batch keyrotation operation` + defaultHelpPostfix(KeyRotationWorkersWait),
Optional: true,
Type: "duration",
},
config.HelpKV{
Key: ExpirationWorkersWait,
Description: "maximum sleep duration between objects to slow down batch expiration operation" + defaultHelpPostfix(ExpirationWorkersWait),
Optional: true,
Type: "duration",
},
}
)

View File

@@ -118,6 +118,8 @@ const (
SubnetSubSys = madmin.SubnetSubSys
CallhomeSubSys = madmin.CallhomeSubSys
DriveSubSys = madmin.DriveSubSys
BatchSubSys = madmin.BatchSubSys
// Add new constants here (similar to above) if you add new fields to config.
)
@@ -185,6 +187,7 @@ var SubSystemsDynamic = set.CreateStringSet(
AuditKafkaSubSys,
StorageClassSubSys,
CacheSubSys,
BatchSubSys,
)
// SubSystemsSingleTargets - subsystems which only support single target.
@@ -207,6 +210,7 @@ var SubSystemsSingleTargets = set.CreateStringSet(
CallhomeSubSys,
DriveSubSys,
CacheSubSys,
BatchSubSys,
)
// Constant separators

View File

@@ -224,4 +224,19 @@ Examples:
"",
"MINIO_API_TRANSITION_WORKERS: should be >= GOMAXPROCS/2",
)
ErrInvalidBatchKeyRotationWorkersWait = newErrFn(
"Invalid value for batch key rotation workers wait",
"Please input a non-negative duration",
"keyrotation_workers_wait should be > 0ms",
)
ErrInvalidBatchReplicationWorkersWait = newErrFn(
"Invalid value for batch replication workers wait",
"Please input a non-negative duration",
"replication_workers_wait should be > 0ms",
)
ErrInvalidBatchExpirationWorkersWait = newErrFn(
"Invalid value for batch expiration workers wait",
"Please input a non-negative duration",
"expiration_workers_wait should be > 0ms",
)
)