Skip to content

Commit

Permalink
storage: Fix detaching shared paths
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Aug 2, 2022
1 parent d117326 commit 6d29903
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
81 changes: 81 additions & 0 deletions itests/path_detach_redeclare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,87 @@ func TestPathDetachRedeclareWorker(t *testing.T) {
require.Equal(t, abi.SectorNumber(1), sps[newId][0].SectorID.Number)
}

func TestPathDetachShared(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

_ = logging.SetLogLevel("storageminer", "INFO")

var (
client kit.TestFullNode
miner kit.TestMiner
wiw, wdw, sealw kit.TestWorker
)
ens := kit.NewEnsemble(t, kit.LatestActorsAt(-1)).
FullNode(&client, kit.ThroughRPC()).
Miner(&miner, &client, kit.WithAllSubsystems(), kit.ThroughRPC(), kit.PresealSectors(2), kit.NoStorage()).
Worker(&miner, &wiw, kit.ThroughRPC(), kit.NoStorage(), kit.WithTaskTypes([]sealtasks.TaskType{sealtasks.TTGenerateWinningPoSt})).
Worker(&miner, &wdw, kit.ThroughRPC(), kit.NoStorage(), kit.WithTaskTypes([]sealtasks.TaskType{sealtasks.TTGenerateWindowPoSt})).
Worker(&miner, &sealw, kit.ThroughRPC(), kit.NoStorage(), kit.WithSealWorkerTasks).
Start()

ens.InterconnectAll()

// check there's only one path on the miner, none on the worker
sps, err := miner.StorageList(ctx)
require.NoError(t, err)
require.Len(t, sps, 1)

var id storiface.ID
for s := range sps {
id = s
}

// check that there's only one URL for the path (provided by the miner node)
si, err := miner.StorageInfo(ctx, id)
require.NoError(t, err)
require.Len(t, si.URLs, 1)

local, err := miner.StorageLocal(ctx)
require.NoError(t, err)
require.Len(t, local, 1)
require.Greater(t, len(local[id]), 1)

minerLocal := local[id]

local, err = sealw.StorageLocal(ctx)
require.NoError(t, err)
require.Len(t, local, 0)

// share the genesis sector path with the worker
require.NoError(t, sealw.StorageAddLocal(ctx, minerLocal))

// still just one path, but accessible from two places
sps, err = miner.StorageList(ctx)
require.NoError(t, err)
require.Len(t, sps, 1)

// should see 2 urls now
si, err = miner.StorageInfo(ctx, id)
require.NoError(t, err)
require.Len(t, si.URLs, 2)

// drop the path from the worker
require.NoError(t, sealw.StorageDetachLocal(ctx, minerLocal))

// the path is still registered
sps, err = miner.StorageList(ctx)
require.NoError(t, err)
require.Len(t, sps, 1)

// but with just one URL (the miner)
si, err = miner.StorageInfo(ctx, id)
require.NoError(t, err)
require.Len(t, si.URLs, 1)

// now also drop from the minel and check that the path is gone
require.NoError(t, miner.StorageDetachLocal(ctx, minerLocal))

sps, err = miner.StorageList(ctx)
require.NoError(t, err)
require.Len(t, sps, 0)
}

func checkSectors(ctx context.Context, t *testing.T, api kit.TestFullNode, miner kit.TestMiner, expectChecked, expectBad int) {
addr, err := miner.ActorAddress(ctx)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion storage/paths/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (i *Index) StorageDetach(ctx context.Context, id storiface.ID, url string)
if len(ent.info.URLs) > 0 {
drop = len(ent.info.URLs) == 1 // only one url

if ent.info.URLs[0] != url {
if drop && ent.info.URLs[0] != url {
return xerrors.Errorf("not dropping path, requested and index urls don't match ('%s' != '%s')", url, ent.info.URLs[0])
}
}
Expand Down

0 comments on commit 6d29903

Please sign in to comment.