Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexport unecesserry index APIs and integrate with mulitcodec #151

Merged
merged 2 commits into from
Jul 13, 2021
Merged

Unexport unecesserry index APIs and integrate with mulitcodec #151

merged 2 commits into from
Jul 13, 2021

Conversation

masih
Copy link
Member

@masih masih commented Jul 13, 2021

Use the codec dedicated to CAR index sorted when marshalling and
unmarshalling indexSorted. Note, the code depends on a specific commit
of go-multicodec master branch. This needs to be replaced with a tag
once a release is made on the go-multicodec side later.

Unexport index APIs that should not be exposed publicly. Remove
Builder now that it is not needed anywhere. Move insertionIndex into
blockstore package since that's the only place it is used.

Introduce an index constructor that takes multicodec code and
instantiates an index.

Fix ignored errors in indexsorted.go during marshalling/unmarshlling.

Rename index constructor functions to use consistent terminology; i.e.
new instead if mk.

Remove redundant TODOs in code.

Relates to:

Use the codec dedicated to CAR index sorted when marshalling and
unmarshalling `indexSorted`. Note, the code depends on a specific commit
of `go-multicodec` `master` branch. This needs to be replaced with a tag
once a release is made on the go-multicodec side later.

Unexport index APIs that should not be exposed publicly. Remove
`Builder` now that it is not needed anywhere. Move `insertionIndex` into
`blockstore` package since that's the only place it is used.

Introduce an index constructor that takes multicodec code and
instantiates an index.

Fix ignored errors in `indexsorted.go` during marshalling/unmarshlling.

Rename index constructor functions to use consistent terminology; i.e.
`new` instead if `mk`.

Remove redundant TODOs in code.

Relates to:
- multiformats/go-multicodec#46
@masih masih requested a review from mvdan July 13, 2021 11:28
}
var (
errUnsupported = errors.New("not supported")
insertionIndexCodec = 0x300003
Copy link
Contributor

Choose a reason for hiding this comment

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

surely this can be replaced by go-multicodec now?

Copy link
Member Author

Choose a reason for hiding this comment

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

this is the insertion index codec. Do we have a codec for that? I thought we only had one for sorted index.

Copy link
Member Author

Choose a reason for hiding this comment

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

Replaced this specific constant with a wrapped multicodec.Code. Please let me know if I missed anything. thanks

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah of course, I had misread the name. SGTM

IndexSingleSorted: mkSingleSorted,
IndexGobHashed: mkGobHashed,
IndexInsertion: mkInsertion,
// NewFromCodec constructs a new index corresponding to the given codec.
Copy link
Contributor

Choose a reason for hiding this comment

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

"given codec" is a bit too general IMO, as you only accept the CAR index codecs. How about "to the given CAR index codec"?

IndexGobHashed: mkGobHashed,
IndexInsertion: mkInsertion,
// NewFromCodec constructs a new index corresponding to the given codec.
func NewFromCodec(codec multicodec.Code) (Index, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if just New would work. The parameter is a multicodec.Code, so it's pretty evident that a codec is used.

And index.NewFromCodec(multicodec.IndexSorted) feels repetitive, whereas index.New(multicodec.IndexSorted) isn't and still works well.

* Rename constructor of index by codec to a simpler name and update
docs.

* Use multicodec.Code as constant instead of wrappint unit64 every time.
@masih masih merged commit a319a1b into ipld:wip-v2 Jul 13, 2021
@masih masih deleted the unexport-internal-indices branch July 13, 2021 11:45
@masih masih added this to the CAR v2 milestone Jul 13, 2021
@masih masih linked an issue Jul 13, 2021 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v2: don't expose bits of API that shouldn't be used directly
2 participants