Skip to content

Commit

Permalink
fix: remove on-the-fly indexing (#1875)
Browse files Browse the repository at this point in the history
* remove on-the-fly indexing

* fix test
  • Loading branch information
LexLuthr authored Jan 24, 2024
1 parent baf26c6 commit 031b40e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
15 changes: 1 addition & 14 deletions piecedirectory/piecedirectory.go
Original file line number Diff line number Diff line change
Expand Up @@ -885,21 +885,8 @@ func (ps *PieceDirectory) BlockstoreGetSize(ctx context.Context, c cid.Cid) (int
return int(offsetSize.Size), nil
}

// The index is incomplete, so re-build the index on the fly
err = ps.BuildIndexForPiece(ctx, p)
if err != nil {
merr = multierror.Append(merr, fmt.Errorf("re-building index for piece %s: %w", p, err))
continue
}

// Now get the size again
offsetSize, err = ps.GetOffsetSize(ctx, p, c.Hash())
if err != nil {
merr = multierror.Append(merr, fmt.Errorf("getting size of cid %s in piece %s: %w", c, p, err))
continue
}
merr = multierror.Append(merr, fmt.Errorf("piece %s is not indexed correctly", p))

return int(offsetSize.Size), nil
}

return 0, merr
Expand Down
2 changes: 2 additions & 0 deletions piecedirectory/piecedirectory_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ func testImportedIndex(ctx context.Context, t *testing.T, cl *client.Store) {
// directory should re-build the index and then return the size.
pm := NewPieceDirectory(cl, pr, 1)
pm.Start(ctx)
err = pm.BuildIndexForPiece(ctx, pieceCid)
require.NoError(t, err)
sz, err := pm.BlockstoreGetSize(ctx, rec.Cid)
require.NoError(t, err)
require.Equal(t, len(blk.RawData()), sz)
Expand Down

0 comments on commit 031b40e

Please sign in to comment.