|
@ -1,15 +1,12 @@ |
|
|
package replication |
|
|
package replication |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"encoding/json" |
|
|
|
|
|
"errors" |
|
|
"errors" |
|
|
"fmt" |
|
|
"fmt" |
|
|
"math/rand" |
|
|
"math/rand" |
|
|
"net/url" |
|
|
|
|
|
"pkg/storage" |
|
|
"pkg/storage" |
|
|
"pkg/topology" |
|
|
"pkg/topology" |
|
|
"pkg/util" |
|
|
|
|
|
"strconv" |
|
|
|
|
|
|
|
|
"pkg/operation" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
@ -125,7 +122,7 @@ func (vg *VolumeGrowth) GrowByCountAndType(count int, repType storage.Replicatio |
|
|
} |
|
|
} |
|
|
func (vg *VolumeGrowth) grow(topo *topology.Topology, vid storage.VolumeId, repType storage.ReplicationType, servers ...*topology.DataNode) error { |
|
|
func (vg *VolumeGrowth) grow(topo *topology.Topology, vid storage.VolumeId, repType storage.ReplicationType, servers ...*topology.DataNode) error { |
|
|
for _, server := range servers { |
|
|
for _, server := range servers { |
|
|
if err := AllocateVolume(server, vid, repType); err == nil { |
|
|
|
|
|
|
|
|
if err := operation.AllocateVolume(server, vid, repType); err == nil { |
|
|
vi := storage.VolumeInfo{Id: vid, Size: 0, RepType:repType} |
|
|
vi := storage.VolumeInfo{Id: vid, Size: 0, RepType:repType} |
|
|
server.AddOrUpdateVolume(vi) |
|
|
server.AddOrUpdateVolume(vi) |
|
|
topo.RegisterVolumeLayout(&vi, server) |
|
|
topo.RegisterVolumeLayout(&vi, server) |
|
@ -137,25 +134,3 @@ func (vg *VolumeGrowth) grow(topo *topology.Topology, vid storage.VolumeId, repT |
|
|
} |
|
|
} |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type AllocateVolumeResult struct { |
|
|
|
|
|
Error string |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func AllocateVolume(dn *topology.DataNode, vid storage.VolumeId, repType storage.ReplicationType) error { |
|
|
|
|
|
values := make(url.Values) |
|
|
|
|
|
values.Add("volume", vid.String()) |
|
|
|
|
|
values.Add("replicationType", repType.String()) |
|
|
|
|
|
jsonBlob, err := util.Post("http://"+dn.Ip+":"+strconv.Itoa(dn.Port)+"/admin/assign_volume", values) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
var ret AllocateVolumeResult |
|
|
|
|
|
if err := json.Unmarshal(jsonBlob, &ret); err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
if ret.Error != "" { |
|
|
|
|
|
return errors.New(ret.Error) |
|
|
|
|
|
} |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|