storj/satellite/repair/clumping_test.go
paul cannon 915f3952af satellite/repair: repair pieces on the same last_net
We avoid putting more than one piece of a segment on the same /24
network (or /64 for ipv6). However, it is possible for multiple pieces
of the same segment to move to the same network over time. Nodes can
change addresses, or segments could be uploaded with dev settings, etc.
We will call such pieces "clumped", as they are clumped into the same
net, and are much more likely to be lost or preserved together.

This change teaches the repair checker to recognize segments which have
clumped pieces, and put them in the repair queue. It also teaches the
repair worker to repair such segments (treating clumped pieces as
"retrievable but unhealthy"; i.e., they will be replaced on new nodes if
possible).

Refs: https://github.com/storj/storj/issues/5391
Change-Id: Iaa9e339fee8f80f4ad39895438e9f18606338908
2023-04-06 17:34:25 +00:00

65 lines
1.6 KiB
Go

// Copyright (C) 2023 Storj Labs, Inc.
// See LICENSE for copying information.
package repair_test
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
"storj.io/common/testrand"
"storj.io/storj/satellite/metabase"
"storj.io/storj/satellite/repair"
)
func TestFindClumpedPieces(t *testing.T) {
pieces := make(metabase.Pieces, 10)
for n := range pieces {
pieces[n] = metabase.Piece{
Number: 0,
StorageNode: testrand.NodeID(),
}
}
t.Run("all-separate-nets", func(t *testing.T) {
lastNets := make([]string, len(pieces))
for n := range lastNets {
lastNets[n] = fmt.Sprintf("172.16.%d.0", n)
}
clumped := repair.FindClumpedPieces(pieces, lastNets)
require.Len(t, clumped, 0)
})
t.Run("one-clumped", func(t *testing.T) {
lastNets := make([]string, len(pieces))
for n := range lastNets {
lastNets[n] = fmt.Sprintf("172.16.%d.0", n)
}
lastNets[len(lastNets)-1] = lastNets[0]
clumped := repair.FindClumpedPieces(pieces, lastNets)
require.Equal(t, metabase.Pieces{pieces[len(pieces)-1]}, clumped)
})
t.Run("all-clumped", func(t *testing.T) {
lastNets := make([]string, len(pieces))
for n := range lastNets {
lastNets[n] = "172.16.41.0"
}
clumped := repair.FindClumpedPieces(pieces, lastNets)
require.Equal(t, pieces[1:], clumped)
})
t.Run("two-clumps", func(t *testing.T) {
lastNets := make([]string, len(pieces))
for n := range lastNets {
lastNets[n] = fmt.Sprintf("172.16.%d.0", n)
lastNets[2] = lastNets[0]
lastNets[4] = lastNets[1]
}
clumped := repair.FindClumpedPieces(pieces, lastNets)
require.Equal(t, metabase.Pieces{pieces[2], pieces[4]}, clumped)
})
}