Browse Source

git-svn-id: https://weed-fs.googlecode.com/svn/trunk@6 282b0af5-e82d-9cf1-ede4-77906d7719d0

pull/2/head
chris.lu@gmail.com 13 years ago
parent
commit
2858701e6c
  1. 22
      weed-fs/src/cmd/gstore.go
  2. 5
      weed-fs/src/pkg/directory/volume_mapping.go
  3. 4
      weed-fs/src/pkg/store/store.go

22
weed-fs/src/cmd/gstore.go

@ -9,10 +9,10 @@ import (
"json"
"log"
"mime"
"os"
"rand"
"strconv"
"strings"
"time"
)
var (
@ -99,35 +99,41 @@ 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)
volumes := make([]store.VolumeStat, 0)
json.Unmarshal([]byte(r.FormValue("volumes")), volumes)
server.directory.Add(directory.NewMachine(s,publicServer),volumes)
server.directory.Add(directory.NewMachine(s, publicServer), volumes)
}
var server *Haystack
func main() {
flag.Parse()
bothEnabled := false
if !*chunkEnabled && !*metaEnabled {
fmt.Fprintf(os.Stdout, "Act as both a store server and a directory server\n")
bothEnabled = true
log.Println("Act as both a store server and a directory server")
}
server = new(Haystack)
if *chunkEnabled {
fmt.Fprintf(os.Stdout, "Chunk data stored in %s\n", *chunkFolder)
if *chunkEnabled || bothEnabled {
log.Println("Chunk data stored in", *chunkFolder)
server.store = store.NewStore(*chunkServer, *publicServer, *chunkFolder)
defer server.store.Close()
http.HandleFunc("/", storeHandler)
}
if *metaEnabled {
if *metaEnabled || bothEnabled {
server.directory = directory.NewMapper(*metaFolder, "directory")
defer server.directory.Save()
http.HandleFunc("/dir/read", dirReadHandler)
http.HandleFunc("/dir/write", dirWriteHandler)
http.HandleFunc("/dir/join", dirJoinHandler)
}
go func() {
time.Sleep(3000 * 1000)
server.store.Join(*metaServer)
log.Println("stored joined at", *metaServer)
}()
log.Println("Serving at http://127.0.0.1:" + strconv.Itoa(*port))
http.ListenAndServe(":"+strconv.Itoa(*port), nil)
}

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

@ -31,10 +31,10 @@ func NewMapper(dirname string, filename string) (m *Mapper) {
m.fileName = filename
log.Println("Loading virtual to physical:", m.dir, "/", m.fileName)
dataFile, e := os.OpenFile(m.dir+string(os.PathSeparator)+m.fileName+".map", os.O_RDONLY, 0644)
m.Virtual2physical = make(map[uint32][]*Machine)
if e != nil {
log.Fatalf("Mapping File Read [ERROR] %s\n", e)
log.Println("Mapping File Read [ERROR]", e)
} else {
m.Virtual2physical = make(map[uint32][]*Machine)
decoder := gob.NewDecoder(dataFile)
decoder.Decode(m.Virtual2physical)
dataFile.Close()
@ -61,6 +61,7 @@ func (m *Mapper) Add(machine *Machine, volumes []store.VolumeStat) {
if !found {
m.Virtual2physical[uint32(v.Id)] = append(existing, machine)
}
log.Println(v.Id, "=>", machine.Server)
}
}
func (m *Mapper) Save() {

4
weed-fs/src/pkg/store/store.go

@ -50,11 +50,11 @@ func (s *Store) Join(mserver string) {
stats = append(stats, s)
}
bytes, _ := json.Marshal(stats)
values := new(url.Values)
values := make(url.Values)
values.Add("server", s.Server)
values.Add("publicServer", s.PublicServer)
values.Add("volumes", string(bytes))
post("http://"+mserver+"/dir/join", *values)
post("http://"+mserver+"/dir/join", values)
}
func (s *Store) Close() {
for _, v := range s.volumes {

Loading…
Cancel
Save