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

"block rm": move core functionally into blockstore_util package #3225

Merged
merged 4 commits into from
Sep 20, 2016

Conversation

kevina
Copy link
Contributor

@kevina kevina commented Sep 14, 2016

No description provided.

@kevina
Copy link
Contributor Author

kevina commented Sep 14, 2016

I refactored the "block rm" code so I can reuse it in #2634.

@kevina kevina changed the title "blockstore rm": move core functionally into blockstore_util package "block rm": move core functionally into blockstore_util package Sep 14, 2016
@kevina
Copy link
Contributor Author

kevina commented Sep 14, 2016

The teamcity failure looks completely unrelated to my change...

@kevina
Copy link
Contributor Author

kevina commented Sep 15, 2016

@whyrusleeping I would like to get this merged ASAP as moving code around is guaranteed to produce conflicts in the future.

}

func RmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, out chan<- interface{}, cids []*cid.Cid, opts RmBlocksOpts) error {
go func() {
Copy link
Member

Choose a reason for hiding this comment

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

This feels weird that the function returns an error, but all it does is spawn a goroutine and returns nil...

Copy link
Contributor Author

@kevina kevina Sep 15, 2016

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Ah, 👍

} else {
out <- &RemovedBlock{
Hash: r.Key.String(),
Error: r.String(),
Copy link
Member

Choose a reason for hiding this comment

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

Is Error being overloaded to contain other information?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. r.String() returns a message as to why the block is pinned. If RemovedBlock returns with the Error field it means the block could not be removed.


func (err RmError) Error() string { return err.Msg }

func ProcRmOutput(in <-chan interface{}, sout io.Writer, serr io.Writer) *RmError {
Copy link
Member

Choose a reason for hiding this comment

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

return type here should just be error. Otherwise you get into weird issues where:

var err error
err = ProcRmOutput(...)
// err is never nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The return type is a pointer to RmError which implemets the error interface and can (and does) return nil. Nevertheless I no longer require the extra information that RmError returns so I removed that structure and just use a normal error now.

Copy link
Member

Choose a reason for hiding this comment

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

@kevina I understand, The issue with the (old) code is this: https://play.golang.org/p/0YxTEK55zb

@whyrusleeping
Copy link
Member

What are we accomplishing by moving this out to a separate package?

License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
Note: this code can not go in the "blockstore" package due to a
circular dependency with the "pin" package.

License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
@kevina
Copy link
Contributor Author

kevina commented Sep 15, 2016

@whyrusleeping to answer your direct question, this code is it's own package because I am not sure where else to put it. The code can not go in the blockstore package because that will create a circular dependency with the "pin" package.

The refactoring is necessary so that I can reuse it in #2634 For example in filestore clean I use FilterPinned to make sure I am not clearing out any pinned blocks.

@whyrusleeping
Copy link
Member

@kevina okay, that sounds good to me.

@kevina kevina added RFM and removed status/in-progress In progress labels Sep 20, 2016
@whyrusleeping whyrusleeping merged commit 87ecb92 into master Sep 20, 2016
@whyrusleeping whyrusleeping deleted the kevina/rm-block-refactor branch September 20, 2016 02:30
@ghost ghost mentioned this pull request Dec 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants