Browse Source

handling lost servers

pull/2/head
Chris Lu 12 years ago
parent
commit
85a1b419c0
  1. 4
      weed-fs/src/cmd/weed/master.go
  2. 9
      weed-fs/src/pkg/directory/volume_mapping.go

4
weed-fs/src/cmd/weed/master.go

@ -55,7 +55,7 @@ func dirAssignHandler(w http.ResponseWriter, r *http.Request) {
if err == nil { if err == nil {
writeJson(w, r, map[string]interface{}{"fid": fid, "url": machine.Url, "publicUrl": machine.PublicUrl, "count": count}) writeJson(w, r, map[string]interface{}{"fid": fid, "url": machine.Url, "publicUrl": machine.PublicUrl, "count": count})
} else { } else {
writeJson(w, r, map[string]interface{}{"error": err})
writeJson(w, r, map[string]string{"error": err.Error()})
} }
} }
func dirJoinHandler(w http.ResponseWriter, r *http.Request) { func dirJoinHandler(w http.ResponseWriter, r *http.Request) {
@ -80,6 +80,8 @@ func runMaster(cmd *Command, args []string) bool {
http.HandleFunc("/dir/join", dirJoinHandler) http.HandleFunc("/dir/join", dirJoinHandler)
http.HandleFunc("/dir/status", dirStatusHandler) http.HandleFunc("/dir/status", dirStatusHandler)
mapper.StartRefreshWritableVolumes()
log.Println("Start directory service at http://127.0.0.1:" + strconv.Itoa(*mport)) log.Println("Start directory service at http://127.0.0.1:" + strconv.Itoa(*mport))
e := http.ListenAndServe(":"+strconv.Itoa(*mport), nil) e := http.ListenAndServe(":"+strconv.Itoa(*mport), nil)
if e != nil { if e != nil {

9
weed-fs/src/pkg/directory/volume_mapping.go

@ -76,6 +76,12 @@ func (m *Mapper) Add(machine *Machine) {
} }
m.refreshWritableVolumes() m.refreshWritableVolumes()
} }
func (m *Mapper) remove(machine *Machine) {
delete(m.Machines,machine.Url)
for _, v := range machine.Volumes {
delete(m.vid2machine,v.Id)
}
}
func (m *Mapper) StartRefreshWritableVolumes() { func (m *Mapper) StartRefreshWritableVolumes() {
go func() { go func() {
for { for {
@ -96,6 +102,9 @@ func (m *Mapper) refreshWritableVolumes() {
writers = append(writers, v.Id) writers = append(writers, v.Id)
} }
} }
} else {
log.Println("Warning! Server", machine_entry.Url, "last seen is", time.Now().Unix()-machine_entry.LastSeen, "seconds ago!")
m.remove(machine_entry)
} }
} }
m.Writers = writers m.Writers = writers

Loading…
Cancel
Save