@ -241,10 +241,10 @@ func (sys *NotificationSys) initListeners(ctx context.Context, objAPI ObjectLaye
// and configFile, take a transaction lock to avoid data race between readConfig()
// and configFile, take a transaction lock to avoid data race between readConfig()
// and saveConfig().
// and saveConfig().
objLock := globalNSMutex . NewNSLock ( minioMetaBucket , transactionConfigFile )
objLock := globalNSMutex . NewNSLock ( minioMetaBucket , transactionConfigFile )
if err := objLock . GetLock ( globalOperationTimeout ) ; err != nil {
if err := objLock . GetR Lock ( globalOperationTimeout ) ; err != nil {
return err
return err
}
}
defer objLock . Unlock ( )
defer objLock . R Unlock( )
reader , e := readConfig ( ctx , objAPI , configFile )
reader , e := readConfig ( ctx , objAPI , configFile )
if e != nil && ! IsErrIgnored ( e , errDiskNotFound , errConfigNotFound ) {
if e != nil && ! IsErrIgnored ( e , errDiskNotFound , errConfigNotFound ) {
@ -265,7 +265,6 @@ func (sys *NotificationSys) initListeners(ctx context.Context, objAPI ObjectLaye
return nil
return nil
}
}
activeListenerList := [ ] ListenBucketNotificationArgs { }
for _ , args := range listenerList {
for _ , args := range listenerList {
found , err := isLocalHost ( args . Addr . Name )
found , err := isLocalHost ( args . Addr . Name )
if err != nil {
if err != nil {
@ -301,48 +300,64 @@ func (sys *NotificationSys) initListeners(ctx context.Context, objAPI ObjectLaye
logger . LogIf ( ctx , err )
logger . LogIf ( ctx , err )
return err
return err
}
}
activeListenerList = append ( activeListenerList , args )
}
data , err := json . Marshal ( activeListenerList )
if err != nil {
logger . LogIf ( ctx , err )
return err
}
}
return saveConfig ( objAPI , configFile , data )
return nil
}
}
// Init - initializes notification system from notification.xml and listener.json of all buckets.
func ( sys * NotificationSys ) refresh ( objAPI ObjectLayer ) error {
func ( sys * NotificationSys ) Init ( objAPI ObjectLayer ) error {
if objAPI == nil {
return errInvalidArgument
}
buckets , err := objAPI . ListBuckets ( context . Background ( ) )
buckets , err := objAPI . ListBuckets ( context . Background ( ) )
if err != nil {
if err != nil {
return err
return err
}
}
for _ , bucket := range buckets {
for _ , bucket := range buckets {
ctx := logger . SetReqInfo ( context . Background ( ) , & logger . ReqInfo { BucketName : bucket . Name } )
ctx := logger . SetReqInfo ( context . Background ( ) , & logger . ReqInfo { BucketName : bucket . Name } )
config , err := readNotificationConfig ( ctx , objAPI , bucket . Name )
config , err := readNotificationConfig ( ctx , objAPI , bucket . Name )
if err != nil {
if err != nil && err != errNoSuchNotifications {
if ! IsErrIgnored ( err , errDiskNotFound , errNoSuchNotifications ) {
return err
return err
}
} else {
sys . AddRulesMap ( bucket . Name , config . ToRulesMap ( ) )
}
}
if err == errNoSuchNotifications {
continue
}
sys . AddRulesMap ( bucket . Name , config . ToRulesMap ( ) )
if err = sys . initListeners ( ctx , objAPI , bucket . Name ) ; err != nil {
if err = sys . initListeners ( ctx , objAPI , bucket . Name ) ; err != nil {
return err
return err
}
}
}
}
return nil
return nil
}
}
// Init - initializes notification system from notification.xml and listener.json of all buckets.
func ( sys * NotificationSys ) Init ( objAPI ObjectLayer ) error {
if objAPI == nil {
return errInvalidArgument
}
doneCh := make ( chan struct { } )
defer close ( doneCh )
// Initializing notification needs a retry mechanism for
// the following reasons:
// - Read quorum is lost just after the initialization
// of the object layer.
retryTimerCh := newRetryTimerSimple ( doneCh )
for {
select {
case _ = <- retryTimerCh :
if err := sys . refresh ( objAPI ) ; err != nil {
if err == errDiskNotFound ||
strings . Contains ( err . Error ( ) , InsufficientReadQuorum { } . Error ( ) ) ||
strings . Contains ( err . Error ( ) , InsufficientWriteQuorum { } . Error ( ) ) {
logger . Info ( "Waiting for notification subsystem to be initialized.." )
continue
}
return err
}
return nil
}
}
}
// AddRulesMap - adds rules map for bucket name.
// AddRulesMap - adds rules map for bucket name.
func ( sys * NotificationSys ) AddRulesMap ( bucketName string , rulesMap event . RulesMap ) {
func ( sys * NotificationSys ) AddRulesMap ( bucketName string , rulesMap event . RulesMap ) {
sys . Lock ( )
sys . Lock ( )