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

Basic Filestore Utilties #3653

Merged
merged 11 commits into from
Mar 23, 2017
Merged

Basic Filestore Utilties #3653

merged 11 commits into from
Mar 23, 2017

Conversation

kevina
Copy link
Contributor

@kevina kevina commented Feb 4, 2017

No description provided.

@kevina kevina added the status/in-progress In progress label Feb 4, 2017
@kevina
Copy link
Contributor Author

kevina commented Feb 4, 2017

Only filestore ls and filestore verify are implemented now. Still needs tests.

@kevina
Copy link
Contributor Author

kevina commented Feb 4, 2017

@whyrusleeping please let me know if you are okay with these changes so far.

if res.Error() != nil {
return
}
outChan, ok := res.Output().(<-chan interface{})
Copy link
Member

Choose a reason for hiding this comment

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

Why is this in the PostRun. Shouldnt this be a marshaler?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is in PostRun becuase I output to both stdout and stderr something that a marshaler can't do, unless I am mistaken.

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, I did a very similar thing in ipfs block rm: https://github.com/ipfs/go-ipfs/blob/master/core/commands/block.go#L283.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also ipfs add does not use a marshaler.

Copy link
Member

Choose a reason for hiding this comment

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

This should be able to go in the marshaler. You can write to stderr and stdout in the marshaler the same way you can in the PostRun. If we do weird things like this in the post run then it breaks the API expectations in a weird way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@whyrusleeping so should the Marshalers just return nil for the Reader?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@whyrusleeping okay done, let me know if its okay now.

}

k := ds.RawKey(v.Key)
c, err := dshelp.DsKeyToCid(k)
Copy link
Member

Choose a reason for hiding this comment

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

shouldnt this reuse the existing method for reading a dataobj ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what method is that?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reusing that method will involve an extra lookup as we already have the value from the iterator.

Copy link
Member

Choose a reason for hiding this comment

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

Then refactor that method so that it looks up the value and calls some dataObjFromValue method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, will look into it tomorrow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

} else if err, ok := err.(*CorruptReferenceError); ok {
switch err.Code {
case FileError:
status = StatusFileError
Copy link
Member

Choose a reason for hiding this comment

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

Why not just reuse the codes from the CorruptReferenceError ?

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 set of codes returned in ListRes is larger than the codes for CorruptReferenceError. For a little less type safety I can have CorruptReferenceError use the same codes in ListRes if you prefer it that way,

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, lets unify the sets of codes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do.

@whyrusleeping
Copy link
Member

Also make sure to clean out commented out imports

@kevina
Copy link
Contributor Author

kevina commented Feb 6, 2017

Also make sure to clean out commented out imports

Will do towards the end, some of them might still be needed.

@kevina
Copy link
Contributor Author

kevina commented Feb 8, 2017

@whyrusleeping this is about done, the final command I plan to add is "clean" which will remove invalid blocks. I will get to that early wed.

}
}
}()
res.SetOutput(reader)
Copy link
Member

Choose a reason for hiding this comment

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

Don't use a reader for output like this. Send objects over a channel like we do in the other commands so that the api is easier to deal with.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, all I am sending is Cid's, is there a Marshaler I can reuse?

Copy link
Member

Choose a reason for hiding this comment

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

The one from ipfs refs should work

