Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 599c09e

Browse files
committed
minor docs
1 parent 23e23fa commit 599c09e

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

io/directory_test.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func TestUpgradeableDirectory(t *testing.T) {
254254
compareDirectoryEntries(t, upgradedDir, dir, []*ipld.Link{missingLink})
255255
}
256256

257-
// Test that we fetch as little nodes needed to reach the HAMTShardingSize
257+
// Test that we fetch as little nodes as needed to reach the HAMTShardingSize
258258
// during the sizeBelowThreshold computation.
259259
// FIXME: This only works for a sequential DAG walk.
260260
// FIXME: Failing in the CI for Ubuntu. This may likely be an indication of race
@@ -269,7 +269,7 @@ func TestHAMTEnumerationWhenComputingSize(t *testing.T) {
269269
// are the "value" links pointing to antyhing that is *not* another Shard).
270270
estimatedLinkSize = mockLinkSizeFunc(1)
271271
defer func() { estimatedLinkSize = productionLinkSize }()
272-
// Use an identity hash function to ease the construction of "full" HAMTs
272+
// Use an identity hash function to ease the construction of "complete" HAMTs
273273
// (see CreateCompleteHAMT below for more details). (Ideally this should be
274274
// a parameter we pass and not a global option we modify in the caller.)
275275
oldHashFunc := hamt.HAMTHashFunction
@@ -280,38 +280,40 @@ func TestHAMTEnumerationWhenComputingSize(t *testing.T) {
280280
//DefaultShardWidth = 8
281281
// FIXME: We should be able to use a smaller DefaultShardWidth to have
282282
// a deeper tree and cheaper tests once the import cycle is resolved
283-
// in hamt.CreateCompleteHAMT.
283+
// in hamt.CreateCompleteHAMT and the DefaultShardWidth value is not
284+
// hardcoded there.
284285

285286
// We create a "complete" HAMT (see CreateCompleteHAMT for more details)
286287
// with a regular structure to be able to predict how many Shard nodes we
287288
// will need to fetch in order to reach the HAMTShardingSize threshold in
288289
// sizeBelowThreshold (assuming a sequential DAG walk function).
289290
oldHamtOption := HAMTShardingSize
290291
defer func() { HAMTShardingSize = oldHamtOption }()
292+
// (Some arbitrary values below that make this test not that expensive.)
291293
treeHeight := 2
292294
thresholdToWidthRatio := 4 // How many leaf shards nodes (with value links,
293-
// directory entries) do we need to reach the threshold.
295+
// i.e., directory entries) do we need to reach the threshold.
294296
HAMTShardingSize = DefaultShardWidth * thresholdToWidthRatio
295297
// With this structure we will then need to fetch the following nodes:
296-
// * `thresholdToWidthRatio` leaf Shards with enough value link to reach
298+
// * `thresholdToWidthRatio` leaf Shards with enough value links to reach
297299
// the HAMTShardingSize threshold.
298300
// * `(treeHeight - 1)` internal nodes to reach those leaf Shard nodes
299301
// (assuming we have thresholdToWidthRatio below the DefaultShardWidth,
300302
// i.e., all leaf nodes come from the same parent).
301303
nodesToFetch := thresholdToWidthRatio + treeHeight - 1
302304
ds := mdtest.Mock()
303-
node, err := hamt.CreateCompleteHAMT(ds, treeHeight)
305+
completeHAMTRoot, err := hamt.CreateCompleteHAMT(ds, treeHeight)
304306
assert.NoError(t, err)
305307

306308
countGetsDS := newCountGetsDS(ds)
307-
hamtDir, err := newHAMTDirectoryFromNode(countGetsDS, node)
309+
hamtDir, err := newHAMTDirectoryFromNode(countGetsDS, completeHAMTRoot)
308310
assert.NoError(t, err)
309311

310312
countGetsDS.resetCounter()
311313
// FIXME: Only works with sequential DAG walk (now hardcoded, needs to be
312314
// added to the internal API) where we can predict the Get requests and
313315
// tree traversal. It would be desirable to have some test for the concurrent
314-
// walk (actually used in production).
316+
// walk (which is the one used in production).
315317
below, err := hamtDir.sizeBelowThreshold(context.TODO(), 0)
316318
assert.NoError(t, err)
317319
assert.False(t, below)
@@ -491,17 +493,17 @@ func (d *countGetsDS) uniqueCidsFetched() int {
491493
func (d *countGetsDS) Get(ctx context.Context, c cid.Cid) (ipld.Node, error) {
492494
node, err := d.DAGService.Get(ctx, c)
493495
if err != nil {
494-
return node, err
496+
return nil, err
495497
}
496498

497499
d.mapLock.Lock()
498500
d.cidsFetched[c] = struct{}{}
499501
d.mapLock.Unlock()
500502

501-
return node, err
503+
return node, nil
502504
}
503505

504-
// Process sequentially. We don't care about performance here.
506+
// Process sequentially (blocking) calling Get which tracks requests.
505507
func (d *countGetsDS) GetMany(ctx context.Context, cids []cid.Cid) <-chan *ipld.NodeOption {
506508
out := make(chan *ipld.NodeOption, len(cids))
507509
defer close(out)

0 commit comments

Comments
 (0)