2012-08-29 08:42:24 +00:00
|
|
|
package topology
|
|
|
|
|
|
|
|
import (
|
2018-06-25 06:55:27 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
2018-07-11 09:01:33 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/sequence"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage"
|
2019-04-19 04:43:36 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
2019-12-23 20:48:20 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/super_block"
|
2021-02-16 10:47:02 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/types"
|
2019-04-19 04:43:36 +00:00
|
|
|
|
2018-07-11 09:01:33 +00:00
|
|
|
"testing"
|
2012-08-29 08:42:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRemoveDataCenter(t *testing.T) {
|
2012-09-02 21:33:48 +00:00
|
|
|
topo := setup(topologyLayout)
|
|
|
|
topo.UnlinkChildNode(NodeId("dc2"))
|
2021-02-16 18:51:03 +00:00
|
|
|
if topo.diskUsages.usages[types.HardDriveType].activeVolumeCount != 15 {
|
2012-09-01 09:20:59 +00:00
|
|
|
t.Fail()
|
|
|
|
}
|
2012-09-02 21:33:48 +00:00
|
|
|
topo.UnlinkChildNode(NodeId("dc3"))
|
2021-02-16 18:51:03 +00:00
|
|
|
if topo.diskUsages.usages[types.HardDriveType].activeVolumeCount != 12 {
|
2012-09-01 09:20:59 +00:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
2018-06-25 06:55:27 +00:00
|
|
|
|
|
|
|
func TestHandlingVolumeServerHeartbeat(t *testing.T) {
|
2020-04-01 19:18:40 +00:00
|
|
|
topo := NewTopology("weedfs", sequence.NewMemorySequencer(), 32*1024, 5, false)
|
2018-06-25 06:55:27 +00:00
|
|
|
|
|
|
|
dc := topo.GetOrCreateDataCenter("dc1")
|
|
|
|
rack := dc.GetOrCreateRack("rack1")
|
2021-02-16 18:51:03 +00:00
|
|
|
maxVolumeCounts := make(map[string]uint32)
|
|
|
|
maxVolumeCounts[""] = 25
|
|
|
|
maxVolumeCounts["ssd"] = 12
|
2021-09-13 05:47:52 +00:00
|
|
|
dn := rack.GetOrCreateDataNode("127.0.0.1", 34534, 0,"127.0.0.1", maxVolumeCounts)
|
2018-06-25 06:55:27 +00:00
|
|
|
|
|
|
|
{
|
2018-07-11 09:01:33 +00:00
|
|
|
volumeCount := 7
|
2018-06-25 06:55:27 +00:00
|
|
|
var volumeMessages []*master_pb.VolumeInformationMessage
|
|
|
|
for k := 1; k <= volumeCount; k++ {
|
|
|
|
volumeMessage := &master_pb.VolumeInformationMessage{
|
|
|
|
Id: uint32(k),
|
|
|
|
Size: uint64(25432),
|
|
|
|
Collection: "",
|
|
|
|
FileCount: uint64(2343),
|
|
|
|
DeleteCount: uint64(345),
|
|
|
|
DeletedByteCount: 34524,
|
|
|
|
ReadOnly: false,
|
|
|
|
ReplicaPlacement: uint32(0),
|
2019-04-21 06:53:37 +00:00
|
|
|
Version: uint32(needle.CurrentVersion),
|
2018-06-25 06:55:27 +00:00
|
|
|
Ttl: 0,
|
|
|
|
}
|
|
|
|
volumeMessages = append(volumeMessages, volumeMessage)
|
|
|
|
}
|
|
|
|
|
2020-12-13 11:11:24 +00:00
|
|
|
for k := 1; k <= volumeCount; k++ {
|
|
|
|
volumeMessage := &master_pb.VolumeInformationMessage{
|
|
|
|
Id: uint32(volumeCount + k),
|
|
|
|
Size: uint64(25432),
|
|
|
|
Collection: "",
|
|
|
|
FileCount: uint64(2343),
|
|
|
|
DeleteCount: uint64(345),
|
|
|
|
DeletedByteCount: 34524,
|
|
|
|
ReadOnly: false,
|
|
|
|
ReplicaPlacement: uint32(0),
|
|
|
|
Version: uint32(needle.CurrentVersion),
|
|
|
|
Ttl: 0,
|
2020-12-16 17:14:05 +00:00
|
|
|
DiskType: "ssd",
|
2020-12-13 11:11:24 +00:00
|
|
|
}
|
|
|
|
volumeMessages = append(volumeMessages, volumeMessage)
|
|
|
|
}
|
|
|
|
|
2018-06-25 07:01:53 +00:00
|
|
|
topo.SyncDataNodeRegistration(volumeMessages, dn)
|
2018-06-25 06:55:27 +00:00
|
|
|
|
2021-02-16 18:51:03 +00:00
|
|
|
usageCounts := topo.diskUsages.usages[types.HardDriveType]
|
|
|
|
|
|
|
|
assert(t, "activeVolumeCount1", int(usageCounts.activeVolumeCount), volumeCount)
|
|
|
|
assert(t, "volumeCount", int(usageCounts.volumeCount), volumeCount)
|
|
|
|
assert(t, "ssdVolumeCount", int(topo.diskUsages.usages[types.SsdType].volumeCount), volumeCount)
|
2018-06-25 06:55:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-07-11 09:01:33 +00:00
|
|
|
volumeCount := 7 - 1
|
2018-06-25 06:55:27 +00:00
|
|
|
var volumeMessages []*master_pb.VolumeInformationMessage
|
|
|
|
for k := 1; k <= volumeCount; k++ {
|
|
|
|
volumeMessage := &master_pb.VolumeInformationMessage{
|
|
|
|
Id: uint32(k),
|
|
|
|
Size: uint64(254320),
|
|
|
|
Collection: "",
|
|
|
|
FileCount: uint64(2343),
|
|
|
|
DeleteCount: uint64(345),
|
|
|
|
DeletedByteCount: 345240,
|
|
|
|
ReadOnly: false,
|
|
|
|
ReplicaPlacement: uint32(0),
|
2019-04-21 06:53:37 +00:00
|
|
|
Version: uint32(needle.CurrentVersion),
|
2018-06-25 06:55:27 +00:00
|
|
|
Ttl: 0,
|
|
|
|
}
|
|
|
|
volumeMessages = append(volumeMessages, volumeMessage)
|
|
|
|
}
|
2018-06-25 07:01:53 +00:00
|
|
|
topo.SyncDataNodeRegistration(volumeMessages, dn)
|
2018-06-25 06:55:27 +00:00
|
|
|
|
2019-04-21 06:53:37 +00:00
|
|
|
//rp, _ := storage.NewReplicaPlacementFromString("000")
|
|
|
|
//layout := topo.GetVolumeLayout("", rp, needle.EMPTY_TTL)
|
|
|
|
//assert(t, "writables", len(layout.writables), volumeCount)
|
|
|
|
|
2021-02-16 18:51:03 +00:00
|
|
|
usageCounts := topo.diskUsages.usages[types.HardDriveType]
|
|
|
|
|
|
|
|
assert(t, "activeVolumeCount1", int(usageCounts.activeVolumeCount), volumeCount)
|
|
|
|
assert(t, "volumeCount", int(usageCounts.volumeCount), volumeCount)
|
2019-04-21 06:53:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
volumeCount := 6
|
|
|
|
newVolumeShortMessage := &master_pb.VolumeShortInformationMessage{
|
|
|
|
Id: uint32(3),
|
|
|
|
Collection: "",
|
|
|
|
ReplicaPlacement: uint32(0),
|
|
|
|
Version: uint32(needle.CurrentVersion),
|
|
|
|
Ttl: 0,
|
|
|
|
}
|
|
|
|
topo.IncrementalSyncDataNodeRegistration(
|
|
|
|
[]*master_pb.VolumeShortInformationMessage{newVolumeShortMessage},
|
|
|
|
nil,
|
|
|
|
dn)
|
2019-12-23 20:48:20 +00:00
|
|
|
rp, _ := super_block.NewReplicaPlacementFromString("000")
|
2021-02-16 10:47:02 +00:00
|
|
|
layout := topo.GetVolumeLayout("", rp, needle.EMPTY_TTL, types.HardDriveType)
|
2019-04-21 06:53:37 +00:00
|
|
|
assert(t, "writables after repeated add", len(layout.writables), volumeCount)
|
|
|
|
|
2021-02-16 18:51:03 +00:00
|
|
|
usageCounts := topo.diskUsages.usages[types.HardDriveType]
|
|
|
|
|
|
|
|
assert(t, "activeVolumeCount1", int(usageCounts.activeVolumeCount), volumeCount)
|
|
|
|
assert(t, "volumeCount", int(usageCounts.volumeCount), volumeCount)
|
2019-04-21 06:53:37 +00:00
|
|
|
|
|
|
|
topo.IncrementalSyncDataNodeRegistration(
|
|
|
|
nil,
|
|
|
|
[]*master_pb.VolumeShortInformationMessage{newVolumeShortMessage},
|
|
|
|
dn)
|
|
|
|
assert(t, "writables after deletion", len(layout.writables), volumeCount-1)
|
2021-02-16 18:51:03 +00:00
|
|
|
assert(t, "activeVolumeCount1", int(usageCounts.activeVolumeCount), volumeCount-1)
|
|
|
|
assert(t, "volumeCount", int(usageCounts.volumeCount), volumeCount-1)
|
2019-04-21 06:53:37 +00:00
|
|
|
|
|
|
|
topo.IncrementalSyncDataNodeRegistration(
|
|
|
|
[]*master_pb.VolumeShortInformationMessage{newVolumeShortMessage},
|
|
|
|
nil,
|
|
|
|
dn)
|
|
|
|
|
2020-12-13 11:11:24 +00:00
|
|
|
for vid := range layout.vid2location {
|
2019-04-21 06:53:37 +00:00
|
|
|
println("after add volume id", vid)
|
|
|
|
}
|
2019-04-30 03:22:19 +00:00
|
|
|
for _, vid := range layout.writables {
|
2019-04-21 06:53:37 +00:00
|
|
|
println("after add writable volume id", vid)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(t, "writables after add back", len(layout.writables), volumeCount)
|
|
|
|
|
2018-06-25 06:55:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
topo.UnRegisterDataNode(dn)
|
|
|
|
|
2021-02-16 18:51:03 +00:00
|
|
|
usageCounts := topo.diskUsages.usages[types.HardDriveType]
|
|
|
|
|
|
|
|
assert(t, "activeVolumeCount2", int(usageCounts.activeVolumeCount), 0)
|
2018-06-25 06:55:27 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func assert(t *testing.T, message string, actual, expected int) {
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("unexpected %s: %d, expected: %d", message, actual, expected)
|
|
|
|
}
|
|
|
|
}
|
2018-07-11 09:01:33 +00:00
|
|
|
|
|
|
|
func TestAddRemoveVolume(t *testing.T) {
|
|
|
|
|
2020-04-01 19:18:40 +00:00
|
|
|
topo := NewTopology("weedfs", sequence.NewMemorySequencer(), 32*1024, 5, false)
|
2018-07-11 09:01:33 +00:00
|
|
|
|
|
|
|
dc := topo.GetOrCreateDataCenter("dc1")
|
|
|
|
rack := dc.GetOrCreateRack("rack1")
|
2021-02-16 18:51:03 +00:00
|
|
|
maxVolumeCounts := make(map[string]uint32)
|
|
|
|
maxVolumeCounts[""] = 25
|
|
|
|
maxVolumeCounts["ssd"] = 12
|
2021-09-13 05:47:52 +00:00
|
|
|
dn := rack.GetOrCreateDataNode("127.0.0.1", 34534, 0,"127.0.0.1", maxVolumeCounts)
|
2018-07-11 09:01:33 +00:00
|
|
|
|
|
|
|
v := storage.VolumeInfo{
|
2019-04-19 04:43:36 +00:00
|
|
|
Id: needle.VolumeId(1),
|
2018-07-11 09:01:33 +00:00
|
|
|
Size: 100,
|
|
|
|
Collection: "xcollection",
|
2020-12-16 17:14:05 +00:00
|
|
|
DiskType: "ssd",
|
2018-07-11 09:01:33 +00:00
|
|
|
FileCount: 123,
|
|
|
|
DeleteCount: 23,
|
|
|
|
DeletedByteCount: 45,
|
|
|
|
ReadOnly: false,
|
2019-04-19 04:43:36 +00:00
|
|
|
Version: needle.CurrentVersion,
|
2019-12-23 20:48:20 +00:00
|
|
|
ReplicaPlacement: &super_block.ReplicaPlacement{},
|
2019-04-19 04:43:36 +00:00
|
|
|
Ttl: needle.EMPTY_TTL,
|
2018-07-11 09:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dn.UpdateVolumes([]storage.VolumeInfo{v})
|
|
|
|
topo.RegisterVolumeLayout(v, dn)
|
2019-04-21 06:53:37 +00:00
|
|
|
topo.RegisterVolumeLayout(v, dn)
|
2018-07-11 09:01:33 +00:00
|
|
|
|
2018-07-11 19:52:48 +00:00
|
|
|
if _, hasCollection := topo.FindCollection(v.Collection); !hasCollection {
|
|
|
|
t.Errorf("collection %v should exist", v.Collection)
|
|
|
|
}
|
2018-07-11 09:01:33 +00:00
|
|
|
|
|
|
|
topo.UnRegisterVolumeLayout(v, dn)
|
|
|
|
|
2018-07-11 19:52:48 +00:00
|
|
|
if _, hasCollection := topo.FindCollection(v.Collection); hasCollection {
|
|
|
|
t.Errorf("collection %v should not exist", v.Collection)
|
|
|
|
}
|
2018-07-11 09:01:33 +00:00
|
|
|
|
|
|
|
}
|