-
Notifications
You must be signed in to change notification settings - Fork 165
Adds basic support for pin and unpin operations #117
Conversation
I guess remove should check if the block is pinned. |
…check when upinning
Alright, a couple of changes:
|
@saresend Here's the overall spec, including what the conformance tests expect for the rs-ipfs/ipfs-rust-conformance#2 Edit: |
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 assume you're done with this? Could you please rebase your branch?
I was going to add some tests at the very least. I might leave the actual |
No problem, I'll open up a new PR for the http endpoints, just to keep concerns separate! |
It's also not clear why you're exposing it on the dag, why unpin should error if a block already is unpinned, as stuff may share blocks or how this works as you can still remove a block even if it's pinned. |
Totally fair, I'm still ramping up on IPFS and don't have great context on how you envision this being architected or how concerns are being separated. If you have suggestions on better ways to expose the API I'm all ears. My understanding of pinning is that it protects against garbage collection, and I wasn't able to find whether garbage collection is already being done in |
As far as the error goes, it should simply follow what js-ipfs or go-ipfs does. So if they error when trying to unpin and already unpinned block, then we should too. Otherwise not. |
I don't think the dag should expose pin/unpin, and if it did then the semantics would probably not be to pin the root of a path as a path can point to other blocks, so you'd want to pin the last block it refers to. Yes pin is for garbage collection, which is not currently implemented. What currently is implemented is manually removing blocks, which shouldn't happen if it's pinned. Since blocks can be shared, pinning should probably increment a counter and unpin should decrement it, instead of having a boolean. Garbage collection can be implemented by iterating through all blocks, checking if the pin count is zero and if it is remove the block. |
Where would you recommend pinning be implemented? |
src/lib.rs
Outdated
@@ -312,6 +312,21 @@ impl<Types: IpfsTypes> Ipfs<Types> { | |||
Ok(self.repo.remove_block(cid).await?) | |||
} | |||
|
|||
/// Pins a given Cid | |||
pub async fn pin_block(&self, path: IpfsPath) -> Result<(), Error> { |
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.
pub async fn pin_block(&self, path: IpfsPath) -> Result<(), Error> { | |
pub async fn pin_block(&self, cid: &Cid) -> Result<(), Error> { | |
self.repo.pin_block(cid).await | |
} |
I might suggest we focus on tests and the HTTP endpoints here, so that at least there's a foundation for architecture changes + refactors. Always room for improvement, especially if we keep getting awesome community contributions. |
Do you have anything to add in regards to my comment? Did I not explain in which ways the implementation suggested here is flawed clearly enough? Conformance tests are not a way to avoid using your brain, as tests are just as buggy as code. Besides tests do not ensure correctness, they sometimes show the presence of bugs. |
Let me try again, I'll use letters to denote blocks in the following diagram: a -> b <- c and these two concurrent processes running in parallel process 1:
put(b)
pin(b)
put(a)
pin(a)
...
unpin(a)
unpin(b)
gc() process 2:
put(b)
pin(b)
put(c)
pin(c)
get(b)??? |
Also put should probably pin automatically to prevent a race, but that's something to be discussed, if someone can supply a usecase where you don't want to put_and_pin |
I approved the PR and would have merged it if it didn't have conflicts with master. But I agree with @aphelionz, this features flaws should be extensively documented and tested. |
Before the next couple changes, I just want to clarify what you'd want for this PR. So far, the changes requested are:
Is there anything I'm missing here? |
If we didn't have the conformance tests I'd suggest removing remove altogether. Also don't use a bool as shown in the example above it can lead to issues. But mainly I'm a bit annoyed, which has nothing to do with your pr. Thanks for contributing... |
@dvc94ch @aphelionz, alright this should include a more |
Looks good! So I think this is much better, thanks. Can you rebase again, looks like it's not mergeable. |
Alright that should be merged! |
Interesting the same test is flaky on windows ... Again. Need to investigate why. |
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.
Looks good!
The test failure will be fixed with #124 but I think this is now good to merge? |
@saresend Please add yourself to rs-ipfs/welcome#1 and also let us know if you plan on doing the endpoints as well |
Yep! I plan to have a PR up in the next week or so, classes have started back up again for me so it may take me a bit longer unfortunately |
That's ok, no rush. |
What
Should address #11, by adding some basic pin / unpin operations to the dag
Todo