17bdb5e9e5
Deprecate the pieceinfo database, and start storing piece info as a header to piece files. Institute a "storage format version" concept allowing us to handle pieces stored under multiple different types of storage. Add a piece_expirations table which will still be used to track expiration times, so we can query it, but which should be much smaller than the pieceinfo database would be for the same number of pieces. (Only pieces with expiration times need to be stored in piece_expirations, and we don't need to store large byte blobs like the serialized order limit, etc.) Use specialized names for accessing any functionality related only to dealing with V0 pieces (e.g., `store.V0PieceInfo()`). Move SpaceUsed- type functionality under the purview of the piece store. Add some generic interfaces for traversing all blobs or all pieces. Add lots of tests.
92 lines
2.7 KiB
Go
92 lines
2.7 KiB
Go
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package pieces_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"storj.io/storj/internal/testcontext"
|
|
"storj.io/storj/internal/testrand"
|
|
"storj.io/storj/storagenode"
|
|
"storj.io/storj/storagenode/pieces"
|
|
"storj.io/storj/storagenode/storagenodedb/storagenodedbtest"
|
|
)
|
|
|
|
func TestPieceExpirationDB(t *testing.T) {
|
|
// test GetExpired, SetExpiration, DeleteExpiration, DeleteFailed
|
|
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
|
|
ctx := testcontext.New(t)
|
|
defer ctx.Cleanup()
|
|
|
|
expireDB := db.PieceExpirationDB()
|
|
|
|
satelliteID := testrand.NodeID()
|
|
pieceID := testrand.PieceID()
|
|
expectedExpireInfo := pieces.ExpiredInfo{
|
|
SatelliteID: satelliteID,
|
|
PieceID: pieceID,
|
|
InPieceInfo: false,
|
|
}
|
|
|
|
// GetExpired with no matches
|
|
expiredPieceIDs, err := expireDB.GetExpired(ctx, time.Now(), 1000)
|
|
require.NoError(t, err)
|
|
require.Len(t, expiredPieceIDs, 0)
|
|
|
|
// DeleteExpiration with no matches
|
|
found, err := expireDB.DeleteExpiration(ctx, satelliteID, pieceID)
|
|
require.NoError(t, err)
|
|
require.False(t, found)
|
|
|
|
// DeleteFailed with no matches
|
|
err = expireDB.DeleteFailed(ctx, satelliteID, pieceID, time.Now())
|
|
require.NoError(t, err)
|
|
|
|
expireAt := time.Now()
|
|
|
|
// SetExpiration normal usage
|
|
err = expireDB.SetExpiration(ctx, satelliteID, pieceID, expireAt)
|
|
require.NoError(t, err)
|
|
|
|
// SetExpiration duplicate
|
|
err = expireDB.SetExpiration(ctx, satelliteID, pieceID, expireAt.Add(time.Hour))
|
|
require.Error(t, err)
|
|
|
|
// GetExpired normal usage
|
|
expiredPieceIDs, err = expireDB.GetExpired(ctx, expireAt.Add(time.Microsecond), 1000)
|
|
require.NoError(t, err)
|
|
require.Len(t, expiredPieceIDs, 1)
|
|
assert.Equal(t, expiredPieceIDs[0], expectedExpireInfo)
|
|
|
|
deleteFailedAt := expireAt.Add(2 * time.Microsecond)
|
|
|
|
// DeleteFailed normal usage
|
|
err = expireDB.DeleteFailed(ctx, satelliteID, pieceID, deleteFailedAt)
|
|
require.NoError(t, err)
|
|
|
|
// GetExpired filters out rows with deletion_failed_at = t
|
|
expiredPieceIDs, err = expireDB.GetExpired(ctx, deleteFailedAt, 1000)
|
|
require.NoError(t, err)
|
|
require.Len(t, expiredPieceIDs, 0)
|
|
expiredPieceIDs, err = expireDB.GetExpired(ctx, deleteFailedAt.Add(time.Microsecond), 1000)
|
|
require.NoError(t, err)
|
|
require.Len(t, expiredPieceIDs, 1)
|
|
assert.Equal(t, expiredPieceIDs[0], expectedExpireInfo)
|
|
|
|
// DeleteExpiration normal usage
|
|
found, err = expireDB.DeleteExpiration(ctx, satelliteID, pieceID)
|
|
require.NoError(t, err)
|
|
require.True(t, found)
|
|
|
|
// Should not be there anymore
|
|
expiredPieceIDs, err = expireDB.GetExpired(ctx, expireAt.Add(365*24*time.Hour), 1000)
|
|
require.NoError(t, err)
|
|
require.Len(t, expiredPieceIDs, 0)
|
|
})
|
|
}
|