mirror of
https://github.com/pgsty/minio.git
synced 2026-08-08 23:33:30 +03:00
Make addition of TopicConfig to globalEventNotifier go-routine safe (#2806)
This commit is contained in:
committed by
Harshavardhana
parent
f72163f856
commit
5fdd768903
@@ -270,47 +270,24 @@ func (api objectAPIHandlers) ListenBucketNotificationHandler(w http.ResponseWrit
|
||||
})
|
||||
}
|
||||
|
||||
// Fetch for existing notification configs and update topic configs.
|
||||
nConfig := globalEventNotifier.GetBucketNotificationConfig(bucket)
|
||||
if nConfig == nil {
|
||||
// No notification configs found, initialize.
|
||||
nConfig = ¬ificationConfig{
|
||||
TopicConfigs: []topicConfig{{
|
||||
TopicARN: accountARN,
|
||||
serviceConfig: serviceConfig{
|
||||
Events: events,
|
||||
Filter: struct {
|
||||
Key keyFilter `xml:"S3Key,omitempty"`
|
||||
}{
|
||||
Key: keyFilter{
|
||||
FilterRules: filterRules,
|
||||
},
|
||||
},
|
||||
ID: "sns-" + accountID,
|
||||
// Make topic configuration corresponding to this ListenBucketNotification request.
|
||||
topicCfg := &topicConfig{
|
||||
TopicARN: accountARN,
|
||||
serviceConfig: serviceConfig{
|
||||
Events: events,
|
||||
Filter: struct {
|
||||
Key keyFilter `xml:"S3Key,omitempty"`
|
||||
}{
|
||||
Key: keyFilter{
|
||||
FilterRules: filterRules,
|
||||
},
|
||||
}},
|
||||
}
|
||||
} else {
|
||||
// Previously set notification configs found append to
|
||||
// existing topic configs.
|
||||
nConfig.TopicConfigs = append(nConfig.TopicConfigs, topicConfig{
|
||||
TopicARN: accountARN,
|
||||
serviceConfig: serviceConfig{
|
||||
Events: events,
|
||||
Filter: struct {
|
||||
Key keyFilter `xml:"S3Key,omitempty"`
|
||||
}{
|
||||
Key: keyFilter{
|
||||
FilterRules: filterRules,
|
||||
},
|
||||
},
|
||||
ID: "sns-" + accountID,
|
||||
},
|
||||
})
|
||||
ID: "sns-" + accountID,
|
||||
},
|
||||
}
|
||||
|
||||
// Save bucket notification config.
|
||||
if err = globalEventNotifier.SetBucketNotificationConfig(bucket, nConfig); err != nil {
|
||||
// Add topic config to bucket notification config.
|
||||
if err = globalEventNotifier.AddTopicConfig(bucket, topicCfg); err != nil {
|
||||
writeErrorResponse(w, r, toAPIErrorCode(err), r.URL.Path)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user