|
@ -18,6 +18,10 @@ type Store struct { |
|
|
Ip string |
|
|
Ip string |
|
|
PublicUrl string |
|
|
PublicUrl string |
|
|
MaxVolumeCount int |
|
|
MaxVolumeCount int |
|
|
|
|
|
|
|
|
|
|
|
//read from the master
|
|
|
|
|
|
masterNode string |
|
|
|
|
|
volumeSizeLimit uint64 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func NewStore(port int, ip, publicUrl, dirname string, maxVolumeCount int) (s *Store) { |
|
|
func NewStore(port int, ip, publicUrl, dirname string, maxVolumeCount int) (s *Store) { |
|
@ -87,7 +91,7 @@ func (s *Store) CompactVolume(volumeIdString string) error { |
|
|
} |
|
|
} |
|
|
return s.volumes[vid].compact() |
|
|
return s.volumes[vid].compact() |
|
|
} |
|
|
} |
|
|
func (s *Store) CommitCompactVolume(volumeIdString string) (error) { |
|
|
|
|
|
|
|
|
func (s *Store) CommitCompactVolume(volumeIdString string) error { |
|
|
vid, err := NewVolumeId(volumeIdString) |
|
|
vid, err := NewVolumeId(volumeIdString) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return errors.New("Volume Id " + volumeIdString + " is not a valid unsigned integer!") |
|
|
return errors.New("Volume Id " + volumeIdString + " is not a valid unsigned integer!") |
|
@ -115,16 +119,24 @@ func (s *Store) Status() []*VolumeInfo { |
|
|
var stats []*VolumeInfo |
|
|
var stats []*VolumeInfo |
|
|
for k, v := range s.volumes { |
|
|
for k, v := range s.volumes { |
|
|
s := new(VolumeInfo) |
|
|
s := new(VolumeInfo) |
|
|
s.Id, s.Size, s.RepType, s.FileCount, s.DeleteCount, s.DeletedByteCount = VolumeId(k), v.Size(), v.replicaType, v.nm.fileCounter, v.nm.deletionCounter, v.nm.deletionByteCounter |
|
|
|
|
|
|
|
|
s.Id, s.Size, s.RepType, s.FileCount, s.DeleteCount, s.DeletedByteCount = VolumeId(k), v.ContentSize(), v.replicaType, v.nm.fileCounter, v.nm.deletionCounter, v.nm.deletionByteCounter |
|
|
stats = append(stats, s) |
|
|
stats = append(stats, s) |
|
|
} |
|
|
} |
|
|
return stats |
|
|
return stats |
|
|
} |
|
|
} |
|
|
func (s *Store) Join(mserver string) error { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type JoinResult struct { |
|
|
|
|
|
VolumeSizeLimit uint64 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *Store) SetMaster(mserver string) { |
|
|
|
|
|
s.masterNode = mserver |
|
|
|
|
|
} |
|
|
|
|
|
func (s *Store) Join() error { |
|
|
stats := new([]*VolumeInfo) |
|
|
stats := new([]*VolumeInfo) |
|
|
for k, v := range s.volumes { |
|
|
for k, v := range s.volumes { |
|
|
s := new(VolumeInfo) |
|
|
s := new(VolumeInfo) |
|
|
s.Id, s.Size, s.RepType, s.FileCount, s.DeleteCount, s.DeletedByteCount = VolumeId(k), v.Size(), v.replicaType, v.nm.fileCounter, v.nm.deletionCounter, v.nm.deletionByteCounter |
|
|
|
|
|
|
|
|
s.Id, s.Size, s.RepType, s.FileCount, s.DeleteCount, s.DeletedByteCount = VolumeId(k), uint64(v.Size()), v.replicaType, v.nm.fileCounter, v.nm.deletionCounter, v.nm.deletionByteCounter |
|
|
*stats = append(*stats, s) |
|
|
*stats = append(*stats, s) |
|
|
} |
|
|
} |
|
|
bytes, _ := json.Marshal(stats) |
|
|
bytes, _ := json.Marshal(stats) |
|
@ -134,8 +146,16 @@ func (s *Store) Join(mserver string) error { |
|
|
values.Add("publicUrl", s.PublicUrl) |
|
|
values.Add("publicUrl", s.PublicUrl) |
|
|
values.Add("volumes", string(bytes)) |
|
|
values.Add("volumes", string(bytes)) |
|
|
values.Add("maxVolumeCount", strconv.Itoa(s.MaxVolumeCount)) |
|
|
values.Add("maxVolumeCount", strconv.Itoa(s.MaxVolumeCount)) |
|
|
_, err := util.Post("http://"+mserver+"/dir/join", values) |
|
|
|
|
|
|
|
|
jsonBlob, err := util.Post("http://"+s.masterNode+"/dir/join", values) |
|
|
|
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
var ret JoinResult |
|
|
|
|
|
if err := json.Unmarshal(jsonBlob, &ret); err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
s.volumeSizeLimit = ret.VolumeSizeLimit |
|
|
|
|
|
return nil |
|
|
} |
|
|
} |
|
|
func (s *Store) Close() { |
|
|
func (s *Store) Close() { |
|
|
for _, v := range s.volumes { |
|
|
for _, v := range s.volumes { |
|
@ -144,9 +164,13 @@ func (s *Store) Close() { |
|
|
} |
|
|
} |
|
|
func (s *Store) Write(i VolumeId, n *Needle) uint32 { |
|
|
func (s *Store) Write(i VolumeId, n *Needle) uint32 { |
|
|
if v := s.volumes[i]; v != nil { |
|
|
if v := s.volumes[i]; v != nil { |
|
|
return v.write(n) |
|
|
|
|
|
|
|
|
size := v.write(n) |
|
|
|
|
|
if s.volumeSizeLimit < v.ContentSize()+uint64(size) { |
|
|
|
|
|
s.Join() |
|
|
|
|
|
} |
|
|
|
|
|
return size |
|
|
} |
|
|
} |
|
|
log.Println("volume",i, "not found!") |
|
|
|
|
|
|
|
|
log.Println("volume", i, "not found!") |
|
|
return 0 |
|
|
return 0 |
|
|
} |
|
|
} |
|
|
func (s *Store) Delete(i VolumeId, n *Needle) uint32 { |
|
|
func (s *Store) Delete(i VolumeId, n *Needle) uint32 { |
|
|