simplifying volume id mechanism, removing automatic volume id generation and discovering

periodically report machine status

git-svn-id: https://weed-fs.googlecode.com/svn/trunk@25 282b0af5-e82d-9cf1-ede4-77906d7719d0
This commit is contained in:
chris.lu@gmail.com committed 2011-12-26 09:43:17 +00:00
1 parent ae3a53388f
commit 6913fabc64
4 files changed
+99 -149

No files matched your search

+39 -40
View File
@@ -2,7 +2,6 @@ package storage
import (
"log"
"io/ioutil"
"json"
"os"
"strings"
@@ -13,7 +12,6 @@ import (
type Store struct {
volumes map[uint64]*Volume
capacity int
dir string
Port int
PublicServer string
@@ -23,35 +21,48 @@ type VolumeInfo struct {
Size int64
}
func NewStore(port int, publicServer, dirname string, chunkSize, capacity int) (s *Store) {
s = &Store{Port: port, PublicServer: publicServer, dir: dirname, capacity: capacity}
func NewStore(port int, publicServer, dirname string, volumeListString string) (s *Store) {
s = &Store{Port: port, PublicServer: publicServer, dir: dirname}
s.volumes = make(map[uint64]*Volume)
files, _ := ioutil.ReadDir(dirname)
for _, f := range files {
if f.IsDirectory() || !strings.HasSuffix(f.Name, ".dat") {
continue
for _, range_string := range strings.Split(volumeListString, ",") {
if strings.Index(range_string, "-") < 0 {
id_string := range_string
id, err := strconv.Atoui64(id_string)
if err != nil {
log.Println("Volume Id", id_string, "is not a valid unsigned integer! Skipping it...")
continue
}
s.volumes[id] = NewVolume(s.dir, uint32(id))
} else {
pair := strings.Split(range_string, "-")
start, start_err := strconv.Atoui64(pair[0])
if start_err != nil {
log.Println("Volume Id", pair[0], "is not a valid unsigned integer! Skipping it...")
continue
}
end, end_err := strconv.Atoui64(pair[1])
if end_err != nil {
log.Println("Volume Id", pair[1], "is not a valid unsigned integer! Skipping it...")
continue
}
for id := start; id<=end; id++ {
s.volumes[id] = NewVolume(s.dir, uint32(id))
}
}
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[id] = NewVolume(s.dir, uint32(id))
}
log.Println("Store started on dir:", dirname, "with", len(s.volumes), "existing volumes")
log.Println("Expected capacity=", s.capacity, "volumes")
return
}
func (s *Store) Status()(*[]*VolumeInfo){
stats := new([]*VolumeInfo)
for k, v := range s.volumes {
s := new(VolumeInfo)
s.Id, s.Size = uint32(k), v.Size()
*stats = append(*stats, s)
}
return stats
func (s *Store) Status() *[]*VolumeInfo {
stats := new([]*VolumeInfo)
for k, v := range s.volumes {
s := new(VolumeInfo)
s.Id, s.Size = uint32(k), v.Size()
*stats = append(*stats, s)
}
return stats
}
func (s *Store) Join(mserver string) {
stats := new([]*VolumeInfo)
@@ -65,29 +76,17 @@ func (s *Store) Join(mserver string) {
values.Add("port", strconv.Itoa(s.Port))
values.Add("publicServer", s.PublicServer)
values.Add("volumes", string(bytes))
log.Println("Registering exiting volumes", string(bytes))
values.Add("capacity", strconv.Itoa(s.capacity))
retString := util.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, uint32(vid))
log.Println("Adding volume", vid)
}
}
}
log.Println("Exiting volumes", string(bytes))
util.Post("http://"+mserver+"/dir/join", values)
}
func (s *Store) Close() {
for _, v := range s.volumes {
v.Close()
}
}
func (s *Store) Write(i uint64, n *Needle) (uint32){
func (s *Store) Write(i uint64, n *Needle) uint32 {
return s.volumes[i].write(n)
}
func (s *Store) Read(i uint64, n *Needle) (int, os.Error){
func (s *Store) Read(i uint64, n *Needle) (int, os.Error) {
return s.volumes[i].read(n)
}