-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Basic Filestore Utilties #3653
Conversation
Only |
@whyrusleeping please let me know if you are okay with these changes so far. |
2b3bd24
to
d9c40b5
Compare
6371a0d
to
b8343e0
Compare
if res.Error() != nil { | ||
return | ||
} | ||
outChan, ok := res.Output().(<-chan interface{}) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what method is that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
filestore/util.go
Outdated
} else if err, ok := err.(*CorruptReferenceError); ok { | ||
switch err.Code { | ||
case FileError: | ||
status = StatusFileError |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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,
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
Also make sure to clean out commented out imports |
Will do towards the end, some of them might still be needed. |
7b01409
to
2340263
Compare
@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. |
core/commands/filestore.go
Outdated
} | ||
} | ||
}() | ||
res.SetOutput(reader) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
filestore/util.go
Outdated
func (r *ListRes) FormatLong() string { | ||
switch { | ||
case r.Key == nil: | ||
return "?????????????????????????????????????????????????" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe <corrupt key string>
?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 && |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
@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 |
@mib-kd743naq yeah I know. I prefer the |
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug code?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 | ||
|
||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
core/commands/filestore.go
Outdated
return | ||
} | ||
|
||
out := make(chan interface{}) |
There was a problem hiding this comment.
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.
core/commands/filestore.go
Outdated
`, | ||
}, | ||
Arguments: []cmds.Argument{ | ||
cmds.StringArg("hash", true, true, "Bash58 encoded multihash of block(s) to remove."), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oversight. Will fix.
Can you also rebase it to master. |
No, it depends on |
Can I rebase |
d9c40b5
to
299f5c9
Compare
c3d6cd6
to
10e2401
Compare
299f5c9
to
1a94991
Compare
@kevina cool, will review |
Slating for 0.4.8, will review in the next few days |
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>
c40d42d
to
77648f0
Compare
Rebased yet again... |
core/commands/filestore.go
Outdated
|
||
var dupsFileStore = &cmds.Command{ | ||
Helptext: cmds.HelpText{ | ||
Tagline: "Print block both in filestore and non-filestore.", |
There was a problem hiding this comment.
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>
77648f0
to
620b52b
Compare
License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
Factored out |
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! 🚢 |
No description provided.