Initialize global object layer after all subsystems have initialized (#6333)

This is to ensure that object API operations are not performed
on a server on which subsystems are yet to be initialized.
This commit is contained in:
Harshavardhana 2018-08-22 23:11:17 -07:00 committed by GitHub
parent 8601f29d95
commit b01e69e08f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 21 deletions

View File

@ -174,10 +174,6 @@ func TestServerConfigMigrateV2toV28(t *testing.T) {
}
defer os.RemoveAll(fsDir)
globalObjLayerMutex.Lock()
globalObjectAPI = objLayer
globalObjLayerMutex.Unlock()
configPath := rootPath + "/" + minioConfigFile
// Create a corrupted config file
@ -203,12 +199,12 @@ func TestServerConfigMigrateV2toV28(t *testing.T) {
t.Fatal("Unexpected error: ", err)
}
if err := migrateConfigToMinioSys(); err != nil {
if err := migrateConfigToMinioSys(objLayer); err != nil {
t.Fatal("Unexpected error: ", err)
}
// Initialize server config and check again if everything is fine
if err := loadConfig(newObjectLayerFn()); err != nil {
if err := loadConfig(objLayer); err != nil {
t.Fatalf("Unable to initialize from updated config file %s", err)
}

View File

@ -202,9 +202,9 @@ func NewConfigSys() *ConfigSys {
}
// Migrates ${HOME}/.minio/config.json to '<export_path>/.minio.sys/config/config.json'
func migrateConfigToMinioSys() error {
func migrateConfigToMinioSys(objAPI ObjectLayer) error {
// Verify if backend already has the file.
if err := checkServerConfig(context.Background(), newObjectLayerFn()); err != errConfigNotFound {
if err := checkServerConfig(context.Background(), objAPI); err != errConfigNotFound {
return err
} // if errConfigNotFound proceed to migrate..
@ -213,7 +213,7 @@ func migrateConfigToMinioSys() error {
return err
}
return saveServerConfig(newObjectLayerFn(), config)
return saveServerConfig(objAPI, config)
}
// Initialize and load config from remote etcd or local config directory
@ -236,7 +236,7 @@ func initConfig(objAPI ObjectLayer) error {
}
// Migrates ${HOME}/.minio/config.json to '<export_path>/.minio.sys/config/config.json'
if err := migrateConfigToMinioSys(); err != nil {
if err := migrateConfigToMinioSys(objAPI); err != nil {
return err
}
}

View File

@ -77,10 +77,6 @@ func (sys *PolicySys) Remove(bucketName string) {
// IsAllowed - checks given policy args is allowed to continue the Rest API.
func (sys *PolicySys) IsAllowed(args policy.Args) bool {
if sys == nil {
return args.IsOwner
}
sys.RLock()
defer sys.RUnlock()

View File

@ -313,10 +313,6 @@ func serverMain(ctx *cli.Context) {
logger.FatalIf(err, "Unable to initialize backend")
}
globalObjLayerMutex.Lock()
globalObjectAPI = newObject
globalObjLayerMutex.Unlock()
// Populate existing buckets to the etcd backend
if globalDNSConfig != nil {
initFederatorBackend(newObject)
@ -326,7 +322,7 @@ func serverMain(ctx *cli.Context) {
globalConfigSys = NewConfigSys()
// Initialize config system.
if err = globalConfigSys.Init(newObjectLayerFn()); err != nil {
if err = globalConfigSys.Init(newObject); err != nil {
logger.Fatal(err, "Unable to initialize config system")
}
@ -347,7 +343,7 @@ func serverMain(ctx *cli.Context) {
globalPolicySys = NewPolicySys()
// Initialize policy system.
if err := globalPolicySys.Init(newObjectLayerFn()); err != nil {
if err := globalPolicySys.Init(newObject); err != nil {
logger.Fatal(err, "Unable to initialize policy system")
}
@ -355,10 +351,14 @@ func serverMain(ctx *cli.Context) {
globalNotificationSys = NewNotificationSys(globalServerConfig, globalEndpoints)
// Initialize notification system.
if err := globalNotificationSys.Init(newObjectLayerFn()); err != nil {
if err := globalNotificationSys.Init(newObject); err != nil {
logger.Fatal(err, "Unable to initialize notification system")
}
globalObjLayerMutex.Lock()
globalObjectAPI = newObject
globalObjLayerMutex.Unlock()
// Prints the formatted startup message once object layer is initialized.
apiEndpoints := getAPIEndpoints(globalMinioAddr)
printStartupMessage(apiEndpoints)