Browse Source

add volume not found error type, to reduce error log

pull/2348/head
Chris Lu 3 years ago
parent
commit
8c6ff55226
  1. 6
      weed/storage/disk_location.go
  2. 4
      weed/storage/store.go

6
weed/storage/disk_location.go

@ -247,13 +247,15 @@ func (l *DiskLocation) LoadVolume(vid needle.VolumeId, needleMapKind NeedleMapKi
return false return false
} }
var ErrVolumeNotFound = fmt.Errorf("volume not found")
func (l *DiskLocation) DeleteVolume(vid needle.VolumeId) error { func (l *DiskLocation) DeleteVolume(vid needle.VolumeId) error {
l.volumesLock.Lock() l.volumesLock.Lock()
defer l.volumesLock.Unlock() defer l.volumesLock.Unlock()
_, ok := l.volumes[vid] _, ok := l.volumes[vid]
if !ok { if !ok {
return fmt.Errorf("Volume not found, VolumeId: %d", vid)
return ErrVolumeNotFound
} }
_, err := l.deleteVolumeById(vid) _, err := l.deleteVolumeById(vid)
return err return err
@ -265,7 +267,7 @@ func (l *DiskLocation) UnloadVolume(vid needle.VolumeId) error {
v, ok := l.volumes[vid] v, ok := l.volumes[vid]
if !ok { if !ok {
return fmt.Errorf("Volume not loaded, VolumeId: %d", vid)
return ErrVolumeNotFound
} }
v.Close() v.Close()
delete(l.volumes, vid) delete(l.volumes, vid)

4
weed/storage/store.go

@ -428,7 +428,7 @@ func (s *Store) UnmountVolume(i needle.VolumeId) error {
} }
for _, location := range s.Locations { for _, location := range s.Locations {
if err := location.UnloadVolume(i); err == nil {
if err := location.UnloadVolume(i); err == nil || err == ErrVolumeNotFound {
glog.V(0).Infof("UnmountVolume %d", i) glog.V(0).Infof("UnmountVolume %d", i)
s.DeletedVolumesChan <- message s.DeletedVolumesChan <- message
return nil return nil
@ -452,7 +452,7 @@ func (s *Store) DeleteVolume(i needle.VolumeId) error {
DiskType: string(v.location.DiskType), DiskType: string(v.location.DiskType),
} }
for _, location := range s.Locations { for _, location := range s.Locations {
if err := location.DeleteVolume(i); err == nil {
if err := location.DeleteVolume(i); err == nil || err == ErrVolumeNotFound {
glog.V(0).Infof("DeleteVolume %d", i) glog.V(0).Infof("DeleteVolume %d", i)
s.DeletedVolumesChan <- message s.DeletedVolumesChan <- message
return nil return nil

Loading…
Cancel
Save