replication related work
This commit is contained in:
31
weed-fs/src/pkg/admin/storage.go
Normal file
31
weed-fs/src/pkg/admin/storage.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strconv"
|
||||
"net/url"
|
||||
"pkg/util"
|
||||
"pkg/storage"
|
||||
"pkg/topology"
|
||||
)
|
||||
|
||||
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 := util.Post("http://"+dn.Ip+":"+strconv.Itoa(dn.Port)+"/admin/assign_volume", values)
|
||||
var ret AllocateVolumeResult
|
||||
err := json.Unmarshal(jsonBlob, &ret)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if ret.error != "" {
|
||||
return errors.New(ret.error)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -33,6 +33,21 @@ func NewReplicationType(t string) ReplicationType {
|
||||
}
|
||||
return Copy00
|
||||
}
|
||||
func (r *ReplicationType) String() string {
|
||||
switch *r {
|
||||
case Copy00:
|
||||
return "00"
|
||||
case Copy01:
|
||||
return "01"
|
||||
case Copy10:
|
||||
return "10"
|
||||
case Copy11:
|
||||
return "11"
|
||||
case Copy20:
|
||||
return "20"
|
||||
}
|
||||
return "00"
|
||||
}
|
||||
|
||||
func GetReplicationLevelIndex(v *VolumeInfo) int {
|
||||
switch v.RepType {
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
type DataNode struct {
|
||||
NodeImpl
|
||||
volumes map[storage.VolumeId]*storage.VolumeInfo
|
||||
ip string
|
||||
port int
|
||||
publicUrl string
|
||||
Ip string
|
||||
Port int
|
||||
PublicUrl string
|
||||
lastSeen int64 // unix time in seconds
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ func NewDataNodeLocationList() *DataNodeLocationList {
|
||||
|
||||
func (dnll *DataNodeLocationList) Add(loc *DataNode) {
|
||||
for _, dnl := range dnll.list {
|
||||
if loc.ip == dnl.ip && loc.port == dnl.port {
|
||||
if loc.Ip == dnl.Ip && loc.Port == dnl.Port {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user