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

This commit is contained in:
chris.lu@gmail.com
2011-12-17 06:47:23 +00:00
parent 25d0caa901
commit 10930ce6b6
6 changed files with 137 additions and 74 deletions

View File

@@ -11,50 +11,64 @@ import (
type Store struct {
volumes map[uint64]*Volume
capacity int
dir string
Port int
Port int
PublicServer string
}
type VolumeStat struct {
Id uint64 "id"
Status int "status" //0:read, 1:write
Id uint64 "id"
CanWrite bool
}
func NewStore(port int, publicServer, dirname string) (s *Store) {
func NewStore(port int, publicServer, dirname string, chunkSize, capacity int) (s *Store) {
s = new(Store)
s.Port, s.PublicServer, s.dir = port, publicServer, dirname
s.Port, s.PublicServer, s.dir, s.capacity = port, publicServer, dirname, capacity
s.volumes = make(map[uint64]*Volume)
counter := uint64(0)
files, _ := ioutil.ReadDir(dirname)
for _, f := range files {
if f.IsDirectory() || !strings.HasSuffix(f.Name, ".dat") {
continue
}
id, err := strconv.Atoui64(f.Name[:-4])
if err == nil {
id, err := strconv.Atoui64(f.Name[0:(strings.LastIndex(f.Name, ".dat"))])
log.Println("Loading data file name:", f.Name)
if err != nil {
continue
}
s.volumes[counter] = NewVolume(s.dir, id)
counter++
s.volumes[id] = NewVolume(s.dir, id)
}
log.Println("Store started on dir:", dirname, "with", counter, "existing volumes")
log.Println("Store started on dir:", dirname, "with", len(s.volumes), "existing volumes")
log.Println("Expected capacity=", s.capacity, "volumes")
return
}
func (s *Store) Join(mserver string) {
stats := make([]*VolumeStat, len(s.volumes))
stats := new([]*VolumeStat)
for k, _ := range s.volumes {
s := new(VolumeStat)
s.Id, s.Status = k, 1
stats = append(stats, s)
s.Id, s.CanWrite = k, true
*stats = append(*stats, s)
}
bytes, _ := json.Marshal(stats)
values := make(url.Values)
values.Add("port", strconv.Itoa(s.Port))
values.Add("publicServer", s.PublicServer)
values.Add("publicServer", s.PublicServer)
values.Add("volumes", string(bytes))
post("http://"+mserver+"/dir/join", values)
log.Println("Registering exiting volumes", string(bytes))
values.Add("capacity", strconv.Itoa(s.capacity))
retString := post("http://"+mserver+"/dir/join", values)
if retString != nil {
newVids := new([]int)
log.Println("Instructed to create volume",string(retString))
e := json.Unmarshal(retString, newVids)
if e == nil {
for _, vid := range *newVids {
s.volumes[uint64(vid)] = NewVolume(s.dir, uint64(vid))
log.Println("Adding volume", vid)
}
}
}
}
func (s *Store) Close() {
for _, v := range s.volumes {