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

Tests for unsharding PR #99

Merged

Conversation

schomatis
Copy link
Contributor

@schomatis schomatis commented Jun 23, 2021

Tests for #94.

Concurrent test being worked independently in #106.


Preliminary design review requested:

  • Only needed for io/directory_test.go, particularly TestHAMTEnumerationWhenComputingSize and countGetsDS.(Tests failing for Ubuntu but that might be expected, see more details in TestHAMTEnumerationWhenComputingSize in linked file.)
  • Focus is on testing the sizeBelowThreshold logic and making sure we are not fetching more nodes than we should. Making this the priority as it's the trickiest part to test since it's an optimization and the unsharding will work just the same without it which makes problems here harder to detect (the rest is evaluating just if the directory switched from HAMT to Basic on different scenarios, see TestUpgradeableDirectory from base PR as an illustration).
  • Lots of FIXMES and rough edges around internal interfaces to simplify HAMT logic and make it easier to test. Addressing them now it's not a priority of this review but any feedback welcome. Priority was to get something working ASAP for an early review.

@schomatis schomatis self-assigned this Jun 23, 2021
@schomatis schomatis force-pushed the schomatis/directory/unsharding-tests branch from dafe0c3 to 9fbc4b7 Compare June 23, 2021 23:09
@schomatis schomatis mentioned this pull request Jun 23, 2021
4 tasks
@schomatis schomatis force-pushed the schomatis/directory/unsharding-tests branch 2 times, most recently from 912b849 to 790373d Compare June 24, 2021 15:29
@schomatis schomatis force-pushed the schomatis/directory/unsharding branch from 068bcdd to 3301178 Compare June 29, 2021 19:42
@schomatis schomatis force-pushed the schomatis/directory/unsharding-tests branch from 445e541 to 444e5b8 Compare August 11, 2021 19:09
@aschmahmann aschmahmann changed the base branch from schomatis/directory/unsharding to schomatis/directory/unsharding-split/add-unshadring-for-addchild August 12, 2021 01:31
Copy link
Contributor

@aschmahmann aschmahmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some general comments on approach here since it looks like the PR is still a WIP.

Comment on lines +72 to +74
// FIXME: Remove. We don't actually store "value nodes". This confusing
// abstraction just removes the maxpadlen from the link names to extract
// the actual value link the trie is storing.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding of your comment here is that val.Name and maxpadlen can be used to compute key and so we shouldn't bother caching it here and just recompute it when needed. Is that correct?

Also, can you clarify if this a FIXME intended for this set of PRs?

hamt/hamt.go Show resolved Hide resolved
hamt/hamt.go Outdated Show resolved Hide resolved
hamt/hamt.go Outdated
Comment on lines 405 to 407
// EnumLinksAsync returns a channel which will receive Links in the directory
// as they are enumerated, where order is not guaranteed
func (ds *Shard) EnumAllAsync(ctx context.Context) <-chan format.LinkResult {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't needed anymore given EnumLinksAsync should be concurrent, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems not, and also seems to be unused. Removing

hamt/util.go Outdated
// the fake hash as in io.SetAndPrevious through `newHashBits()` and pass
// it as an argument making the hash independent of tree manipulation; that
// sounds as the correct way to go in general and we wouldn't need this.)
func CreateCompleteHAMT(ds ipld.DAGService, treeHeight int) (ipld.Node, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functions only used by go tests should live in _test.go files if possible.

Note: if you're running into dependency cycle issues or issues with breaking the API a tool that may be your friend here is the internal package which allows things to be exported for use within the module, but not outside of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: if you're running into dependency cycle issues or issues with breaking the API a tool that may be your friend here is the internal package which allows things to be exported for use within the module, but not outside of it.

Could you expand a bit more on that? I'm not hitting many useful results Googling golang internal package import cycle.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An example of using the internal package (although they probably abuse it) is in go-bitswap e.g. https://github.com/ipfs/go-bitswap/blob/master/internal/peermanager/peermanager.go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

io/directory_test.go Outdated Show resolved Hide resolved
@schomatis schomatis force-pushed the schomatis/directory/unsharding-split/add-unshadring-for-addchild branch 3 times, most recently from 7a7204f to 16a96a3 Compare August 26, 2021 16:42
Base automatically changed from schomatis/directory/unsharding-split/add-unshadring-for-addchild to schomatis/directory/unsharding August 26, 2021 16:44
@schomatis schomatis force-pushed the schomatis/directory/unsharding-tests branch from 599c09e to 4568234 Compare August 27, 2021 18:34
@schomatis schomatis force-pushed the schomatis/directory/unsharding-tests branch from 4568234 to d60be37 Compare August 27, 2021 18:35
io/directory_test.go Outdated Show resolved Hide resolved
io/directory_test.go Outdated Show resolved Hide resolved
io/directory_test.go Outdated Show resolved Hide resolved
@schomatis schomatis mentioned this pull request Sep 1, 2021
* wip

* fix CreateCompleteHAMT test

* relax test constraint

* fix value of nodes fetched in test according to a BFS walk
@schomatis schomatis marked this pull request as ready for review October 14, 2021 15:32
* move CreateCompleteHAMT to an internal package

* change package name: internal -> private

* move hash function to internal pacakge

* make link size function internal

* make shard width private

* add internal

* go fmt

* fix import order

* export DefaultShardWidth back again

* move IdHash to private package

* move LinkSizeFunction to private

* add linksize
hamt/hamt.go Outdated
Comment on lines 357 to 371
// FIXME: Check which functions do we need to actually expose.
func (ds *Shard) EnumAll(ctx context.Context) ([]*ipld.Link, error) {
var links []*ipld.Link

linkResults := ds.EnumAllAsync(ctx)

for linkResult := range linkResults {
if linkResult.Err != nil {
return links, linkResult.Err
}
links = append(links, linkResult.Link)
}
return links, nil
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this function is a duplicate of EnumLinks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schomatis I pushed a commit removing this

hamt/hamt.go Outdated
internal.HAMTHashFunction = murmur3Hash
}

func (ds *Shard) IsValueNode() bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be unexported again, it's not used anywhere outside this file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schomatis I pushed a commit for this

io/directory.go Outdated
@@ -316,11 +344,11 @@ func (d *BasicDirectory) GetCidBuilder() cid.Builder {
}

// SwitchToSharding returns a HAMT implementation of this directory.
func (d *BasicDirectory) SwitchToSharding(ctx context.Context) (*HAMTDirectory, error) {
func (d *BasicDirectory) SwitchToSharding(ctx context.Context, shardWidth int) (*HAMTDirectory, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change that will have to be propagated upstream, but seems reasonable 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT this isn't used by tests or anywhere else. What was the reason to make this change, just to align with hamt.NewShard()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can revert it back if you want.

io/directory.go Outdated Show resolved Hide resolved
@aschmahmann aschmahmann merged commit 51cb5fe into schomatis/directory/unsharding Oct 22, 2021
@schomatis schomatis deleted the schomatis/directory/unsharding-tests branch October 22, 2021 21:21
schomatis added a commit that referenced this pull request Oct 22, 2021
- Add tests for automatic unsharding
- Modified some internals to be sufficiently extensible for testing
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants