storj/satellite/overlay/piececount_test.go
Jessica Grebenschikov 803e2930f4 satellite: use IP for all uplink operations, use hostname for audit and repairs
My understanding is that the nodes table has the following fields:
- `address` field which can be a hostname or an IP
- `last_net` field that is the /24 subnet of the IP resolved from the address

This PR does the following:
1) add back the `last_ip` field to the nodes table
2) for uplink operations remove the calls that the satellite makes to `lookupNodeAddress` (which makes the DNS calls to resolve the IP from the hostname) and instead use the data stored in the nodes table `last_ip` field. This means that the IP that the satellite sends to the uplink for the storage nodes could be approx 1 hr stale. In the short term this is fine, next we will be adding changes so that the storage node pushes any IP changes to the satellite in real time.
3) use the address field for repair and audit since we want them to still make DNS calls to confirm the IP is up to date
4) try to reduce confusion about hostname, ip, subnet, and address in the code base

Change-Id: I96ce0d8bb78303f82483d0701bc79544b74057ac
2020-03-11 09:11:40 -07:00

119 lines
2.9 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package overlay_test
import (
"math"
"testing"
"github.com/stretchr/testify/require"
"storj.io/common/pb"
"storj.io/common/storj"
"storj.io/common/testcontext"
"storj.io/common/testrand"
"storj.io/storj/satellite"
"storj.io/storj/satellite/overlay"
"storj.io/storj/satellite/satellitedb/satellitedbtest"
)
func TestDB_PieceCounts(t *testing.T) {
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
overlaydb := db.OverlayCache()
type TestNode struct {
ID storj.NodeID
PieceCount int // TODO: fix to int64
}
nodes := make([]TestNode, 100)
for i := range nodes {
nodes[i].ID = testrand.NodeID()
nodes[i].PieceCount = int(math.Pow10(i + 1))
}
for _, node := range nodes {
n := pb.Node{
Id: node.ID,
Address: &pb.NodeAddress{
Transport: pb.NodeTransport_TCP_TLS_GRPC,
Address: "0.0.0.0",
},
}
d := overlay.NodeDossier{Node: n, LastIPPort: "0.0.0.0", LastNet: "0.0.0.0"}
require.NoError(t, overlaydb.UpdateAddress(ctx, &d, overlay.NodeSelectionConfig{}))
}
// check that they are initialized to zero
initialCounts, err := overlaydb.AllPieceCounts(ctx)
require.NoError(t, err)
require.Empty(t, initialCounts)
// TODO: make AllPieceCounts return results for all nodes,
// since it will keep the logic slightly clearer.
// update counts
counts := make(map[storj.NodeID]int)
for _, node := range nodes {
counts[node.ID] = node.PieceCount
}
err = overlaydb.UpdatePieceCounts(ctx, counts)
require.NoError(t, err)
// fetch new counts
updatedCounts, err := overlaydb.AllPieceCounts(ctx)
require.NoError(t, err)
// verify values
for _, node := range nodes {
count, ok := updatedCounts[node.ID]
require.True(t, ok)
require.Equal(t, count, node.PieceCount)
}
})
}
func BenchmarkDB_PieceCounts(b *testing.B) {
satellitedbtest.Bench(b, func(b *testing.B, db satellite.DB) {
ctx := testcontext.New(b)
defer ctx.Cleanup()
overlaydb := db.OverlayCache()
counts := make(map[storj.NodeID]int)
for i := 0; i < 10000; i++ {
counts[testrand.NodeID()] = testrand.Intn(100000)
}
for nodeID := range counts {
n := pb.Node{
Id: nodeID,
Address: &pb.NodeAddress{
Transport: pb.NodeTransport_TCP_TLS_GRPC,
Address: "0.0.0.0",
},
}
d := overlay.NodeDossier{Node: n, LastIPPort: "0.0.0.0", LastNet: "0.0.0.0"}
require.NoError(b, overlaydb.UpdateAddress(ctx, &d, overlay.NodeSelectionConfig{}))
}
b.Run("Update", func(b *testing.B) {
for i := 0; i < b.N; i++ {
err := overlaydb.UpdatePieceCounts(ctx, counts)
if err != nil {
b.Fatal(err)
}
}
})
b.Run("All", func(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := overlaydb.AllPieceCounts(ctx)
if err != nil {
b.Fatal(err)
}
}
})
})
}