From 444e5b857a68ff8bb6485c3246702c7f9a5bac8e Mon Sep 17 00:00:00 2001 From: Lucas Molas Date: Tue, 29 Jun 2021 16:39:14 -0300 Subject: [PATCH] docs --- hamt/util.go | 9 ++++++++- io/directory_test.go | 13 +++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/hamt/util.go b/hamt/util.go index e4f6876dc..ce37ecfed 100644 --- a/hamt/util.go +++ b/hamt/util.go @@ -126,10 +126,17 @@ func CreateFullShard(ds ipld.DAGService, treeHeight int) (rootNode ipld.Node, er for i := 0; i < totalChildren; i++ { var hashbuf [8]byte binary.LittleEndian.PutUint64(hashbuf[:], uint64(i)) - _, err = root.SetAndPrevious(context.Background(), string(hashbuf[:treeHeight]), unixfs.EmptyFileNode()) + var previous *ipld.Link + previous, err = root.SetAndPrevious(context.Background(), string(hashbuf[:treeHeight]), unixfs.EmptyFileNode()) if err != nil { return } + if previous != nil { + // We shouldn't be overwriting any value, otherwise the tree + // won't be full. + return nil, fmt.Errorf("we have overwritten entry %s", + previous.Cid) + } } rootNode, err = root.Node() diff --git a/io/directory_test.go b/io/directory_test.go index 70e0f201f..5ad8ca8ee 100644 --- a/io/directory_test.go +++ b/io/directory_test.go @@ -264,6 +264,9 @@ func TestHAMTEnumerationWhenComputingSize(t *testing.T) { //oldShardWidth := DefaultShardWidth //defer func() { DefaultShardWidth = oldShardWidth }() //DefaultShardWidth = 8 + // FIXME: We should be able to use a smaller DefaultShardWidth to have + // a deeper tree and cheaper tests once the import cycle is resolved + // in hamt.CreateFullShard. treeHeight := 2 thresholdToWidthRatio := 4 @@ -285,9 +288,7 @@ func TestHAMTEnumerationWhenComputingSize(t *testing.T) { assert.NoError(t, err) sequentialDagService.ResetCounter() - // FIXME: Revert to const timeout after debugging. - below, timeoutExceeded := hamtDir.sizeBelowThreshold(1, func(ctx context.Context, _ *ipld.Link) { - }) + below, timeoutExceeded := hamtDir.sizeBelowThreshold(EvaluateHAMTTransitionTimeout, nil) assert.False(t, below) assert.False(t, timeoutExceeded) assert.Equal(t, nodesToFetch, sequentialDagService.UniqueCidsFetched()) @@ -433,10 +434,14 @@ func TestDirBuilder(t *testing.T) { } // serialFetchDag is a DAG service that keeps track of requested nodes -// and serves them in FIFO order to keep tight control on requests. +// and serves them in FIFO order to keep tight control on requests. (We +// don't use GetMany.) +// FIXME: We still depend on the walk function to be sequential. The name +// here might be misleading. type serialFetchDag struct { ipld.DAGService + // FIXME: Remove if we won't be using it for now. nextNode <-chan struct{} cidsFetched map[cid.Cid]struct{} mapLock sync.Mutex