remote assigns volume to volume server

This commit is contained in:
Chris Lu 2012-09-13 00:04:56 -07:00
parent 4a7833f1bf
commit 9e0f8d9f0d
5 changed files with 32 additions and 11 deletions

View file

@ -65,6 +65,7 @@ Plan:
For the above operations, here are the todo list:
for data node:
0. detect existing volumes
1. onStartUp, and periodically, send existing volumes and maxVolumeCount store.Join(), DONE
2. accept command to grow a volume( id + replication level) DONE
/admin/assign_volume?volume=some_id&replicationType=01

View file

@ -40,15 +40,15 @@ func statusHandler(w http.ResponseWriter, r *http.Request) {
writeJson(w, r, store.Status())
}
func assignVolumeHandler(w http.ResponseWriter, r *http.Request) {
if *IsDebug {
log.Println("volume =", r.FormValue("volume"), ", replicationType =", r.FormValue("replicationType"))
}
err := store.AddVolume(r.FormValue("volume"), r.FormValue("replicationType"))
if err == nil {
writeJson(w, r, map[string]string{"error": ""})
} else {
writeJson(w, r, map[string]string{"error": err.Error()})
}
if *IsDebug {
log.Println("volume =", r.FormValue("volume"), ", replicationType =", r.FormValue("replicationType"), ", error =", err)
}
}
func setVolumeLocationsHandler(w http.ResponseWriter, r *http.Request) {
if *IsDebug {

View file

@ -11,7 +11,7 @@ import (
)
type AllocateVolumeResult struct {
error string
Error string
}
func AllocateVolume(dn *topology.DataNode, vid storage.VolumeId, repType storage.ReplicationType) error{
@ -24,8 +24,8 @@ func AllocateVolume(dn *topology.DataNode, vid storage.VolumeId, repType storage
if err != nil {
return err
}
if ret.error != "" {
return errors.New(ret.error)
if ret.Error != "" {
return errors.New(ret.Error)
}
return nil
}

View file

@ -0,0 +1,17 @@
package admin
import (
"log"
"pkg/storage"
"pkg/topology"
"testing"
)
func TestXYZ(t *testing.T) {
dn := topology.NewDataNode("server1")
dn.Ip = "localhost"
dn.Port = 8080
vid, _:= storage.NewVolumeId("5")
out := AllocateVolume(dn,vid,storage.Copy00)
log.Println(out)
}

View file

@ -24,10 +24,10 @@ func NewStore(port int, publicUrl, dirname string, volumeListString string) (s *
s.AddVolume(volumeListString, "00")
log.Println("Store started on dir:", dirname, "with", len(s.volumes), "volumes")
log.Println("Store started on dir:", dirname, "with", len(s.volumes), "volumes", volumeListString)
return
}
func (s *Store) AddVolume(volumeListString string, replicationType string) error {
func (s *Store) AddVolume(volumeListString string, replicationType string) (e error) {
for _, range_string := range strings.Split(volumeListString, ",") {
if strings.Index(range_string, "-") < 0 {
id_string := range_string
@ -35,7 +35,7 @@ func (s *Store) AddVolume(volumeListString string, replicationType string) error
if err != nil {
return errors.New("Volume Id " + id_string + " is not a valid unsigned integer!")
}
s.addVolume(VolumeId(id), NewReplicationType(replicationType))
e = s.addVolume(VolumeId(id), NewReplicationType(replicationType))
} else {
pair := strings.Split(range_string, "-")
start, start_err := strconv.ParseUint(pair[0], 10, 64)
@ -47,16 +47,19 @@ func (s *Store) AddVolume(volumeListString string, replicationType string) error
return errors.New("Volume End Id" + pair[1] + " is not a valid unsigned integer!")
}
for id := start; id <= end; id++ {
s.addVolume(VolumeId(id), NewReplicationType(replicationType))
if err := s.addVolume(VolumeId(id), NewReplicationType(replicationType)); err != nil {
e = err
}
}
}
}
return nil
return e
}
func (s *Store) addVolume(vid VolumeId, replicationType ReplicationType) error {
if s.volumes[vid] != nil {
return errors.New("Volume Id " + vid.String() + " already exists!")
}
log.Println("In dir", s.dir, "adds volume = ", vid, ", replicationType =", replicationType)
s.volumes[vid] = NewVolume(s.dir, vid, replicationType)
return nil
}