ensure unwritable volumes are not in writables list

This commit is contained in:
Chris Lu 2013-08-12 16:39:49 -07:00
parent 82f6a6838f
commit a74978baeb

View File

@ -1,9 +1,9 @@
package topology package topology
import ( import (
"code.google.com/p/weed-fs/go/glog"
"code.google.com/p/weed-fs/go/storage" "code.google.com/p/weed-fs/go/storage"
"errors" "errors"
"code.google.com/p/weed-fs/go/glog"
"math/rand" "math/rand"
"sync" "sync"
) )
@ -38,6 +38,8 @@ func (vl *VolumeLayout) RegisterVolume(v *storage.VolumeInfo, dn *DataNode) {
if len(vl.vid2location[v.Id].list) == v.RepType.GetCopyCount() { if len(vl.vid2location[v.Id].list) == v.RepType.GetCopyCount() {
if vl.isWritable(v) { if vl.isWritable(v) {
vl.writables = append(vl.writables, v.Id) vl.writables = append(vl.writables, v.Id)
} else {
vl.removeFromWritable(v.Id)
} }
} }
} }
@ -105,13 +107,18 @@ func (vl *VolumeLayout) GetActiveVolumeCount(dataCenter string) int {
} }
func (vl *VolumeLayout) removeFromWritable(vid storage.VolumeId) bool { func (vl *VolumeLayout) removeFromWritable(vid storage.VolumeId) bool {
for i, v := range vl.writables { toDeleteIndex := -1
if v == vid { for k, id := range vl.writables {
glog.V(0).Infoln("Volume", vid, "becomes unwritable") if id == vid {
vl.writables = append(vl.writables[:i], vl.writables[i+1:]...) toDeleteIndex = k
return true break
} }
} }
if toDeleteIndex >= 0 {
glog.V(0).Infoln("Volume", vid, "becomes unwritable")
vl.writables = append(vl.writables[0:toDeleteIndex], vl.writables[toDeleteIndex+1:]...)
return true
}
return false return false
} }
func (vl *VolumeLayout) setVolumeWritable(vid storage.VolumeId) bool { func (vl *VolumeLayout) setVolumeWritable(vid storage.VolumeId) bool {