aboutsummaryrefslogtreecommitdiff
path: root/weed-fs/src/pkg
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2012-09-26 01:55:56 -0700
committerChris Lu <chris.lu@gmail.com>2012-09-26 01:55:56 -0700
commit7ee12f14a883b96de4b056ae81b9dd3560befa58 (patch)
tree1075dce52f397bc076b0e883dd7ae1bc2a508476 /weed-fs/src/pkg
parent019173b1cccc059d5cda3e7cf4ca6cd9dd1d4f89 (diff)
downloadseaweedfs-7ee12f14a883b96de4b056ae81b9dd3560befa58.tar.xz
seaweedfs-7ee12f14a883b96de4b056ae81b9dd3560befa58.zip
add option to set server's ip address
Diffstat (limited to 'weed-fs/src/pkg')
-rw-r--r--weed-fs/src/pkg/operation/allocate_volume.go3
-rw-r--r--weed-fs/src/pkg/operation/lookup_volume_id.go2
-rw-r--r--weed-fs/src/pkg/storage/store.go22
-rw-r--r--weed-fs/src/pkg/topology/data_node.go7
-rw-r--r--weed-fs/src/pkg/util/post.go4
5 files changed, 21 insertions, 17 deletions
diff --git a/weed-fs/src/pkg/operation/allocate_volume.go b/weed-fs/src/pkg/operation/allocate_volume.go
index 771ec40eb..6a3512896 100644
--- a/weed-fs/src/pkg/operation/allocate_volume.go
+++ b/weed-fs/src/pkg/operation/allocate_volume.go
@@ -7,7 +7,6 @@ import (
"pkg/storage"
"pkg/topology"
"pkg/util"
- "strconv"
)
type AllocateVolumeResult struct {
@@ -18,7 +17,7 @@ func AllocateVolume(dn *topology.DataNode, vid storage.VolumeId, repType storage
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)
+ jsonBlob, err := util.Post("http://"+dn.Url()+"/admin/assign_volume", values)
if err != nil {
return err
}
diff --git a/weed-fs/src/pkg/operation/lookup_volume_id.go b/weed-fs/src/pkg/operation/lookup_volume_id.go
index 720286c31..c46c6670e 100644
--- a/weed-fs/src/pkg/operation/lookup_volume_id.go
+++ b/weed-fs/src/pkg/operation/lookup_volume_id.go
@@ -11,7 +11,7 @@ import (
type Location struct {
Url string "url"
- PublicUrl string "publicUrl"
+ PublicUrl string "publicUrl"
}
type LookupResult struct {
Locations []Location "locations"
diff --git a/weed-fs/src/pkg/storage/store.go b/weed-fs/src/pkg/storage/store.go
index 9e7bed192..b8337d51f 100644
--- a/weed-fs/src/pkg/storage/store.go
+++ b/weed-fs/src/pkg/storage/store.go
@@ -15,23 +15,24 @@ type Store struct {
volumes map[VolumeId]*Volume
dir string
Port int
+ Ip string
PublicUrl string
MaxVolumeCount int
}
-func NewStore(port int, publicUrl, dirname string, maxVolumeCount int) (s *Store) {
- s = &Store{Port: port, PublicUrl: publicUrl, dir: dirname, MaxVolumeCount: maxVolumeCount}
+func NewStore(port int, ip, publicUrl, dirname string, maxVolumeCount int) (s *Store) {
+ s = &Store{Port: port, Ip: ip, PublicUrl: publicUrl, dir: dirname, MaxVolumeCount: maxVolumeCount}
s.volumes = make(map[VolumeId]*Volume)
s.loadExistingVolumes()
log.Println("Store started on dir:", dirname, "with", len(s.volumes), "volumes")
return
}
-func (s *Store) AddVolume(volumeListString string, replicationType string) (error) {
- rt, e := NewReplicationType(replicationType)
- if e!=nil {
- return e
- }
+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
@@ -103,6 +104,7 @@ func (s *Store) Join(mserver string) error {
bytes, _ := json.Marshal(stats)
values := make(url.Values)
values.Add("port", strconv.Itoa(s.Port))
+ values.Add("ip", s.Ip)
values.Add("publicUrl", s.PublicUrl)
values.Add("volumes", string(bytes))
values.Add("maxVolumeCount", strconv.Itoa(s.MaxVolumeCount))
@@ -133,10 +135,10 @@ func (s *Store) Read(i VolumeId, n *Needle) (int, error) {
return 0, errors.New("Not Found")
}
func (s *Store) GetVolume(i VolumeId) *Volume {
- return s.volumes[i]
+ return s.volumes[i]
}
func (s *Store) HasVolume(i VolumeId) bool {
- _, ok := s.volumes[i]
- return ok
+ _, ok := s.volumes[i]
+ return ok
}
diff --git a/weed-fs/src/pkg/topology/data_node.go b/weed-fs/src/pkg/topology/data_node.go
index cfdae45c3..0410df5f6 100644
--- a/weed-fs/src/pkg/topology/data_node.go
+++ b/weed-fs/src/pkg/topology/data_node.go
@@ -3,6 +3,7 @@ package topology
import (
_ "fmt"
"pkg/storage"
+ "strconv"
)
type DataNode struct {
@@ -43,11 +44,13 @@ func (dn *DataNode) GetTopology() *Topology {
func (dn *DataNode) MatchLocation(ip string, port int) bool {
return dn.Ip == ip && dn.Port == port
}
+func (dn *DataNode) Url() string {
+ return dn.Ip + strconv.Itoa(dn.Port)
+}
func (dn *DataNode) ToMap() interface{} {
ret := make(map[string]interface{})
- ret["Ip"] = dn.Ip
- ret["Port"] = dn.Port
+ ret["Url"] = dn.Url()
ret["Volumes"] = dn.GetActiveVolumeCount()
ret["Max"] = dn.GetMaxVolumeCount()
ret["Free"] = dn.FreeSpace()
diff --git a/weed-fs/src/pkg/util/post.go b/weed-fs/src/pkg/util/post.go
index 357b42185..f643faa6b 100644
--- a/weed-fs/src/pkg/util/post.go
+++ b/weed-fs/src/pkg/util/post.go
@@ -10,13 +10,13 @@ import (
func Post(url string, values url.Values) ([]byte, error) {
r, err := http.PostForm(url, values)
if err != nil {
- log.Println("post:", err)
+ log.Println("post to", url, err)
return nil, err
}
defer r.Body.Close()
b, err := ioutil.ReadAll(r.Body)
if err != nil {
- log.Println("post:", err)
+ log.Println("read post result from", url, err)
return nil, err
}
return b, nil