Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the connection between ipfs pin and MFS?

Tags:

ipfs

There are two concepts in IPFS, the connection of which is not very clear to me: IPFS pin and IPFS MFS.

As I understand it, ipfs pin allows you to keep content on your node, protecting it from being automatically removed by the garbage collector. In this case, if I add content by myself using ipfs add <file>, then it will be automatically pinned and then it can be unpinned and removed only manually.

IPFS MFS, on the other hand, allows objects to be manipulated as if they were in the file system. For example, I can copy a specific external object to MFS using ipfs files cp <id> <name>. After that, I can find out its ID using ipfs files stat <name>.

The questions are:

  1. Are the files in MFS protected from being removed by garbage collector?
  2. If protected, then why are they not displayed in ipfs pin ls?
  3. Will the data be saved if I add it using ipfs add <file>, then add it to MFS using ipfs files cp <id> <name>, and then unpin it using ipfs pin rm <id>?
  4. Is IPFS MFS a more reliable way to work with data?
like image 968
Raisongran Avatar asked Jan 13 '19 10:01

Raisongran


1 Answers

these pretty good questions! Answering them separately

  1. Are the files in MFS protected from being removed by garbage collector?

They are not by default Pinned. You will need to pin those files as well if you want them tracked by the Pinner. You can do a ipfs files stat /somePath, get the hash and then pin that hash.

The part where it gets confusing is that GC will do a "best effort" pinning, in which files that are accessed by the root of the MFS DAG will not be GC as well.

Example:

  • You add a file to MFS
  • You make a modification to that file on MFS
  • The previous version will get GC'ed
  • The latest version will be protected from GC

If you want to protect the previous, you can use the Pin API.

  1. If protected, then why are they not displayed in ipfs pin ls?

As answered on 1., you will need to pin them manually to see it being tracked by the pinning system.

  1. Will the data be saved if I add it using ipfs add <file>, then add it to MFS using ipfs files cp <id> <name>, and then unpin it using ipfs pin rm <id>?

Perhaps you get the gist by now. To clarify:

  • Pinning is a protection for garbage collection (GC). If pinned, GC won't delete it
  • MFS doesn't auto pin files. GC just tries to be friends with MFS and not GC files that are reachable by the root of MFS.
  1. Is IPFS MFS a more reliable way to work with data?

It is a more familiar way as you get the regular directory structures and Unix like API to operate over files. It handles the graph manipulations for you.

like image 141
David Dias Avatar answered Sep 27 '22 19:09

David Dias