No `listener.json` for single-node mode (Fixes #3052) (#3108)

In FS or single-node XL mode, there is no need to save listener
configuration to persistent storage. As there is only one server, if it
is restarted, any connected listenBucketAPI clients were disconnected
and will have to reconnect - so there is nothing to actually store.

This incidentally solves #3052 by avoiding the problem.
master
Aditya Manthramurthy 8 years ago committed by Harshavardhana
parent a15dc5fed5
commit 30dc11a931
  1. 24
      cmd/bucket-notification-handlers.go
  2. 7
      cmd/event-notifier.go
  3. 10
      cmd/event-notifier_test.go
  4. 6
      cmd/s3-peer-client.go

@ -379,11 +379,13 @@ func AddBucketListenerConfig(bucket string, lcfg *listenerConfig, objAPI ObjectL
// Release lock after notifying peers // Release lock after notifying peers
defer nsMutex.Unlock(bucket, "", opsID) defer nsMutex.Unlock(bucket, "", opsID)
// update persistent config // update persistent config if dist XL
err := persistListenerConfig(bucket, listenerCfgs, objAPI) if globalS3Peers.isDistXL {
if err != nil { err := persistListenerConfig(bucket, listenerCfgs, objAPI)
errorIf(err, "Error persisting listener config when adding a listener.") if err != nil {
return err errorIf(err, "Error persisting listener config when adding a listener.")
return err
}
} }
// persistence success - now update in-memory globals on all // persistence success - now update in-memory globals on all
@ -419,11 +421,13 @@ func RemoveBucketListenerConfig(bucket string, lcfg *listenerConfig, objAPI Obje
// Release lock after notifying peers // Release lock after notifying peers
defer nsMutex.Unlock(bucket, "", opsID) defer nsMutex.Unlock(bucket, "", opsID)
// update persistent config // update persistent config if dist XL
err := persistListenerConfig(bucket, updatedLcfgs, objAPI) if globalS3Peers.isDistXL {
if err != nil { err := persistListenerConfig(bucket, updatedLcfgs, objAPI)
errorIf(err, "Error persisting listener config when removing a listener.") if err != nil {
return errorIf(err, "Error persisting listener config when removing a listener.")
return
}
} }
// persistence success - now update in-memory globals on all // persistence success - now update in-memory globals on all

@ -347,6 +347,13 @@ func loadNotificationConfig(bucket string, objAPI ObjectLayer) (*notificationCon
// loads notification config if any for a given bucket, returns // loads notification config if any for a given bucket, returns
// structured notification config. // structured notification config.
func loadListenerConfig(bucket string, objAPI ObjectLayer) ([]listenerConfig, error) { func loadListenerConfig(bucket string, objAPI ObjectLayer) ([]listenerConfig, error) {
// in single node mode, there are no peers, so in this case
// there is no configuration to load, as any previously
// connected listen clients have been disconnected
if !globalS3Peers.isDistXL {
return nil, nil
}
// Construct the notification config path. // Construct the notification config path.
listenerConfigPath := path.Join(bucketConfigPrefix, bucket, bucketListenerConfig) listenerConfigPath := path.Join(bucketConfigPrefix, bucket, bucketListenerConfig)
objInfo, err := objAPI.GetObjectInfo(minioMetaBucket, listenerConfigPath) objInfo, err := objAPI.GetObjectInfo(minioMetaBucket, listenerConfigPath)

@ -291,6 +291,11 @@ func TestInitEventNotifier(t *testing.T) {
t.Fatal("Unexpected error:", err) t.Fatal("Unexpected error:", err)
} }
// needed to load listener config from disk for testing (in
// single peer mode, the listener config is ingored, but here
// we want to test the loading from disk too.)
globalS3Peers.isDistXL = true
// test event notifier init // test event notifier init
if err := initEventNotifier(obj); err != nil { if err := initEventNotifier(obj); err != nil {
t.Fatal("Unexpected error:", err) t.Fatal("Unexpected error:", err)
@ -361,6 +366,11 @@ func TestListenBucketNotification(t *testing.T) {
t.Fatalf("Test Setup error: %v", err) t.Fatalf("Test Setup error: %v", err)
} }
// needed to load listener config from disk for testing (in
// single peer mode, the listener config is ingored, but here
// we want to test the loading from disk too.)
globalS3Peers.isDistXL = true
// Init event notifier // Init event notifier
if err := initEventNotifier(obj); err != nil { if err := initEventNotifier(obj); err != nil {
t.Fatal("Unexpected error:", err) t.Fatal("Unexpected error:", err)

@ -32,6 +32,9 @@ type s3Peers struct {
mutex *sync.RWMutex mutex *sync.RWMutex
// Is single-node?
isDistXL bool
// Slice of all peer addresses (in `host:port` format). // Slice of all peer addresses (in `host:port` format).
peers []string peers []string
} }
@ -53,6 +56,9 @@ func initGlobalS3Peers(eps []storageEndPoint) {
// Save new peers // Save new peers
globalS3Peers.peers = peers globalS3Peers.peers = peers
// store if this is a distributed setup or not.
globalS3Peers.isDistXL = len(globalS3Peers.peers) > 1
} }
func (s3p *s3Peers) GetPeers() []string { func (s3p *s3Peers) GetPeers() []string {

Loading…
Cancel
Save