refactoring
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
||||
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
||||
. "github.com/chrislusf/seaweedfs/weed/storage/types"
|
||||
)
|
||||
|
||||
@@ -27,8 +28,8 @@ type Store struct {
|
||||
volumeSizeLimit uint64 //read from the master
|
||||
Client master_pb.Seaweed_SendHeartbeatClient
|
||||
NeedleMapType NeedleMapType
|
||||
NewVolumeIdChan chan VolumeId
|
||||
DeletedVolumeIdChan chan VolumeId
|
||||
NewVolumeIdChan chan needle.VolumeId
|
||||
DeletedVolumeIdChan chan needle.VolumeId
|
||||
}
|
||||
|
||||
func (s *Store) String() (str string) {
|
||||
@@ -44,16 +45,16 @@ func NewStore(port int, ip, publicUrl string, dirnames []string, maxVolumeCounts
|
||||
location.loadExistingVolumes(needleMapKind)
|
||||
s.Locations = append(s.Locations, location)
|
||||
}
|
||||
s.NewVolumeIdChan = make(chan VolumeId, 3)
|
||||
s.DeletedVolumeIdChan = make(chan VolumeId, 3)
|
||||
s.NewVolumeIdChan = make(chan needle.VolumeId, 3)
|
||||
s.DeletedVolumeIdChan = make(chan needle.VolumeId, 3)
|
||||
return
|
||||
}
|
||||
func (s *Store) AddVolume(volumeId VolumeId, collection string, needleMapKind NeedleMapType, replicaPlacement string, ttlString string, preallocate int64) error {
|
||||
func (s *Store) AddVolume(volumeId needle.VolumeId, collection string, needleMapKind NeedleMapType, replicaPlacement string, ttlString string, preallocate int64) error {
|
||||
rt, e := NewReplicaPlacementFromString(replicaPlacement)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
ttl, e := ReadTTL(ttlString)
|
||||
ttl, e := needle.ReadTTL(ttlString)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
@@ -71,7 +72,7 @@ func (s *Store) DeleteCollection(collection string) (e error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (s *Store) findVolume(vid VolumeId) *Volume {
|
||||
func (s *Store) findVolume(vid needle.VolumeId) *Volume {
|
||||
for _, location := range s.Locations {
|
||||
if v, found := location.FindVolume(vid); found {
|
||||
return v
|
||||
@@ -90,7 +91,7 @@ func (s *Store) FindFreeLocation() (ret *DiskLocation) {
|
||||
}
|
||||
return ret
|
||||
}
|
||||
func (s *Store) addVolume(vid VolumeId, collection string, needleMapKind NeedleMapType, replicaPlacement *ReplicaPlacement, ttl *TTL, preallocate int64) error {
|
||||
func (s *Store) addVolume(vid needle.VolumeId, collection string, needleMapKind NeedleMapType, replicaPlacement *ReplicaPlacement, ttl *needle.TTL, preallocate int64) error {
|
||||
if s.findVolume(vid) != nil {
|
||||
return fmt.Errorf("Volume Id %d already exists!", vid)
|
||||
}
|
||||
@@ -114,7 +115,7 @@ func (s *Store) Status() []*VolumeInfo {
|
||||
location.RLock()
|
||||
for k, v := range location.volumes {
|
||||
s := &VolumeInfo{
|
||||
Id: VolumeId(k),
|
||||
Id: needle.VolumeId(k),
|
||||
Size: v.ContentSize(),
|
||||
Collection: v.Collection,
|
||||
ReplicaPlacement: v.ReplicaPlacement,
|
||||
@@ -184,7 +185,7 @@ func (s *Store) Close() {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Store) Write(i VolumeId, n *Needle) (size uint32, err error) {
|
||||
func (s *Store) Write(i needle.VolumeId, n *needle.Needle) (size uint32, err error) {
|
||||
if v := s.findVolume(i); v != nil {
|
||||
if v.readOnly {
|
||||
err = fmt.Errorf("Volume %d is read only", i)
|
||||
@@ -203,32 +204,32 @@ func (s *Store) Write(i VolumeId, n *Needle) (size uint32, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (s *Store) Delete(i VolumeId, n *Needle) (uint32, error) {
|
||||
func (s *Store) Delete(i needle.VolumeId, n *needle.Needle) (uint32, error) {
|
||||
if v := s.findVolume(i); v != nil && !v.readOnly {
|
||||
return v.deleteNeedle(n)
|
||||
}
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (s *Store) ReadVolumeNeedle(i VolumeId, n *Needle) (int, error) {
|
||||
func (s *Store) ReadVolumeNeedle(i needle.VolumeId, n *needle.Needle) (int, error) {
|
||||
if v := s.findVolume(i); v != nil {
|
||||
return v.readNeedle(n)
|
||||
}
|
||||
return 0, fmt.Errorf("Volume %d not found!", i)
|
||||
}
|
||||
func (s *Store) GetVolume(i VolumeId) *Volume {
|
||||
func (s *Store) GetVolume(i needle.VolumeId) *Volume {
|
||||
return s.findVolume(i)
|
||||
}
|
||||
|
||||
func (s *Store) HasVolume(i VolumeId) bool {
|
||||
func (s *Store) HasVolume(i needle.VolumeId) bool {
|
||||
v := s.findVolume(i)
|
||||
return v != nil
|
||||
}
|
||||
|
||||
func (s *Store) MountVolume(i VolumeId) error {
|
||||
func (s *Store) MountVolume(i needle.VolumeId) error {
|
||||
for _, location := range s.Locations {
|
||||
if found := location.LoadVolume(i, s.NeedleMapType); found == true {
|
||||
s.NewVolumeIdChan <- VolumeId(i)
|
||||
s.NewVolumeIdChan <- needle.VolumeId(i)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -236,10 +237,10 @@ func (s *Store) MountVolume(i VolumeId) error {
|
||||
return fmt.Errorf("Volume %d not found on disk", i)
|
||||
}
|
||||
|
||||
func (s *Store) UnmountVolume(i VolumeId) error {
|
||||
func (s *Store) UnmountVolume(i needle.VolumeId) error {
|
||||
for _, location := range s.Locations {
|
||||
if err := location.UnloadVolume(i); err == nil {
|
||||
s.DeletedVolumeIdChan <- VolumeId(i)
|
||||
s.DeletedVolumeIdChan <- needle.VolumeId(i)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -247,10 +248,10 @@ func (s *Store) UnmountVolume(i VolumeId) error {
|
||||
return fmt.Errorf("Volume %d not found on disk", i)
|
||||
}
|
||||
|
||||
func (s *Store) DeleteVolume(i VolumeId) error {
|
||||
func (s *Store) DeleteVolume(i needle.VolumeId) error {
|
||||
for _, location := range s.Locations {
|
||||
if error := location.deleteVolumeById(i); error == nil {
|
||||
s.DeletedVolumeIdChan <- VolumeId(i)
|
||||
s.DeletedVolumeIdChan <- needle.VolumeId(i)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user