mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-05-04 05:27:48 +08: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) {
|
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
|
var server *Haystack
|
||||||
|
@ -5,15 +5,24 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"rand"
|
"rand"
|
||||||
"log"
|
"log"
|
||||||
|
"store"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Machine struct {
|
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 {
|
type Mapper struct {
|
||||||
dir string
|
dir string
|
||||||
fileName string
|
fileName string
|
||||||
Virtual2physical map[uint32][]Machine
|
Virtual2physical map[uint32][]*Machine
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMapper(dirname string, filename string) (m *Mapper) {
|
func NewMapper(dirname string, filename string) (m *Mapper) {
|
||||||
@ -25,22 +34,34 @@ func NewMapper(dirname string, filename string) (m *Mapper) {
|
|||||||
if e != nil {
|
if e != nil {
|
||||||
log.Fatalf("Mapping File Read [ERROR] %s\n", e)
|
log.Fatalf("Mapping File Read [ERROR] %s\n", e)
|
||||||
} else {
|
} else {
|
||||||
m.Virtual2physical = make(map[uint32][]Machine)
|
m.Virtual2physical = make(map[uint32][]*Machine)
|
||||||
decoder := gob.NewDecoder(dataFile)
|
decoder := gob.NewDecoder(dataFile)
|
||||||
decoder.Decode(m.Virtual2physical)
|
decoder.Decode(m.Virtual2physical)
|
||||||
dataFile.Close()
|
dataFile.Close()
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (m *Mapper) PickForWrite() []Machine {
|
func (m *Mapper) PickForWrite() []*Machine {
|
||||||
vid := uint32(rand.Intn(len(m.Virtual2physical)))
|
vid := uint32(rand.Intn(len(m.Virtual2physical)))
|
||||||
return m.Virtual2physical[vid]
|
|
||||||
}
|
|
||||||
func (m *Mapper) Get(vid uint32) []Machine {
|
|
||||||
return m.Virtual2physical[vid]
|
return m.Virtual2physical[vid]
|
||||||
}
|
}
|
||||||
func (m *Mapper) Add(vid uint32, pids ...Machine) {
|
func (m *Mapper) Get(vid uint32) []*Machine {
|
||||||
m.Virtual2physical[vid] = append(m.Virtual2physical[vid], pids...)
|
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() {
|
func (m *Mapper) Save() {
|
||||||
log.Println("Saving virtual to physical:", m.dir, "/", m.fileName)
|
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)
|
log.Fatalf("Mapping File Save [ERROR] %s\n", e)
|
||||||
}
|
}
|
||||||
defer dataFile.Close()
|
defer dataFile.Close()
|
||||||
m.Virtual2physical = make(map[uint32][]Machine)
|
m.Virtual2physical = make(map[uint32][]*Machine)
|
||||||
encoder := gob.NewEncoder(dataFile)
|
encoder := gob.NewEncoder(dataFile)
|
||||||
encoder.Encode(m.Virtual2physical)
|
encoder.Encode(m.Virtual2physical)
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ func (s *Store) Join(mserver string) {
|
|||||||
values.Add("server", s.Server)
|
values.Add("server", s.Server)
|
||||||
values.Add("publicServer", s.PublicServer)
|
values.Add("publicServer", s.PublicServer)
|
||||||
values.Add("volumes", string(bytes))
|
values.Add("volumes", string(bytes))
|
||||||
post("http://"+mserver+"/join", *values)
|
post("http://"+mserver+"/dir/join", *values)
|
||||||
}
|
}
|
||||||
func (s *Store) Close() {
|
func (s *Store) Close() {
|
||||||
for _, v := range s.volumes {
|
for _, v := range s.volumes {
|
||||||
|
Loading…
Reference in New Issue
Block a user