func (r *ListRes) FormatLong() string {
switch {
case r.Key == nil:
return "?????????????????????????????????????????????????"
Copy link
Member

Choose a reason for hiding this comment

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

If this is never expected to happen, we should probably panic here instead of printing an ugly string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might happen, if the key is corrupt, in which case there will also be an error. The idea is to not abort and be able to move on to the next entry.

Copy link
Member

Choose a reason for hiding this comment

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

Then maybe print something useful like "corrupted key", or maybe error this entry out earlier when its detected the key is bad.

Copy link
Contributor Author

@kevina kevina Feb 9, 2017

Choose a reason for hiding this comment

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

This is what a listing with a corrupt key will likely look like to stdout:

zb2rhaPkR7ZF9BzSC2BfqbcGivi9QMdauermW9YB6NvS7FZMo   10000 somedir/file2 0
zb2rhav4wcdvNXtaKDTWHYAqtUHMEpygT1cxqMsfK7QrDuHxH  262144 somedir/file3 524288
zb2rhbcZ3aUXYcrbhhDH1JyrpDcpdw1KFJ5Xs5covjnvMpxDR    1000 somedir/file1 0
?????????????????????????????????????????????????
zb2rhebtyTTuHKyTbJPnkDUSruU5Uma4DN8t2EkvYZ6fP36mm  262144 somedir/file3 262144
zb2rhm9VTrX2mfatggYUk8mHLz78XBxVUTTzLvM2N3d6frdAU  213568 somedir/file3 786432

And to stderr:

error: could not decode cid: some-bad-key-string

The key may be corrupt, or any number of other things. I will be happy to replace ????????????????????????????????????????????????? with whatever you want (as long as it can not also be a valid key) but I don't want to panic as that will create an unnecessary special case.

Copy link
Member

Choose a reason for hiding this comment

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

maybe <corrupt key string> ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer ????????????????????????????????????????????????? but okay, I'll change it tomorrow.

}

k := ds.RawKey(v.Key)
c, err := dshelp.DsKeyToCid(k)
Copy link
Member

Choose a reason for hiding this comment

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

@whyrusleeping
Copy link
Member

Also make sure to clean up the unused imports

'

test_expect_success "'ipfs filestore ls' output looks good'" '
ipfs filestore ls | LC_ALL=C sort > ls_actual &&
Copy link
Member

Choose a reason for hiding this comment

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

What is the LC_ALL=C for? That seems really weird

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 LC_ALL is to avoid any influence from the locale environment in the sort order.

Copy link
Member

Choose a reason for hiding this comment

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

It isn't needed, sharness sets it.

'

test_expect_success "block okay now" '
ipfs cat $FILE1_HASH > /dev/null
Copy link
Member

Choose a reason for hiding this comment

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

Probably want to shasum the output or something just to be sure. If the filestore read verification was broken then this test could pass.

Also, formatting. The closing quotes should line up with the test_expect_success

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably want to shasum the output or something just to be sure. If the filestore read verification was broken then this test could pass.

okay

Also, formatting.

Sorry. The formatting is done manually. Will double check.

@mib-kd743naq
Copy link
Contributor

I prefer ????????????????????????????????????????????????? ...

@kevina perhaps I am pointing the obvious, but visual alignment would not possible anyway in more complex scenarios where the hashing type / length is not uniform. E.g. cid links to pb content and the like

@kevina
Copy link
Contributor Author

kevina commented Feb 9, 2017

perhaps I am pointing the obvious, but visual alignment would not possible anyway in more complex scenarios

@mib-kd743naq yeah I know. I prefer the ???... because it is non specific, just that there is a problem. It's not a big deal at all.

@whyrusleeping whyrusleeping added this to the ipfs 0.4.6 milestone Feb 12, 2017
Copy link
Member

@Kubuxu Kubuxu left a comment

Choose a reason for hiding this comment

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

Some comments, I will probably have more when I read it once more.


echo "WORKING DIR"
echo "IPFS PATH = " $IPFS_PATH
pwd
Copy link
Member

Choose a reason for hiding this comment

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

Debug code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ask @whyrusleeping I was using t0270-filestore-utils.sh as a template.


cat <<EOF > dups_expect
$FILE1_HASH
EOF
Copy link
Member

Choose a reason for hiding this comment

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

Is it outside of the test?

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, I didn't think it mattered. I can move it into a test if it's important.

echo "IPFS PATH = " $IPFS_PATH
pwd


Copy link
Member

Choose a reason for hiding this comment

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

General comment here, you seem to interleave workspace prep, function definitions and constant definitions, could we clean it up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I know. I didn't think it really matters. I will see what I can do.

Copy link
Member

Choose a reason for hiding this comment

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

It does as it makes harder to understand the tests, which means that in future, when they will have to be changed, already high chance of mistake will be even higher.

return
}

out := make(chan interface{})
Copy link
Member

Choose a reason for hiding this comment

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

Probably best to add some buffer.

`,
},
Arguments: []cmds.Argument{
cmds.StringArg("hash", true, true, "Bash58 encoded multihash of block(s) to remove."),
Copy link
Member

Choose a reason for hiding this comment

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

not bash but Base58, but as it is CID then it should accept just CID. CID can have base descriptor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, will fix.

@@ -124,6 +124,7 @@ var rootSubcommands = map[string]*cmds.Command{
"update": ExternalBinary(),
"version": VersionCmd,
"bitswap": BitswapCmd,
"filestore": FileStoreCmd,
Copy link
Member

Choose a reason for hiding this comment

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

It should be mentioned in helptext of main command.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oversight. Will fix.

@Kubuxu
Copy link
Member

Kubuxu commented Feb 12, 2017

Can you also rebase it to master.

@kevina
Copy link
Contributor Author

kevina commented Feb 12, 2017

Can you also rebase it to master.

No, it depends on feat/filestore0.

@Kubuxu
Copy link
Member

Kubuxu commented Feb 12, 2017

Can I rebase feat/filestore0 to master?

@whyrusleeping
Copy link
Member

@kevina cool, will review

@whyrusleeping whyrusleeping self-assigned this Mar 7, 2017
@whyrusleeping
Copy link
Member

Slating for 0.4.8, will review in the next few days

@whyrusleeping whyrusleeping self-requested a review March 11, 2017 01:13
@whyrusleeping whyrusleeping modified the milestones: Ipfs 0.4.8, Ipfs 0.4.7 Mar 11, 2017
License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
…ng file.

License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
…mands.

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

kevina commented Mar 22, 2017

Rebased yet again...


var dupsFileStore = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Print block both in filestore and non-filestore.",
Copy link
Member

Choose a reason for hiding this comment

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

Change to "List blocks that are both in the filestore and standard block storage."

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>
License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
@kevina kevina mentioned this pull request Mar 23, 2017
@kevina
Copy link
Contributor Author

kevina commented Mar 23, 2017

Factored out filestore rm as requested on IRC.

@whyrusleeping
Copy link
Member

test failures are unrelated (though still concerning). I've noted both of them and will be investigating soon.

Otherwise, lets get this show on the road! 🚢

@whyrusleeping whyrusleeping merged commit 2de21bc into master Mar 23, 2017
@Kubuxu Kubuxu deleted the kevina/filestore-util branch August 10, 2017 17:10
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.

None yet

4 participants