mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
Avoid double for loops in notification init (#8691)
This commit is contained in:
parent
54431b3953
commit
99ad445260
@ -46,7 +46,10 @@ function main()
|
|||||||
gw_pid="$(start_minio_gateway_s3)"
|
gw_pid="$(start_minio_gateway_s3)"
|
||||||
|
|
||||||
SERVER_ENDPOINT=127.0.0.1:24240 ENABLE_HTTPS=0 ACCESS_KEY=minio \
|
SERVER_ENDPOINT=127.0.0.1:24240 ENABLE_HTTPS=0 ACCESS_KEY=minio \
|
||||||
SECRET_KEY=minio123 MINT_MODE="full" /mint/entrypoint.sh
|
SECRET_KEY=minio123 MINT_MODE="full" /mint/entrypoint.sh \
|
||||||
|
aws-sdk-go aws-sdk-java aws-sdk-php aws-sdk-ruby awscli \
|
||||||
|
healthcheck mc minio-dotnet minio-go minio-java minio-py \
|
||||||
|
s3cmd security
|
||||||
rv=$?
|
rv=$?
|
||||||
|
|
||||||
kill "$sr_pid"
|
kill "$sr_pid"
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
@ -39,7 +40,6 @@ func handleEncryptedConfigBackend(objAPI ObjectLayer, server bool) error {
|
|||||||
|
|
||||||
// If its server mode or nas gateway, migrate the backend.
|
// If its server mode or nas gateway, migrate the backend.
|
||||||
doneCh := make(chan struct{})
|
doneCh := make(chan struct{})
|
||||||
defer close(doneCh)
|
|
||||||
|
|
||||||
var encrypted bool
|
var encrypted bool
|
||||||
var err error
|
var err error
|
||||||
@ -48,17 +48,27 @@ func handleEncryptedConfigBackend(objAPI ObjectLayer, server bool) error {
|
|||||||
// the following reasons:
|
// the following reasons:
|
||||||
// - Read quorum is lost just after the initialization
|
// - Read quorum is lost just after the initialization
|
||||||
// of the object layer.
|
// of the object layer.
|
||||||
for range newRetryTimerSimple(doneCh) {
|
retryTimerCh := newRetryTimerSimple(doneCh)
|
||||||
if encrypted, err = checkBackendEncrypted(objAPI); err != nil {
|
var stop bool
|
||||||
if err == errDiskNotFound ||
|
for !stop {
|
||||||
strings.Contains(err.Error(), InsufficientReadQuorum{}.Error()) {
|
select {
|
||||||
logger.Info("Waiting for config backend to be encrypted..")
|
case <-retryTimerCh:
|
||||||
continue
|
if encrypted, err = checkBackendEncrypted(objAPI); err != nil {
|
||||||
|
if err == errDiskNotFound ||
|
||||||
|
strings.Contains(err.Error(), InsufficientReadQuorum{}.Error()) {
|
||||||
|
logger.Info("Waiting for config backend to be encrypted..")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
close(doneCh)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return err
|
stop = true
|
||||||
|
case <-globalOSSignalCh:
|
||||||
|
close(doneCh)
|
||||||
|
return fmt.Errorf("Config encryption process stopped gracefully")
|
||||||
}
|
}
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
close(doneCh)
|
||||||
|
|
||||||
if encrypted {
|
if encrypted {
|
||||||
// backend is encrypted, but credentials are not specified
|
// backend is encrypted, but credentials are not specified
|
||||||
@ -83,24 +93,33 @@ func handleEncryptedConfigBackend(objAPI ObjectLayer, server bool) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doneCh = make(chan struct{})
|
||||||
|
defer close(doneCh)
|
||||||
|
|
||||||
|
retryTimerCh = newRetryTimerSimple(doneCh)
|
||||||
|
|
||||||
// Migrating Config backend needs a retry mechanism for
|
// Migrating Config backend needs a retry mechanism for
|
||||||
// the following reasons:
|
// the following reasons:
|
||||||
// - Read quorum is lost just after the initialization
|
// - Read quorum is lost just after the initialization
|
||||||
// of the object layer.
|
// of the object layer.
|
||||||
for range newRetryTimerSimple(doneCh) {
|
for {
|
||||||
// Migrate IAM configuration
|
select {
|
||||||
if err = migrateConfigPrefixToEncrypted(objAPI, activeCredOld, encrypted); err != nil {
|
case <-retryTimerCh:
|
||||||
if err == errDiskNotFound ||
|
// Migrate IAM configuration
|
||||||
strings.Contains(err.Error(), InsufficientReadQuorum{}.Error()) ||
|
if err = migrateConfigPrefixToEncrypted(objAPI, activeCredOld, encrypted); err != nil {
|
||||||
strings.Contains(err.Error(), InsufficientWriteQuorum{}.Error()) {
|
if err == errDiskNotFound ||
|
||||||
logger.Info("Waiting for config backend to be encrypted..")
|
strings.Contains(err.Error(), InsufficientReadQuorum{}.Error()) ||
|
||||||
continue
|
strings.Contains(err.Error(), InsufficientWriteQuorum{}.Error()) {
|
||||||
|
logger.Info("Waiting for config backend to be encrypted..")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return err
|
return nil
|
||||||
|
case <-globalOSSignalCh:
|
||||||
|
return fmt.Errorf("Config encryption process stopped gracefully")
|
||||||
}
|
}
|
||||||
break
|
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -343,17 +343,24 @@ func formatFSFixDeploymentID(fsFormatPath string) error {
|
|||||||
defer close(doneCh)
|
defer close(doneCh)
|
||||||
|
|
||||||
var wlk *lock.LockedFile
|
var wlk *lock.LockedFile
|
||||||
for range newRetryTimerSimple(doneCh) {
|
retryCh := newRetryTimerSimple(doneCh)
|
||||||
wlk, err = lock.TryLockedOpenFile(fsFormatPath, os.O_RDWR, 0)
|
var stop bool
|
||||||
if err == lock.ErrAlreadyLocked {
|
for !stop {
|
||||||
// Lock already present, sleep and attempt again
|
select {
|
||||||
logger.Info("Another minio process(es) might be holding a lock to the file %s. Please kill that minio process(es) (elapsed %s)\n", fsFormatPath, getElapsedTime())
|
case <-retryCh:
|
||||||
continue
|
wlk, err = lock.TryLockedOpenFile(fsFormatPath, os.O_RDWR, 0)
|
||||||
|
if err == lock.ErrAlreadyLocked {
|
||||||
|
// Lock already present, sleep and attempt again
|
||||||
|
logger.Info("Another minio process(es) might be holding a lock to the file %s. Please kill that minio process(es) (elapsed %s)\n", fsFormatPath, getElapsedTime())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
stop = true
|
||||||
|
case <-globalOSSignalCh:
|
||||||
|
return fmt.Errorf("Initializing FS format stopped gracefully")
|
||||||
}
|
}
|
||||||
break
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
defer wlk.Close()
|
defer wlk.Close()
|
||||||
|
58
cmd/iam.go
58
cmd/iam.go
@ -20,6 +20,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -365,46 +366,41 @@ func (sys *IAMSys) Init(objAPI ObjectLayer) error {
|
|||||||
doneCh := make(chan struct{})
|
doneCh := make(chan struct{})
|
||||||
defer close(doneCh)
|
defer close(doneCh)
|
||||||
|
|
||||||
// Migrating IAM needs a retry mechanism for
|
// Migrating IAM amd Loading IAM needs a retry mechanism for
|
||||||
// the following reasons:
|
// the following reasons:
|
||||||
// - Read quorum is lost just after the initialization
|
// - Read quorum is lost just after the initialization
|
||||||
// of the object layer.
|
// of the object layer.
|
||||||
for range newRetryTimerSimple(doneCh) {
|
retryCh := newRetryTimerSimple(doneCh)
|
||||||
// Migrate IAM configuration
|
for {
|
||||||
if err := sys.doIAMConfigMigration(objAPI); err != nil {
|
select {
|
||||||
if err == errDiskNotFound ||
|
case <-retryCh:
|
||||||
strings.Contains(err.Error(), InsufficientReadQuorum{}.Error()) ||
|
// Migrate IAM configuration
|
||||||
strings.Contains(err.Error(), InsufficientWriteQuorum{}.Error()) {
|
if err := sys.doIAMConfigMigration(objAPI); err != nil {
|
||||||
logger.Info("Waiting for IAM subsystem to be initialized..")
|
if err == errDiskNotFound ||
|
||||||
continue
|
strings.Contains(err.Error(), InsufficientReadQuorum{}.Error()) ||
|
||||||
|
strings.Contains(err.Error(), InsufficientWriteQuorum{}.Error()) {
|
||||||
|
logger.Info("Waiting for IAM subsystem to be initialized..")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return err
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
sys.store.watch(sys)
|
sys.store.watch(sys)
|
||||||
|
|
||||||
// Initializing IAM needs a retry mechanism for
|
if err := sys.store.loadAll(sys, objAPI); err != nil {
|
||||||
// the following reasons:
|
if err == errDiskNotFound ||
|
||||||
// - Read quorum is lost just after the initialization
|
strings.Contains(err.Error(), InsufficientReadQuorum{}.Error()) ||
|
||||||
// of the object layer.
|
strings.Contains(err.Error(), InsufficientWriteQuorum{}.Error()) {
|
||||||
for range newRetryTimerSimple(doneCh) {
|
logger.Info("Waiting for IAM subsystem to be initialized..")
|
||||||
// Load IAMSys once during boot. Need to pass in
|
continue
|
||||||
// objAPI as server has not yet initialized.
|
}
|
||||||
if err := sys.store.loadAll(sys, objAPI); err != nil {
|
return err
|
||||||
if err == errDiskNotFound ||
|
|
||||||
strings.Contains(err.Error(), InsufficientReadQuorum{}.Error()) ||
|
|
||||||
strings.Contains(err.Error(), InsufficientWriteQuorum{}.Error()) {
|
|
||||||
logger.Info("Waiting for IAM subsystem to be initialized..")
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
return err
|
return nil
|
||||||
|
case <-globalOSSignalCh:
|
||||||
|
return fmt.Errorf("Initializing IAM sub-system gracefully stopped")
|
||||||
}
|
}
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeletePolicy - deletes a canned policy from backend or etcd.
|
// DeletePolicy - deletes a canned policy from backend or etcd.
|
||||||
|
@ -718,8 +718,7 @@ func (sys *NotificationSys) Init(buckets []BucketInfo, objAPI ObjectLayer) error
|
|||||||
// - Read quorum is lost just after the initialization
|
// - Read quorum is lost just after the initialization
|
||||||
// of the object layer.
|
// of the object layer.
|
||||||
retryTimerCh := newRetryTimerSimple(doneCh)
|
retryTimerCh := newRetryTimerSimple(doneCh)
|
||||||
stop := false
|
for {
|
||||||
for !stop {
|
|
||||||
select {
|
select {
|
||||||
case <-retryTimerCh:
|
case <-retryTimerCh:
|
||||||
if err := sys.load(buckets, objAPI); err != nil {
|
if err := sys.load(buckets, objAPI); err != nil {
|
||||||
@ -731,17 +730,8 @@ func (sys *NotificationSys) Init(buckets []BucketInfo, objAPI ObjectLayer) error
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
stop = true
|
// Initializing bucket retention config needs a retry mechanism if
|
||||||
case <-globalOSSignalCh:
|
// read quorum is lost just after the initialization of the object layer.
|
||||||
return fmt.Errorf("Initializing Notification sub-system gracefully stopped")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initializing bucket retention config needs a retry mechanism if
|
|
||||||
// read quorum is lost just after the initialization of the object layer.
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-retryTimerCh:
|
|
||||||
if err := sys.initBucketObjectLockConfig(objAPI); err != nil {
|
if err := sys.initBucketObjectLockConfig(objAPI); err != nil {
|
||||||
if err == errDiskNotFound ||
|
if err == errDiskNotFound ||
|
||||||
strings.Contains(err.Error(), InsufficientReadQuorum{}.Error()) ||
|
strings.Contains(err.Error(), InsufficientReadQuorum{}.Error()) ||
|
||||||
|
Loading…
Reference in New Issue
Block a user