You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
942 B
41 lines
942 B
package donut
|
|
|
|
import (
|
|
"errors"
|
|
"github.com/minio-io/iodine"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
type donutBucket struct {
|
|
nodes []string
|
|
objects map[string][]byte
|
|
}
|
|
|
|
// GetNodes - get list of associated nodes for a given bucket
|
|
func (b donutBucket) GetNodes() ([]string, error) {
|
|
var nodes []string
|
|
for _, node := range b.nodes {
|
|
nodes = append(nodes, node)
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// AddNode - adds a node to a bucket
|
|
func (b donutBucket) AddNode(nodeID, bucketID string) error {
|
|
errParams := map[string]string{"node": nodeID, "bucketID": bucketID}
|
|
tokens := strings.Split(bucketID, ":")
|
|
if len(tokens) != 3 {
|
|
return iodine.New(errors.New("Bucket ID malformeD: "+bucketID), errParams)
|
|
|
|
}
|
|
// bucketName := tokens[0]
|
|
// aggregate := tokens[1]
|
|
// aggregate := "0"
|
|
part, err := strconv.Atoi(tokens[2])
|
|
if err != nil {
|
|
return iodine.New(errors.New("Part malformed: "+tokens[2]), errParams)
|
|
}
|
|
b.nodes[part] = nodeID
|
|
return nil
|
|
}
|
|
|