diff --git a/weed/topology/duplicate_volume_id_test.go b/weed/topology/duplicate_volume_id_test.go index 5fb315ea88..201583410b 100644 --- a/weed/topology/duplicate_volume_id_test.go +++ b/weed/topology/duplicate_volume_id_test.go @@ -73,6 +73,30 @@ func TestSameLayoutReplicaIsNotDuplicate(t *testing.T) { } } +func TestSameLayoutReplicaWithoutTtlIsNotDuplicate(t *testing.T) { + topo := NewTopology("topo", nil, 128, 3, false) + rp, _ := super_block.NewReplicaPlacementFromString("001") + + dn1 := NewDataNode("server1") + dn1.Ip = "10.0.0.1" + dn1.Port = 8080 + dn2 := NewDataNode("server2") + dn2.Ip = "10.0.0.2" + dn2.Port = 8080 + + v1 := storage.VolumeInfo{Id: 7, Collection: "a", ReplicaPlacement: rp, Ttl: needle.EMPTY_TTL} + v2 := storage.VolumeInfo{Id: 7, Collection: "a", ReplicaPlacement: rp} + dn1.UpdateVolumes([]storage.VolumeInfo{v1}) + dn2.UpdateVolumes([]storage.VolumeInfo{v2}) + topo.RegisterVolumeLayout(v1, dn1) + topo.RegisterVolumeLayout(v2, dn2) + topo.duplicateFlagChecks.Wait() + + if topo.isQuarantined(dn1, v1.Id) || topo.isQuarantined(dn2, v2.Id) { + t.Fatal("a nil ttl and the empty ttl share one layout, so the replica is not a duplicate") + } +} + func TestSameNodeVolumeMoveIsNotDuplicate(t *testing.T) { topo := NewTopology("topo", nil, 128, 3, false) rp, _ := super_block.NewReplicaPlacementFromString("000") diff --git a/weed/topology/topology.go b/weed/topology/topology.go index 81db2ff59a..47efeac322 100644 --- a/weed/topology/topology.go +++ b/weed/topology/topology.go @@ -1084,10 +1084,7 @@ func volumeLayoutKey(collection string, rp *super_block.ReplicaPlacement, ttl *n } func ttlEqual(a, b *needle.TTL) bool { - if a == nil || b == nil { - return a == b - } - return a.ToUint32() == b.ToUint32() + return a.String() == b.String() } // findDuplicateVolumeLayouts reports every layout that already holds v.Id on