2012-09-10 15:18:07 +08:00
|
|
|
package topology
|
|
|
|
|
2015-01-08 15:54:50 +08:00
|
|
|
import (
|
|
|
|
"fmt"
|
2018-11-23 16:24:51 +08:00
|
|
|
|
2019-04-19 12:43:36 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
2015-01-08 15:54:50 +08:00
|
|
|
)
|
|
|
|
|
2012-09-20 07:48:04 +08:00
|
|
|
type VolumeLocationList struct {
|
2012-09-11 08:08:52 +08:00
|
|
|
list []*DataNode
|
2012-09-10 15:18:07 +08:00
|
|
|
}
|
|
|
|
|
2012-09-20 07:48:04 +08:00
|
|
|
func NewVolumeLocationList() *VolumeLocationList {
|
|
|
|
return &VolumeLocationList{}
|
2012-09-10 15:18:07 +08:00
|
|
|
}
|
|
|
|
|
2015-01-08 15:54:50 +08:00
|
|
|
func (dnll *VolumeLocationList) String() string {
|
|
|
|
return fmt.Sprintf("%v", dnll.list)
|
|
|
|
}
|
|
|
|
|
2020-09-23 20:56:51 +08:00
|
|
|
func (dnll *VolumeLocationList) Copy() *VolumeLocationList {
|
|
|
|
list := make([]*DataNode, len(dnll.list))
|
|
|
|
copy(list, dnll.list)
|
|
|
|
return &VolumeLocationList{
|
|
|
|
list: list,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-20 07:48:04 +08:00
|
|
|
func (dnll *VolumeLocationList) Head() *DataNode {
|
2015-11-29 23:49:41 +08:00
|
|
|
//mark first node as master volume
|
2012-09-17 08:31:15 +08:00
|
|
|
return dnll.list[0]
|
|
|
|
}
|
|
|
|
|
2021-09-06 14:32:25 +08:00
|
|
|
func (dnll *VolumeLocationList) Rest() []*DataNode {
|
|
|
|
//mark first node as master volume
|
|
|
|
return dnll.list[1:]
|
|
|
|
}
|
|
|
|
|
2012-09-20 07:48:04 +08:00
|
|
|
func (dnll *VolumeLocationList) Length() int {
|
adding locking to avoid nil VolumeLocationList
fix panic: runtime error: invalid memory address or nil pointer dereference
Oct 22 00:53:44 bedb-master1 weed[8055]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x17658da]
Oct 22 00:53:44 bedb-master1 weed[8055]: goroutine 310 [running]:
Oct 22 00:53:44 bedb-master1 weed[8055]: github.com/chrislusf/seaweedfs/weed/topology.(*VolumeLocationList).Length(...)
Oct 22 00:53:44 bedb-master1 weed[8055]: #011/root/seaweedfs/weed/topology/volume_location_list.go:35
Oct 22 00:53:44 bedb-master1 weed[8055]: github.com/chrislusf/seaweedfs/weed/topology.(*VolumeLayout).enoughCopies(...)
Oct 22 00:53:44 bedb-master1 weed[8055]: #011/root/seaweedfs/weed/topology/volume_layout.go:376
Oct 22 00:53:44 bedb-master1 weed[8055]: github.com/chrislusf/seaweedfs/weed/topology.(*VolumeLayout).ensureCorrectWritables(0xc000111d50, 0xc000b55438)
Oct 22 00:53:44 bedb-master1 weed[8055]: #011/root/seaweedfs/weed/topology/volume_layout.go:202 +0x5a
Oct 22 00:53:44 bedb-master1 weed[8055]: github.com/chrislusf/seaweedfs/weed/topology.(*Topology).SyncDataNodeRegistration(0xc00042ac60, 0xc001454d30, 0x1, 0x1, 0xc0005fc000, 0xc00135de40, 0x4, 0xc00135de50, 0x10, 0x10d, ...)
Oct 22 00:53:44 bedb-master1 weed[8055]: #011/root/seaweedfs/weed/topology/topology.go:224 +0x616
Oct 22 00:53:44 bedb-master1 weed[8055]: github.com/chrislusf/seaweedfs/weed/server.(*MasterServer).SendHeartbeat(0xc000162700, 0x23b97c0, 0xc000ae2c90, 0x0, 0x0)
Oct 22 00:53:44 bedb-master1 weed[8055]: #011/root/seaweedfs/weed/server/master_grpc_server.go:106 +0x325
Oct 22 00:53:44 bedb-master1 weed[8055]: github.com/chrislusf/seaweedfs/weed/pb/master_pb._Seaweed_SendHeartbeat_Handler(0x1f8e7c0, 0xc000162700, 0x23b0a60, 0xc00024b440, 0x3172c38, 0xc000ab7100)
Oct 22 00:53:44 bedb-master1 weed[8055]: #011/root/seaweedfs/weed/pb/master_pb/master.pb.go:4250 +0xad
Oct 22 00:53:44 bedb-master1 weed[8055]: google.golang.org/grpc.(*Server).processStreamingRPC(0xc0001f31e0, 0x23bb800, 0xc000ac5500, 0xc000ab7100, 0xc0001fea80, 0x311fec0, 0x0, 0x0, 0x0)
Oct 22 00:53:44 bedb-master1 weed[8055]: #011/root/go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:1329 +0xcd8
Oct 22 00:53:44 bedb-master1 weed[8055]: google.golang.org/grpc.(*Server).handleStream(0xc0001f31e0, 0x23bb800, 0xc000ac5500, 0xc000ab7100, 0x0)
Oct 22 00:53:44 bedb-master1 weed[8055]: #011/root/go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:1409 +0xc5c
Oct 22 00:53:44 bedb-master1 weed[8055]: google.golang.org/grpc.(*Server).serveStreams.func1.1(0xc0001ce8b0, 0xc0001f31e0, 0x23bb800, 0xc000ac5500, 0xc000ab7100)
Oct 22 00:53:44 bedb-master1 weed[8055]: #011/root/go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:746 +0xa5
Oct 22 00:53:44 bedb-master1 weed[8055]: created by google.golang.org/grpc.(*Server).serveStreams.func1
Oct 22 00:53:44 bedb-master1 weed[8055]: #011/root/go/pkg/mod/google.golang.org/grpc@v1.29.1/server.go:744 +0xa5
Oct 22 00:53:44 bedb-master1 systemd[1]: weedmaster.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Oct 22 00:53:44 bedb-master1 systemd[1]: weedmaster.service: Failed with result 'exit-code'.
2020-10-22 14:15:48 +08:00
|
|
|
if dnll == nil {
|
|
|
|
return 0
|
|
|
|
}
|
2013-01-17 16:56:56 +08:00
|
|
|
return len(dnll.list)
|
2012-09-20 07:48:04 +08:00
|
|
|
}
|
|
|
|
|
2014-03-19 19:48:13 +08:00
|
|
|
func (dnll *VolumeLocationList) Set(loc *DataNode) {
|
|
|
|
for i := 0; i < len(dnll.list); i++ {
|
|
|
|
if loc.Ip == dnll.list[i].Ip && loc.Port == dnll.list[i].Port {
|
|
|
|
dnll.list[i] = loc
|
|
|
|
return
|
2012-09-11 08:08:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
dnll.list = append(dnll.list, loc)
|
|
|
|
}
|
2012-11-07 17:51:43 +08:00
|
|
|
|
2012-09-20 07:48:04 +08:00
|
|
|
func (dnll *VolumeLocationList) Remove(loc *DataNode) bool {
|
2013-01-17 16:56:56 +08:00
|
|
|
for i, dnl := range dnll.list {
|
|
|
|
if loc.Ip == dnl.Ip && loc.Port == dnl.Port {
|
|
|
|
dnll.list = append(dnll.list[:i], dnll.list[i+1:]...)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
2012-09-20 07:48:04 +08:00
|
|
|
}
|
2012-09-11 08:08:52 +08:00
|
|
|
|
2012-09-20 07:48:04 +08:00
|
|
|
func (dnll *VolumeLocationList) Refresh(freshThreshHold int64) {
|
2012-09-11 08:08:52 +08:00
|
|
|
var changed bool
|
|
|
|
for _, dnl := range dnll.list {
|
2012-09-17 16:48:09 +08:00
|
|
|
if dnl.LastSeen < freshThreshHold {
|
2012-09-11 08:08:52 +08:00
|
|
|
changed = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if changed {
|
|
|
|
var l []*DataNode
|
|
|
|
for _, dnl := range dnll.list {
|
2012-09-17 16:48:09 +08:00
|
|
|
if dnl.LastSeen >= freshThreshHold {
|
2012-09-11 08:08:52 +08:00
|
|
|
l = append(l, dnl)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dnll.list = l
|
|
|
|
}
|
2012-09-10 15:18:07 +08:00
|
|
|
}
|
2018-11-23 16:24:51 +08:00
|
|
|
|
2019-04-19 12:43:36 +08:00
|
|
|
func (dnll *VolumeLocationList) Stats(vid needle.VolumeId, freshThreshHold int64) (size uint64, fileCount int) {
|
2018-11-23 16:24:51 +08:00
|
|
|
for _, dnl := range dnll.list {
|
|
|
|
if dnl.LastSeen < freshThreshHold {
|
|
|
|
vinfo, err := dnl.GetVolumesById(vid)
|
|
|
|
if err == nil {
|
2021-02-26 20:58:40 +08:00
|
|
|
return (vinfo.Size - vinfo.DeletedByteCount) * uint64(len(dnll.list)), vinfo.FileCount - vinfo.DeleteCount
|
2018-11-23 16:24:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0, 0
|
|
|
|
}
|