adjusting return messages for growing volumes

This commit is contained in:
Chris Lu
2012-09-16 23:18:47 -07:00
parent 15ced2398e
commit 4846a7232e
6 changed files with 69 additions and 41 deletions

View File

@@ -30,7 +30,11 @@ func NewStore(port int, publicUrl, dirname string, maxVolumeCount int, volumeLis
log.Println("Store started on dir:", dirname, "with", len(s.volumes), "volumes", volumeListString)
return
}
func (s *Store) AddVolume(volumeListString string, replicationType string) (e error) {
func (s *Store) AddVolume(volumeListString string, replicationType string) (error) {
rt, e := NewReplicationType(replicationType)
if e!=nil {
return e
}
for _, range_string := range strings.Split(volumeListString, ",") {
if strings.Index(range_string, "-") < 0 {
id_string := range_string
@@ -38,7 +42,7 @@ func (s *Store) AddVolume(volumeListString string, replicationType string) (e er
if err != nil {
return errors.New("Volume Id " + id_string + " is not a valid unsigned integer!")
}
e = s.addVolume(VolumeId(id), NewReplicationType(replicationType))
e = s.addVolume(VolumeId(id), rt)
} else {
pair := strings.Split(range_string, "-")
start, start_err := strconv.ParseUint(pair[0], 10, 64)
@@ -50,7 +54,7 @@ func (s *Store) AddVolume(volumeListString string, replicationType string) (e er
return errors.New("Volume End Id" + pair[1] + " is not a valid unsigned integer!")
}
for id := start; id <= end; id++ {
if err := s.addVolume(VolumeId(id), NewReplicationType(replicationType)); err != nil {
if err := s.addVolume(VolumeId(id), rt); err != nil {
e = err
}
}

View File

@@ -1,6 +1,8 @@
package storage
import ()
import (
"errors"
)
type VolumeInfo struct {
Id VolumeId
@@ -19,20 +21,20 @@ const (
CopyNil = ReplicationType(255) // nil value
)
func NewReplicationType(t string) ReplicationType {
func NewReplicationType(t string) (ReplicationType, error) {
switch t {
case "00":
return Copy00
return Copy00, nil
case "01":
return Copy01
return Copy01, nil
case "10":
return Copy10
return Copy10, nil
case "11":
return Copy11
return Copy11, nil
case "20":
return Copy20
return Copy20, nil
}
return Copy00
return Copy00, errors.New("Unknown Replication Type:"+t)
}
func (r *ReplicationType) String() string {
switch *r {
@@ -50,7 +52,7 @@ func (r *ReplicationType) String() string {
return "00"
}
func GetReplicationLevelIndex(repType ReplicationType) int {
func (repType ReplicationType)GetReplicationLevelIndex() int {
switch repType {
case Copy00:
return 0
@@ -65,7 +67,7 @@ func GetReplicationLevelIndex(repType ReplicationType) int {
}
return -1
}
func GetCopyCount(repType ReplicationType) int {
func (repType ReplicationType)GetCopyCount() int {
switch repType {
case Copy00:
return 1