2012-08-29 16:42:24 +08:00
|
|
|
package topology
|
|
|
|
|
|
|
|
import (
|
2018-07-11 17:01:33 +08:00
|
|
|
"fmt"
|
2018-06-25 14:55:27 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
2018-07-11 17:01:33 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/sequence"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage"
|
|
|
|
"github.com/kr/pretty"
|
|
|
|
"testing"
|
2012-08-29 16:42:24 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRemoveDataCenter(t *testing.T) {
|
2012-09-03 05:33:48 +08:00
|
|
|
topo := setup(topologyLayout)
|
|
|
|
topo.UnlinkChildNode(NodeId("dc2"))
|
|
|
|
if topo.GetActiveVolumeCount() != 15 {
|
2012-09-01 17:20:59 +08:00
|
|
|
t.Fail()
|
|
|
|
}
|
2012-09-03 05:33:48 +08:00
|
|
|
topo.UnlinkChildNode(NodeId("dc3"))
|
|
|
|
if topo.GetActiveVolumeCount() != 12 {
|
2012-09-01 17:20:59 +08:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
2018-06-25 14:55:27 +08:00
|
|
|
|
|
|
|
func TestHandlingVolumeServerHeartbeat(t *testing.T) {
|
|
|
|
topo := NewTopology("weedfs", sequence.NewMemorySequencer(), 32*1024, 5)
|
|
|
|
|
|
|
|
dc := topo.GetOrCreateDataCenter("dc1")
|
|
|
|
rack := dc.GetOrCreateRack("rack1")
|
|
|
|
dn := rack.GetOrCreateDataNode("127.0.0.1", 34534, "127.0.0.1", 25)
|
|
|
|
|
|
|
|
{
|
2018-07-11 17:01:33 +08:00
|
|
|
volumeCount := 7
|
2018-06-25 14:55:27 +08: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),
|
|
|
|
Version: uint32(1),
|
|
|
|
Ttl: 0,
|
|
|
|
}
|
|
|
|
volumeMessages = append(volumeMessages, volumeMessage)
|
|
|
|
}
|
|
|
|
|
2018-06-25 15:01:53 +08:00
|
|
|
topo.SyncDataNodeRegistration(volumeMessages, dn)
|
2018-06-25 14:55:27 +08:00
|
|
|
|
|
|
|
assert(t, "activeVolumeCount1", topo.activeVolumeCount, volumeCount)
|
|
|
|
assert(t, "volumeCount", topo.volumeCount, volumeCount)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-07-11 17:01:33 +08:00
|
|
|
volumeCount := 7 - 1
|
2018-06-25 14:55:27 +08: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),
|
|
|
|
Version: uint32(1),
|
|
|
|
Ttl: 0,
|
|
|
|
}
|
|
|
|
volumeMessages = append(volumeMessages, volumeMessage)
|
|
|
|
}
|
2018-06-25 15:01:53 +08:00
|
|
|
topo.SyncDataNodeRegistration(volumeMessages, dn)
|
2018-06-25 14:55:27 +08:00
|
|
|
|
|
|
|
assert(t, "activeVolumeCount1", topo.activeVolumeCount, volumeCount)
|
|
|
|
assert(t, "volumeCount", topo.volumeCount, volumeCount)
|
|
|
|
}
|
|
|
|
|
|
|
|
topo.UnRegisterDataNode(dn)
|
|
|
|
|
|
|
|
assert(t, "activeVolumeCount2", topo.activeVolumeCount, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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 17:01:33 +08:00
|
|
|
|
|
|
|
func TestAddRemoveVolume(t *testing.T) {
|
|
|
|
|
|
|
|
topo := NewTopology("weedfs", sequence.NewMemorySequencer(), 32*1024, 5)
|
|
|
|
|
|
|
|
dc := topo.GetOrCreateDataCenter("dc1")
|
|
|
|
rack := dc.GetOrCreateRack("rack1")
|
|
|
|
dn := rack.GetOrCreateDataNode("127.0.0.1", 34534, "127.0.0.1", 25)
|
|
|
|
|
|
|
|
v := storage.VolumeInfo{
|
|
|
|
Id: storage.VolumeId(1),
|
|
|
|
Size: 100,
|
|
|
|
Collection: "xcollection",
|
|
|
|
FileCount: 123,
|
|
|
|
DeleteCount: 23,
|
|
|
|
DeletedByteCount: 45,
|
|
|
|
ReadOnly: false,
|
|
|
|
Version: storage.CurrentVersion,
|
|
|
|
ReplicaPlacement: &storage.ReplicaPlacement{},
|
|
|
|
Ttl: storage.EMPTY_TTL,
|
|
|
|
}
|
|
|
|
|
|
|
|
dn.UpdateVolumes([]storage.VolumeInfo{v})
|
|
|
|
topo.RegisterVolumeLayout(v, dn)
|
|
|
|
|
|
|
|
fmt.Printf("added volume 1 \n%# v\n", pretty.Formatter(topo.ToMap()))
|
|
|
|
|
|
|
|
topo.UnRegisterVolumeLayout(v, dn)
|
|
|
|
|
|
|
|
fmt.Printf("removed volume 1 \n%# v\n", pretty.Formatter(topo.ToMap()))
|
|
|
|
|
|
|
|
}
|