aboutsummaryrefslogtreecommitdiff
path: root/weed/storage
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2018-08-24 01:26:56 -0700
committerChris Lu <chris.lu@gmail.com>2018-08-24 01:26:56 -0700
commit76cbe8bf3371fbdbb65cf13fe0d767164b53b151 (patch)
treeacefbaeb8ab2b66b0ddfb07415abd8c263c63e94 /weed/storage
parent5ccf8e8078eee570f7ff444ea86a07589394a4ed (diff)
downloadseaweedfs-76cbe8bf3371fbdbb65cf13fe0d767164b53b151.tar.xz
seaweedfs-76cbe8bf3371fbdbb65cf13fe0d767164b53b151.zip
instant notification of new volumes added or deleted
Diffstat (limited to 'weed/storage')
-rw-r--r--weed/storage/store.go40
1 files changed, 19 insertions, 21 deletions
diff --git a/weed/storage/store.go b/weed/storage/store.go
index ac125ef4b..aea4670ad 100644
--- a/weed/storage/store.go
+++ b/weed/storage/store.go
@@ -18,16 +18,18 @@ const (
* A VolumeServer contains one Store
*/
type Store struct {
- Ip string
- Port int
- PublicUrl string
- Locations []*DiskLocation
- dataCenter string //optional informaton, overwriting master setting if exists
- rack string //optional information, overwriting master setting if exists
- connected bool
- VolumeSizeLimit uint64 //read from the master
- Client master_pb.Seaweed_SendHeartbeatClient
- NeedleMapType NeedleMapType
+ Ip string
+ Port int
+ PublicUrl string
+ Locations []*DiskLocation
+ dataCenter string //optional informaton, overwriting master setting if exists
+ rack string //optional information, overwriting master setting if exists
+ connected bool
+ VolumeSizeLimit uint64 //read from the master
+ Client master_pb.Seaweed_SendHeartbeatClient
+ NeedleMapType NeedleMapType
+ NewVolumeIdChan chan VolumeId
+ DeletedVolumeIdChan chan VolumeId
}
func (s *Store) String() (str string) {
@@ -43,6 +45,8 @@ 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)
return
}
func (s *Store) AddVolume(volumeListString string, collection string, needleMapKind NeedleMapType, replicaPlacement string, ttlString string, preallocate int64) error {
@@ -87,6 +91,7 @@ func (s *Store) DeleteCollection(collection string) (e error) {
if e != nil {
return
}
+ // let the heartbeat send the list of volumes, instead of sending the deleted volume ids to DeletedVolumeIdChan
}
return
}
@@ -119,6 +124,7 @@ func (s *Store) addVolume(vid VolumeId, collection string, needleMapKind NeedleM
location.Directory, vid, collection, replicaPlacement, ttl)
if volume, err := NewVolume(location.Directory, collection, vid, needleMapKind, replicaPlacement, ttl, preallocate); err == nil {
location.SetVolume(vid, volume)
+ s.NewVolumeIdChan <- vid
return nil
} else {
return err
@@ -232,14 +238,6 @@ func (s *Store) Write(i VolumeId, n *Needle) (size uint32, err error) {
return
}
-func (s *Store) updateMaster() {
- if s.Client != nil {
- if e := s.Client.Send(s.CollectHeartbeat()); e != nil {
- glog.V(0).Infoln("error when reporting size:", e)
- }
- }
-}
-
func (s *Store) Delete(i VolumeId, n *Needle) (uint32, error) {
if v := s.findVolume(i); v != nil && !v.readOnly {
return v.deleteNeedle(n)
@@ -265,7 +263,7 @@ func (s *Store) HasVolume(i VolumeId) bool {
func (s *Store) MountVolume(i VolumeId) error {
for _, location := range s.Locations {
if found := location.LoadVolume(i, s.NeedleMapType); found == true {
- s.updateMaster()
+ s.NewVolumeIdChan <- VolumeId(i)
return nil
}
}
@@ -276,7 +274,7 @@ func (s *Store) MountVolume(i VolumeId) error {
func (s *Store) UnmountVolume(i VolumeId) error {
for _, location := range s.Locations {
if err := location.UnloadVolume(i); err == nil {
- s.updateMaster()
+ s.DeletedVolumeIdChan <- VolumeId(i)
return nil
}
}
@@ -287,7 +285,7 @@ func (s *Store) UnmountVolume(i VolumeId) error {
func (s *Store) DeleteVolume(i VolumeId) error {
for _, location := range s.Locations {
if error := location.deleteVolumeById(i); error == nil {
- s.updateMaster()
+ s.DeletedVolumeIdChan <- VolumeId(i)
return nil
}
}