mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
Merge pull request #1168 from stlpmo-jn/optimize_DeleteCollectionFromDiskLocation
decouple the volume.Destroy() from the operation of unmountVolume()
This commit is contained in:
commit
409a3fe41f
|
@ -71,7 +71,6 @@ func (l *DiskLocation) loadExistingVolume(fileInfo os.FileInfo, needleMapKind Ne
|
||||||
} else {
|
} else {
|
||||||
glog.V(0).Infof("new volume %s error %s", name, e)
|
glog.V(0).Infof("new volume %s error %s", name, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,28 +115,46 @@ func (l *DiskLocation) loadExistingVolumes(needleMapKind NeedleMapType) {
|
||||||
func (l *DiskLocation) DeleteCollectionFromDiskLocation(collection string) (e error) {
|
func (l *DiskLocation) DeleteCollectionFromDiskLocation(collection string) (e error) {
|
||||||
|
|
||||||
l.volumesLock.Lock()
|
l.volumesLock.Lock()
|
||||||
for k, v := range l.volumes {
|
delVolsMap := l.unmountVolumeByCollection(collection)
|
||||||
if v.Collection == collection {
|
|
||||||
e = l.deleteVolumeById(k)
|
|
||||||
if e != nil {
|
|
||||||
l.volumesLock.Unlock()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
l.volumesLock.Unlock()
|
l.volumesLock.Unlock()
|
||||||
|
|
||||||
l.ecVolumesLock.Lock()
|
l.ecVolumesLock.Lock()
|
||||||
for k, v := range l.ecVolumes {
|
delEcVolsMap := l.unmountEcVolumeByCollection(collection)
|
||||||
if v.Collection == collection {
|
l.ecVolumesLock.Unlock()
|
||||||
e = l.deleteEcVolumeById(k)
|
|
||||||
if e != nil {
|
errChain := make(chan error, 2)
|
||||||
l.ecVolumesLock.Unlock()
|
var wg sync.WaitGroup
|
||||||
return
|
wg.Add(2)
|
||||||
|
go func() {
|
||||||
|
for _, v := range delVolsMap {
|
||||||
|
if err := v.Destroy(); err != nil {
|
||||||
|
errChain <- err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for _, v := range delEcVolsMap {
|
||||||
|
v.Destroy()
|
||||||
|
}
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
wg.Wait()
|
||||||
|
close(errChain)
|
||||||
|
}()
|
||||||
|
|
||||||
|
errBuilder := strings.Builder{}
|
||||||
|
for err := range errChain {
|
||||||
|
errBuilder.WriteString(err.Error())
|
||||||
|
errBuilder.WriteString("; ")
|
||||||
}
|
}
|
||||||
l.ecVolumesLock.Unlock()
|
if errBuilder.Len() > 0 {
|
||||||
|
e = fmt.Errorf(errBuilder.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -193,6 +210,20 @@ func (l *DiskLocation) UnloadVolume(vid needle.VolumeId) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *DiskLocation) unmountVolumeByCollection(collectionName string) map[needle.VolumeId]*Volume {
|
||||||
|
deltaVols := make(map[needle.VolumeId]*Volume, 0)
|
||||||
|
for k, v := range l.volumes {
|
||||||
|
if v.Collection == collectionName && !v.isCompacting {
|
||||||
|
deltaVols[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, _ := range deltaVols {
|
||||||
|
delete(l.volumes, k)
|
||||||
|
}
|
||||||
|
return deltaVols
|
||||||
|
}
|
||||||
|
|
||||||
func (l *DiskLocation) SetVolume(vid needle.VolumeId, volume *Volume) {
|
func (l *DiskLocation) SetVolume(vid needle.VolumeId, volume *Volume) {
|
||||||
l.volumesLock.Lock()
|
l.volumesLock.Lock()
|
||||||
defer l.volumesLock.Unlock()
|
defer l.volumesLock.Unlock()
|
||||||
|
|
|
@ -169,3 +169,17 @@ func (l *DiskLocation) deleteEcVolumeById(vid needle.VolumeId) (e error) {
|
||||||
delete(l.ecVolumes, vid)
|
delete(l.ecVolumes, vid)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *DiskLocation) unmountEcVolumeByCollection(collectionName string) map[needle.VolumeId]*erasure_coding.EcVolume {
|
||||||
|
deltaVols := make(map[needle.VolumeId]*erasure_coding.EcVolume, 0)
|
||||||
|
for k, v := range l.ecVolumes {
|
||||||
|
if v.Collection == collectionName {
|
||||||
|
deltaVols[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, _ := range deltaVols {
|
||||||
|
delete(l.ecVolumes, k)
|
||||||
|
}
|
||||||
|
return deltaVols
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue