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.
38 lines
762 B
38 lines
762 B
10 years ago
|
package donut
|
||
|
|
||
10 years ago
|
import (
|
||
|
"errors"
|
||
|
"strconv"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
10 years ago
|
type donutBucket struct {
|
||
10 years ago
|
nodes []string
|
||
|
objects map[string][]byte
|
||
|
}
|
||
|
|
||
10 years ago
|
// GetNodes - get list of associated nodes for a given bucket
|
||
|
func (b donutBucket) GetNodes() ([]string, error) {
|
||
10 years ago
|
var nodes []string
|
||
10 years ago
|
for _, node := range b.nodes {
|
||
10 years ago
|
nodes = append(nodes, node)
|
||
|
}
|
||
|
return nodes, nil
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
func (b donutBucket) AddNode(nodeID, bucketID string) error {
|
||
10 years ago
|
tokens := strings.Split(bucketID, ":")
|
||
|
if len(tokens) != 3 {
|
||
|
return errors.New("Bucket ID malformed: " + bucketID)
|
||
|
}
|
||
|
// bucketName := tokens[0]
|
||
|
// aggregate := tokens[1]
|
||
|
// aggregate := "0"
|
||
|
part, err := strconv.Atoi(tokens[2])
|
||
|
if err != nil {
|
||
|
return errors.New("Part malformed: " + tokens[2])
|
||
|
}
|
||
|
b.nodes[part] = nodeID
|
||
|
return nil
|
||
|
}
|