aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2012-09-20 18:02:56 -0700
committerChris Lu <chris.lu@gmail.com>2012-09-20 18:02:56 -0700
commit08dcf2f03568296b4d6e8fe9073c0e6c2339812c (patch)
treea2d477f1e931586825c899321e5b34ce82fe2f3e
parent5e97179d061fd885ab5df0d91c1713a5139ca112 (diff)
downloadseaweedfs-08dcf2f03568296b4d6e8fe9073c0e6c2339812c.tar.xz
seaweedfs-08dcf2f03568296b4d6e8fe9073c0e6c2339812c.zip
refactoring allocate_volume operation
-rw-r--r--weed-fs/src/pkg/operation/allocate_volume.go33
-rw-r--r--weed-fs/src/pkg/replication/volume_growth.go29
2 files changed, 35 insertions, 27 deletions
diff --git a/weed-fs/src/pkg/operation/allocate_volume.go b/weed-fs/src/pkg/operation/allocate_volume.go
new file mode 100644
index 000000000..771ec40eb
--- /dev/null
+++ b/weed-fs/src/pkg/operation/allocate_volume.go
@@ -0,0 +1,33 @@
+package operation
+
+import (
+ "encoding/json"
+ "errors"
+ "net/url"
+ "pkg/storage"
+ "pkg/topology"
+ "pkg/util"
+ "strconv"
+)
+
+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
+}
diff --git a/weed-fs/src/pkg/replication/volume_growth.go b/weed-fs/src/pkg/replication/volume_growth.go
index 0176033d8..39597f2a6 100644
--- a/weed-fs/src/pkg/replication/volume_growth.go
+++ b/weed-fs/src/pkg/replication/volume_growth.go
@@ -1,15 +1,12 @@
package replication
import (
- "encoding/json"
"errors"
"fmt"
"math/rand"
- "net/url"
"pkg/storage"
"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 {
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}
server.AddOrUpdateVolume(vi)
topo.RegisterVolumeLayout(&vi, server)
@@ -137,25 +134,3 @@ func (vg *VolumeGrowth) grow(topo *topology.Topology, vid storage.VolumeId, repT
}
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
-}