mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
git-svn-id: https://weed-fs.googlecode.com/svn/trunk@5 282b0af5-e82d-9cf1-ede4-77906d7719d0
This commit is contained in:
parent
da97f86447
commit
70be76735c
|
@ -97,7 +97,11 @@ func dirWriteHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
func dirJoinHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
s := r.FormValue("server")
|
||||
publicServer := r.FormValue("publicServer")
|
||||
volumes := make([]store.VolumeStat,0)
|
||||
json.Unmarshal([]byte(r.FormValue("volumes")), volumes)
|
||||
server.directory.Add(directory.NewMachine(s,publicServer),volumes)
|
||||
}
|
||||
|
||||
var server *Haystack
|
||||
|
|
|
@ -5,15 +5,24 @@ import (
|
|||
"os"
|
||||
"rand"
|
||||
"log"
|
||||
"store"
|
||||
)
|
||||
|
||||
type Machine struct {
|
||||
Server string //<server name/ip>[:port]
|
||||
Server string //<server name/ip>[:port]
|
||||
PublicServer string
|
||||
}
|
||||
|
||||
func NewMachine(server, publicServer string) (m *Machine) {
|
||||
m = new(Machine)
|
||||
m.Server, m.PublicServer = server, publicServer
|
||||
return
|
||||
}
|
||||
|
||||
type Mapper struct {
|
||||
dir string
|
||||
fileName string
|
||||
Virtual2physical map[uint32][]Machine
|
||||
Virtual2physical map[uint32][]*Machine
|
||||
}
|
||||
|
||||
func NewMapper(dirname string, filename string) (m *Mapper) {
|
||||
|
@ -25,22 +34,34 @@ func NewMapper(dirname string, filename string) (m *Mapper) {
|
|||
if e != nil {
|
||||
log.Fatalf("Mapping File Read [ERROR] %s\n", e)
|
||||
} else {
|
||||
m.Virtual2physical = make(map[uint32][]Machine)
|
||||
m.Virtual2physical = make(map[uint32][]*Machine)
|
||||
decoder := gob.NewDecoder(dataFile)
|
||||
decoder.Decode(m.Virtual2physical)
|
||||
dataFile.Close()
|
||||
dataFile.Close()
|
||||
}
|
||||
return
|
||||
}
|
||||
func (m *Mapper) PickForWrite() []Machine {
|
||||
vid := uint32(rand.Intn(len(m.Virtual2physical)))
|
||||
return m.Virtual2physical[vid]
|
||||
}
|
||||
func (m *Mapper) Get(vid uint32) []Machine {
|
||||
func (m *Mapper) PickForWrite() []*Machine {
|
||||
vid := uint32(rand.Intn(len(m.Virtual2physical)))
|
||||
return m.Virtual2physical[vid]
|
||||
}
|
||||
func (m *Mapper) Add(vid uint32, pids ...Machine) {
|
||||
m.Virtual2physical[vid] = append(m.Virtual2physical[vid], pids...)
|
||||
func (m *Mapper) Get(vid uint32) []*Machine {
|
||||
return m.Virtual2physical[vid]
|
||||
}
|
||||
func (m *Mapper) Add(machine *Machine, volumes []store.VolumeStat) {
|
||||
for _, v := range volumes {
|
||||
existing := m.Virtual2physical[uint32(v.Id)]
|
||||
found := false
|
||||
for _, entry := range existing {
|
||||
if machine == entry {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
m.Virtual2physical[uint32(v.Id)] = append(existing, machine)
|
||||
}
|
||||
}
|
||||
}
|
||||
func (m *Mapper) Save() {
|
||||
log.Println("Saving virtual to physical:", m.dir, "/", m.fileName)
|
||||
|
@ -49,7 +70,7 @@ func (m *Mapper) Save() {
|
|||
log.Fatalf("Mapping File Save [ERROR] %s\n", e)
|
||||
}
|
||||
defer dataFile.Close()
|
||||
m.Virtual2physical = make(map[uint32][]Machine)
|
||||
m.Virtual2physical = make(map[uint32][]*Machine)
|
||||
encoder := gob.NewEncoder(dataFile)
|
||||
encoder.Encode(m.Virtual2physical)
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ func (s *Store) Join(mserver string) {
|
|||
values.Add("server", s.Server)
|
||||
values.Add("publicServer", s.PublicServer)
|
||||
values.Add("volumes", string(bytes))
|
||||
post("http://"+mserver+"/join", *values)
|
||||
post("http://"+mserver+"/dir/join", *values)
|
||||
}
|
||||
func (s *Store) Close() {
|
||||
for _, v := range s.volumes {
|
||||
|
|
Loading…
Reference in a new issue