mirror of https://github.com/minio/minio.git
Browse Source
Add bucket metadata state client/handler (Fixes #3022) (#3152)
Add bucket metadata state client/handler (Fixes #3022) (#3152)
- Adds an interface to update in-memory bucket metadata state called BucketMetaState - this interface has functions to: - update bucket notification configuration, - bucket listener configuration, - bucket policy configuration, and - send bucket event - This interface is implemented by `localBMS` a type for manipulating local node in-memory bucket metadata, and by `remoteBMS` a type for manipulating remote node in-memory bucket metadata. - The remote node interface, makes an RPC call, but the local node interface does not - it updates in-memory bucket state directly. - Rename mkPeersFromEndpoints to makeS3Peers and refactored it. - Use arrayslice instead of map in s3Peers struct - `s3Peers.SendUpdate` now receives an arrayslice of peer indexes to send the request to, with a special nil value slice indicating that all peers should be sent the update. - `s3Peers.SendUpdate` now returns an arrayslice of errors, representing errors from peers when sending an update. The array positions correspond to peer array s3Peers.peers Improve globalS3Peers: - Make isDistXL a global `globalIsDistXL` and remove from s3Peers - Make globalS3Peers an array of (address, bucket-meta-state) pairs. - Fix code and tests.pull/3192/head

committed by
Harshavardhana

19 changed files with 383 additions and 249 deletions
-
7cmd/browser-peer-rpc.go
-
152cmd/bucket-metadata.go
-
4cmd/bucket-notification-handlers.go
-
4cmd/control-router.go
-
11cmd/control-router_test.go
-
2cmd/event-notifier.go
-
4cmd/event-notifier_test.go
-
3cmd/globals.go
-
6cmd/lock-rpc-server_test.go
-
16cmd/notify-listener.go
-
2cmd/routers.go
-
286cmd/s3-peer-client.go
-
44cmd/s3-peer-client_test.go
-
6cmd/s3-peer-router.go
-
50cmd/s3-peer-rpc-handlers.go
-
19cmd/server-main.go
-
4cmd/test-utils_test.go
-
2cmd/utils.go
-
10cmd/utils_test.go
@ -0,0 +1,152 @@ |
|||
/* |
|||
* Minio Cloud Storage, (C) 2014-2016 Minio, Inc. |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
|
|||
package cmd |
|||
|
|||
import ( |
|||
"encoding/json" |
|||
"net/rpc" |
|||
) |
|||
|
|||
// BucketMetaState - Interface to update bucket metadata in-memory
|
|||
// state.
|
|||
type BucketMetaState interface { |
|||
// Updates bucket notification
|
|||
UpdateBucketNotification(args *SetBNPArgs) error |
|||
|
|||
// Updates bucket listener
|
|||
UpdateBucketListener(args *SetBLPArgs) error |
|||
|
|||
// Updates bucket policy
|
|||
UpdateBucketPolicy(args *SetBPPArgs) error |
|||
|
|||
// Sends event
|
|||
SendEvent(args *EventArgs) error |
|||
} |
|||
|
|||
// Type that implements BucketMetaState for local node.
|
|||
type localBMS struct { |
|||
ObjectAPI func() ObjectLayer |
|||
} |
|||
|
|||
// localBMS.UpdateBucketNotification - updates in-memory global bucket
|
|||
// notification info.
|
|||
func (lc *localBMS) UpdateBucketNotification(args *SetBNPArgs) error { |
|||
// check if object layer is available.
|
|||
objAPI := lc.ObjectAPI() |
|||
if objAPI == nil { |
|||
return errServerNotInitialized |
|||
} |
|||
|
|||
globalEventNotifier.SetBucketNotificationConfig(args.Bucket, args.NCfg) |
|||
|
|||
return nil |
|||
} |
|||
|
|||
// localBMS.UpdateBucketListener - updates in-memory global bucket
|
|||
// listeners info.
|
|||
func (lc *localBMS) UpdateBucketListener(args *SetBLPArgs) error { |
|||
// check if object layer is available.
|
|||
objAPI := lc.ObjectAPI() |
|||
if objAPI == nil { |
|||
return errServerNotInitialized |
|||
} |
|||
|
|||
// Update in-memory notification config.
|
|||
return globalEventNotifier.SetBucketListenerConfig(args.Bucket, args.LCfg) |
|||
} |
|||
|
|||
// localBMS.UpdateBucketPolicy - updates in-memory global bucket
|
|||
// policy info.
|
|||
func (lc *localBMS) UpdateBucketPolicy(args *SetBPPArgs) error { |
|||
// check if object layer is available.
|
|||
objAPI := lc.ObjectAPI() |
|||
if objAPI == nil { |
|||
return errServerNotInitialized |
|||
} |
|||
|
|||
var pCh policyChange |
|||
if err := json.Unmarshal(args.PChBytes, &pCh); err != nil { |
|||
return err |
|||
} |
|||
|
|||
return globalBucketPolicies.SetBucketPolicy(args.Bucket, pCh) |
|||
} |
|||
|
|||
// localBMS.SendEvent - sends event to local event notifier via
|
|||
// `globalEventNotifier`
|
|||
func (lc *localBMS) SendEvent(args *EventArgs) error { |
|||
// check if object layer is available.
|
|||
objAPI := lc.ObjectAPI() |
|||
if objAPI == nil { |
|||
return errServerNotInitialized |
|||
} |
|||
|
|||
return globalEventNotifier.SendListenerEvent(args.Arn, args.Event) |
|||
} |
|||
|
|||
// Type that implements BucketMetaState for remote node.
|
|||
type remoteBMS struct { |
|||
*AuthRPCClient |
|||
} |
|||
|
|||
// remoteBMS.UpdateBucketNotification - sends bucket notification
|
|||
// change to remote peer via RPC call.
|
|||
func (rc *remoteBMS) UpdateBucketNotification(args *SetBNPArgs) error { |
|||
reply := GenericReply{} |
|||
err := rc.Call("S3.SetBucketNotificationPeer", args, &reply) |
|||
// Check for network error and retry once.
|
|||
if err != nil && err.Error() == rpc.ErrShutdown.Error() { |
|||
err = rc.Call("S3.SetBucketNotificationPeer", args, &reply) |
|||
} |
|||
return err |
|||
} |
|||
|
|||
// remoteBMS.UpdateBucketListener - sends bucket listener change to
|
|||
// remote peer via RPC call.
|
|||
func (rc *remoteBMS) UpdateBucketListener(args *SetBLPArgs) error { |
|||
reply := GenericReply{} |
|||
err := rc.Call("S3.SetBucketListenerPeer", args, &reply) |
|||
// Check for network error and retry once.
|
|||
if err != nil && err.Error() == rpc.ErrShutdown.Error() { |
|||
err = rc.Call("S3.SetBucketListenerPeer", args, &reply) |
|||
} |
|||
return err |
|||
} |
|||
|
|||
// remoteBMS.UpdateBucketPolicy - sends bucket policy change to remote
|
|||
// peer via RPC call.
|
|||
func (rc *remoteBMS) UpdateBucketPolicy(args *SetBPPArgs) error { |
|||
reply := GenericReply{} |
|||
err := rc.Call("S3.SetBucketPolicyPeer", args, &reply) |
|||
// Check for network error and retry once.
|
|||
if err != nil && err.Error() == rpc.ErrShutdown.Error() { |
|||
err = rc.Call("S3.SetBucketPolicyPeer", args, &reply) |
|||
} |
|||
return err |
|||
} |
|||
|
|||
// remoteBMS.SendEvent - sends event for bucket listener to remote
|
|||
// peer via RPC call.
|
|||
func (rc *remoteBMS) SendEvent(args *EventArgs) error { |
|||
reply := GenericReply{} |
|||
err := rc.Call("S3.Event", args, &reply) |
|||
// Check for network error and retry once.
|
|||
if err != nil && err.Error() == rpc.ErrShutdown.Error() { |
|||
err = rc.Call("S3.Event", args, &reply) |
|||
} |
|||
return err |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue