diff options
Diffstat (limited to 'weed/topology')
| -rw-r--r-- | weed/topology/volume_growth_test.go | 17 | ||||
| -rw-r--r-- | weed/topology/volume_layout.go | 17 | ||||
| -rw-r--r-- | weed/topology/volume_location_list.go | 3 |
3 files changed, 28 insertions, 9 deletions
diff --git a/weed/topology/volume_growth_test.go b/weed/topology/volume_growth_test.go index a3473c677..04c5e8aeb 100644 --- a/weed/topology/volume_growth_test.go +++ b/weed/topology/volume_growth_test.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "github.com/seaweedfs/seaweedfs/weed/storage/types" + "github.com/seaweedfs/seaweedfs/weed/util" "testing" "github.com/seaweedfs/seaweedfs/weed/sequence" @@ -419,11 +420,13 @@ func TestPickForWrite(t *testing.T) { Rack: "", DataNode: "", } + v := util.GetViper() + v.Set("master.volume_growth.threshold", 0.9) for _, rpStr := range []string{"001", "010", "100"} { rp, _ := super_block.NewReplicaPlacementFromString(rpStr) vl := topo.GetVolumeLayout("test", rp, needle.EMPTY_TTL, types.HardDriveType) volumeGrowOption.ReplicaPlacement = rp - for _, dc := range []string{"", "dc1", "dc2", "dc3"} { + for _, dc := range []string{"", "dc1", "dc2", "dc3", "dc0"} { volumeGrowOption.DataCenter = dc for _, r := range []string{""} { volumeGrowOption.Rack = r @@ -432,8 +435,13 @@ func TestPickForWrite(t *testing.T) { continue } volumeGrowOption.DataNode = dn - fileId, count, _, _, err := topo.PickForWrite(1, volumeGrowOption, vl) - if err != nil { + fileId, count, _, shouldGrow, err := topo.PickForWrite(1, volumeGrowOption, vl) + if dc == "dc0" { + if err == nil || count != 0 || !shouldGrow { + fmt.Println(dc, r, dn, "pick for write should be with error") + t.Fail() + } + } else if err != nil { fmt.Println(dc, r, dn, "pick for write error :", err) t.Fail() } else if count == 0 { @@ -442,6 +450,9 @@ func TestPickForWrite(t *testing.T) { } else if len(fileId) == 0 { fmt.Println(dc, r, dn, "pick for write file id is empty") t.Fail() + } else if shouldGrow { + fmt.Println(dc, r, dn, "pick for write error : not should grow") + t.Fail() } } } diff --git a/weed/topology/volume_layout.go b/weed/topology/volume_layout.go index 278978292..d04552d35 100644 --- a/weed/topology/volume_layout.go +++ b/weed/topology/volume_layout.go @@ -234,13 +234,18 @@ func (vl *VolumeLayout) ensureCorrectWritables(vid needle.VolumeId) { } func (vl *VolumeLayout) isAllWritable(vid needle.VolumeId) bool { - for _, dn := range vl.vid2location[vid].list { - if v, getError := dn.GetVolumesById(vid); getError == nil { - if v.ReadOnly { - return false + if location, ok := vl.vid2location[vid]; ok { + for _, dn := range location.list { + if v, getError := dn.GetVolumesById(vid); getError == nil { + if v.ReadOnly { + return false + } } } + } else { + return false } + return true } @@ -301,7 +306,7 @@ func (vl *VolumeLayout) PickForWrite(count uint64, option *VolumeGrowOption) (vi if float64(info.Size) > float64(vl.volumeSizeLimit)*option.Threshold() { shouldGrow = true } - return vid, count, locationList, shouldGrow, nil + return vid, count, locationList.Copy(), shouldGrow, nil } return 0, 0, nil, shouldGrow, errors.New("Strangely vid " + vid.String() + " is on no machine!") } @@ -336,7 +341,7 @@ func (vl *VolumeLayout) PickForWrite(count uint64, option *VolumeGrowOption) (vi return } } - return vid, count, locationList, shouldGrow, fmt.Errorf("No writable volumes in DataCenter:%v Rack:%v DataNode:%v", option.DataCenter, option.Rack, option.DataNode) + return vid, count, locationList, true, fmt.Errorf("No writable volumes in DataCenter:%v Rack:%v DataNode:%v", option.DataCenter, option.Rack, option.DataNode) } func (vl *VolumeLayout) HasGrowRequest() bool { diff --git a/weed/topology/volume_location_list.go b/weed/topology/volume_location_list.go index c26f77104..127ad67eb 100644 --- a/weed/topology/volume_location_list.go +++ b/weed/topology/volume_location_list.go @@ -28,6 +28,9 @@ func (dnll *VolumeLocationList) Copy() *VolumeLocationList { func (dnll *VolumeLocationList) Head() *DataNode { //mark first node as master volume + if dnll.Length() == 0 { + return nil + } return dnll.list[0] } |
