aboutsummaryrefslogtreecommitdiff
path: root/weed/topology/volume_layout.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-09-22 15:05:37 -0700
committerChris Lu <chris.lu@gmail.com>2020-09-22 15:05:37 -0700
commit3e52329cee39f3a83f58d3896514547093ff0cf8 (patch)
tree3c1dd7941030e394b7899ac6a3037f1e5a318117 /weed/topology/volume_layout.go
parent4a1fe4b8e25c53c871c50edb624823435fd3e948 (diff)
downloadseaweedfs-3e52329cee39f3a83f58d3896514547093ff0cf8.tar.xz
seaweedfs-3e52329cee39f3a83f58d3896514547093ff0cf8.zip
Revert "Merge pull request #1479 from LIBA-S/fix_oversized"
This reverts commit bd11f0b3e4c14e91c7c9c19cd19db454ff02b4d6, reversing changes made to ec5b9f1e91a8609d0e70bf9d26dc0840774153c4.
Diffstat (limited to 'weed/topology/volume_layout.go')
-rw-r--r--weed/topology/volume_layout.go116
1 files changed, 13 insertions, 103 deletions
diff --git a/weed/topology/volume_layout.go b/weed/topology/volume_layout.go
index e3a70ef25..9e84fd2da 100644
--- a/weed/topology/volume_layout.go
+++ b/weed/topology/volume_layout.go
@@ -13,100 +13,14 @@ import (
"github.com/chrislusf/seaweedfs/weed/storage/super_block"
)
-type copyState int
-
-const (
- noCopies copyState = 0 + iota
- insufficientCopies
- enoughCopies
-)
-
-type volumeState string
-
-const (
- readOnlyState volumeState = "ReadOnly"
- oversizedState = "Oversized"
-)
-
-type stateIndicator func(copyState) bool
-
-func ExistCopies() stateIndicator {
- return func(state copyState) bool { return state != noCopies }
-}
-
-func NoCopies() stateIndicator {
- return func(state copyState) bool { return state == noCopies }
-}
-
-type volumesBinaryState struct {
- copyCount int
- name volumeState // the name for volume state (eg. "Readonly", "Oversized")
- indicator stateIndicator // indicate whether the volumes should be marked as `name`
- copyMap map[needle.VolumeId]*VolumeLocationList
-}
-
-func NewVolumesBinaryState(name volumeState, copyCount int, indicator stateIndicator) *volumesBinaryState {
- return &volumesBinaryState{
- copyCount: copyCount,
- name: name,
- indicator: indicator,
- copyMap: make(map[needle.VolumeId]*VolumeLocationList),
- }
-}
-
-func (v *volumesBinaryState) Dump() (res []uint32) {
- for vid, list := range v.copyMap {
- if v.indicator(v.copyState(list)) {
- res = append(res, uint32(vid))
- }
- }
- return
-}
-
-func (v *volumesBinaryState) IsTrue(vid needle.VolumeId) bool {
- list, _ := v.copyMap[vid]
- return v.indicator(v.copyState(list))
-}
-
-func (v *volumesBinaryState) Add(vid needle.VolumeId, dn *DataNode) {
- list, _ := v.copyMap[vid]
- if list != nil {
- list.Set(dn)
- return
- }
- list = NewVolumeLocationList()
- list.Set(dn)
- v.copyMap[vid] = list
-}
-
-func (v *volumesBinaryState) Remove(vid needle.VolumeId, dn *DataNode) {
- list, _ := v.copyMap[vid]
- if list != nil {
- list.Remove(dn)
- if list.Length() == 0 {
- delete(v.copyMap, vid)
- }
- }
-}
-
-func (v *volumesBinaryState) copyState(list *VolumeLocationList) copyState {
- if list == nil {
- return noCopies
- }
- if list.Length() < v.copyCount {
- return insufficientCopies
- }
- return enoughCopies
-}
-
// mapping from volume to its locations, inverted from server to volume
type VolumeLayout struct {
rp *super_block.ReplicaPlacement
ttl *needle.TTL
vid2location map[needle.VolumeId]*VolumeLocationList
- writables []needle.VolumeId // transient array of writable volume id
- readonlyVolumes *volumesBinaryState // readonly volumes
- oversizedVolumes *volumesBinaryState // oversized volumes
+ writables []needle.VolumeId // transient array of writable volume id
+ readonlyVolumes map[needle.VolumeId]bool // transient set of readonly volumes
+ oversizedVolumes map[needle.VolumeId]bool // set of oversized volumes
volumeSizeLimit uint64
replicationAsMin bool
accessLock sync.RWMutex
@@ -124,8 +38,8 @@ func NewVolumeLayout(rp *super_block.ReplicaPlacement, ttl *needle.TTL, volumeSi
ttl: ttl,
vid2location: make(map[needle.VolumeId]*VolumeLocationList),
writables: *new([]needle.VolumeId),
- readonlyVolumes: NewVolumesBinaryState(readOnlyState, rp.GetCopyCount(), ExistCopies()),
- oversizedVolumes: NewVolumesBinaryState(oversizedState, rp.GetCopyCount(), ExistCopies()),
+ readonlyVolumes: make(map[needle.VolumeId]bool),
+ oversizedVolumes: make(map[needle.VolumeId]bool),
volumeSizeLimit: volumeSizeLimit,
replicationAsMin: replicationAsMin,
}
@@ -140,7 +54,7 @@ func (vl *VolumeLayout) RegisterVolume(v *storage.VolumeInfo, dn *DataNode) {
defer vl.accessLock.Unlock()
defer vl.ensureCorrectWritables(v)
- defer vl.rememberOversizedVolume(v, dn)
+ defer vl.rememberOversizedVolume(v)
if _, ok := vl.vid2location[v.Id]; !ok {
vl.vid2location[v.Id] = NewVolumeLocationList()
@@ -152,26 +66,24 @@ func (vl *VolumeLayout) RegisterVolume(v *storage.VolumeInfo, dn *DataNode) {
if vInfo.ReadOnly {
glog.V(1).Infof("vid %d removed from writable", v.Id)
vl.removeFromWritable(v.Id)
- vl.readonlyVolumes.Add(v.Id, dn)
+ vl.readonlyVolumes[v.Id] = true
return
} else {
- vl.readonlyVolumes.Remove(v.Id, dn)
+ delete(vl.readonlyVolumes, v.Id)
}
} else {
glog.V(1).Infof("vid %d removed from writable", v.Id)
vl.removeFromWritable(v.Id)
- vl.readonlyVolumes.Remove(v.Id, dn)
+ delete(vl.readonlyVolumes, v.Id)
return
}
}
}
-func (vl *VolumeLayout) rememberOversizedVolume(v *storage.VolumeInfo, dn *DataNode) {
+func (vl *VolumeLayout) rememberOversizedVolume(v *storage.VolumeInfo) {
if vl.isOversized(v) {
- vl.oversizedVolumes.Add(v.Id, dn)
- } else {
- vl.oversizedVolumes.Remove(v.Id, dn)
+ vl.oversizedVolumes[v.Id] = true
}
}
@@ -187,8 +99,6 @@ func (vl *VolumeLayout) UnRegisterVolume(v *storage.VolumeInfo, dn *DataNode) {
if location.Remove(dn) {
- vl.readonlyVolumes.Remove(v.Id, dn)
- vl.oversizedVolumes.Remove(v.Id, dn)
vl.ensureCorrectWritables(v)
if location.Length() == 0 {
@@ -200,7 +110,7 @@ func (vl *VolumeLayout) UnRegisterVolume(v *storage.VolumeInfo, dn *DataNode) {
func (vl *VolumeLayout) ensureCorrectWritables(v *storage.VolumeInfo) {
if vl.enoughCopies(v.Id) && vl.isWritable(v) {
- if vl.oversizedVolumes.IsTrue(v.Id) {
+ if _, ok := vl.oversizedVolumes[v.Id]; !ok {
vl.setVolumeWritable(v.Id)
}
} else {
@@ -405,7 +315,7 @@ func (vl *VolumeLayout) Stats() *VolumeLayoutStats {
size, fileCount := vll.Stats(vid, freshThreshold)
ret.FileCount += uint64(fileCount)
ret.UsedSize += size
- if vl.readonlyVolumes.IsTrue(vid) {
+ if vl.readonlyVolumes[vid] {
ret.TotalSize += size
} else {
ret.TotalSize += vl.volumeSizeLimit