Advertise filters param in discovery doc.
[arvados.git] / doc / user / tutorials / tutorial-keep.html.textile.liquid
1 ---
2 layout: default
3 navsection: userguide
4 navmenu: Tutorials
5 title: "Storing and Retrieving data using Arvados Keep"
6
7 ...
8
9 h1. Storing and Retrieving data using Arvados Keep
10
11 This tutorial introduces you to the Arvados file storage system.
12
13
14 *This tutorial assumes that you are "logged into an Arvados VM instance":{{site.baseurl}}/user/getting_started/ssh-access.html#login, and have a "working environment.":{{site.baseurl}}/user/getting_started/check-environment.html*
15
16 The Arvados distributed file system is called *Keep*.  Keep is a content-addressable file system.  This means that files are managed using special unique identifiers derived from the _contents_ of the file, rather than human-assigned file names (specifically, the md5 hash).  This has a number of advantages:
17 * Files can be stored and replicated across a cluster of servers without requiring a central name server.
18 * Systematic validation of data integrity by both server and client because the checksum is built into the identifier.
19 * Minimizes data duplication (two files with the same contents will result in the same identifier, and will not be stored twice.)
20 * Avoids data race conditions (an identifier always points to the same data.)
21
22 h1. Putting Data into Keep
23
24 We will start with downloading a freely available VCF file from the "Personal Genome Project (PGP)":http://www.personalgenomes.org subject "hu599905":https://my.personalgenomes.org/profile/hu599905 to a staging directory on the VM, and then add it to Keep.
25
26 In the following tutorials, replace <b><code>you</code></b> with your user id.
27
28 First, log into the Arvados VM instance and set up the staging area:
29
30 notextile. <pre><code>~$ <span class="userinput">mkdir /scratch/<b>you</b></span></code></pre>
31
32 Next, download the file:
33
34 <notextile>
35 <pre><code>~$ <span class="userinput">cd /scratch/<b>you</b></span>
36 /scratch/<b>you</b>$ <span class="userinput">curl -o var-GS000016015-ASM.tsv.bz2 'https://warehouse.personalgenomes.org/warehouse/f815ec01d5d2f11cb12874ab2ed50daa+234+K@ant/var-GS000016015-ASM.tsv.bz2'</span>
37   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
38                                  Dload  Upload   Total   Spent    Left  Speed
39 100  216M  100  216M    0     0  10.0M      0  0:00:21  0:00:21 --:--:-- 9361k
40 </code></pre>
41 </notextile>
42
43 {% include 'notebox_begin' %}
44
45 If you have your own data, for example @MyData.vcf@, you can use @scp@ or @rsync@ to copy from your local workstation to the shell VM (run this on your local workstation):
46
47 notextile. <pre><code>~$ <span class="userinput">scp MyData.vcf <b>you@shell</b>.arvados:/scratch/<b>you</b>/MyData.vcf</span></code></pre>
48
49 {% include 'notebox_end' %}
50
51 Now use @arv keep put@ to add your VCF data to Keep, then delete the local copy of the file:
52
53 <notextile>
54 <pre><code>/scratch/<b>you</b>$ <span class="userinput">arv keep put var-GS000016015-ASM.tsv.bz2</span>
55 c1bad4b39ca5a924e481008009d94e32+210
56 /scratch/<b>you</b>$ <span class="userinput">rm var-GS000016015-ASM.tsv.bz2</span>
57 </code></pre>
58 </notextile>
59
60 The output value @c1bad4b39ca5a924e481008009d94e32+210@ from @arv keep put@ is the Keep locator.  This enables you to access the file you just uploaded, and is explained in the next section.
61
62 h2. Putting a directory
63
64 You can also use @arv keep put@ to add an entire directory:
65
66 <notextile>
67 <pre><code>/scratch/<b>you</b>$ <span class="userinput">mkdir tmp</span>
68 /scratch/<b>you</b>$ <span class="userinput">echo "hello alice" > tmp/alice.txt</span>
69 /scratch/<b>you</b>$ <span class="userinput">echo "hello bob" > tmp/bob.txt</span>
70 /scratch/<b>you</b>$ <span class="userinput">echo "hello carol" > tmp/carol.txt</span>
71 /scratch/<b>you</b>$ <span class="userinput">arv keep put tmp</span>
72 0M / 0M 100.0% 
73 887cd41e9c613463eab2f0d885c6dd96+83
74 </code></pre>
75 </notextile>
76
77 h1. Getting Data from Keep
78
79 In Keep, information is stored in *data blocks*.  Data blocks are normally between 1 byte and 64 megabytes in size.  If a file exceeds the maximum size of a single data block, the file will be split across multiple data blocks until the entire file can be stored.  These data blocks may be stored and replicated across multiple disks, servers, or clusters.  Each data block has its own identifier for the contents of that specific data block.
80
81 In order to reassemble the file, Keep stores a *collection* data block which lists in sequence the data blocks that make up the original file.  A collection data block may store the information for multiple files, including a directory structure.
82
83 In this example we will use @c1bad4b39ca5a924e481008009d94e32+210@ which we added to keep in the previous section.  First let us examine the contents of this collection using @arv keep get@:
84
85 <notextile>
86 <pre><code>/scratch/<b>you</b>$ <span class="userinput">arv keep get c1bad4b39ca5a924e481008009d94e32+210</span>
87 . 204e43b8a1185621ca55a94839582e6f+67108864 b9677abbac956bd3e86b1deb28dfac03+67108864 fc15aff2a762b13f521baf042140acec+67108864 323d2a3ce20370c4ca1d3462a344f8fd+25885655 0:227212247:var-GS000016015-ASM.tsv.bz2
88 </code></pre>
89 </notextile>
90
91 The command @arv keep get@ fetches the contents of the locator @c1bad4b39ca5a924e481008009d94e32+210@.  This is a locator for a collection data block, so it fetches the contents of the collection.  In this example, this collection consists of a single file @var-GS000016015-ASM.tsv.bz2@ which is 227212247 bytes long, and is stored using four sequential data blocks, <code>204e43b8a1185621ca55a94839582e6f+67108864</code>, <code>b9677abbac956bd3e86b1deb28dfac03+67108864</code>, <code>fc15aff2a762b13f521baf042140acec+67108864</code>, <code>323d2a3ce20370c4ca1d3462a344f8fd+25885655</code>.
92
93 Let's use @arv keep get@ to download the first datablock:
94
95 notextile. <pre><code>/scratch/<b>you</b>$ <span class="userinput">arv keep get 204e43b8a1185621ca55a94839582e6f+67108864 &gt; block1</span></code></pre>
96
97 Let's look at the size and compute the md5 hash of @block1@:
98
99 <notextile>
100 <pre><code>/scratch/<b>you</b>$ <span class="userinput">ls -l block1</span>
101 -rw-r--r-- 1 you group 67108864 Dec  9 20:14 block1
102 /scratch/<b>you</b>$ <span class="userinput">md5sum block1</span>
103 204e43b8a1185621ca55a94839582e6f  block1
104 </code></pre>
105 </notextile>
106
107 Notice that the block identifer <code>204e43b8a1185621ca55a94839582e6f+67108864</code> of:
108 * the md5 hash @204e43b8a1185621ca55a94839582e6f@ which matches the md5 hash of @block1@
109 * a size hint @67108864@ which matches the size of @block1@
110
111 Next, let's use @arv keep get@ to download and reassemble @var-GS000016015-ASM.tsv.bz2@ using the following command:
112
113 <notextile>
114 <pre><code>/scratch/<b>you</b>$ <span class="userinput">arv keep get c1bad4b39ca5a924e481008009d94e32+210/var-GS000016015-ASM.tsv.bz2 .</span>
115 </code></pre>
116
117 This downloads the file @var-GS000016015-ASM.tsv.bz2@ described by collection @c1bad4b39ca5a924e481008009d94e32+210@ from Keep and places it into the local directory.  Now that we have the file, we can compute the md5 hash of the complete file:
118
119 <notextile>
120 <pre><code>/scratch/<b>you</b>$ <span class="userinput">md5sum var-GS000016015-ASM.tsv.bz2</span>
121 44b8ae3fde7a8a88d2f7ebd237625b4f  var-GS000016015-ASM.tsv.bz2
122 </code></pre>
123 </notextile>
124
125 h2. Accessing Collections
126
127 There are a couple of other ways to access a collection.  You may view the contents of a collection using @arv keep ls@:
128
129 <notextile>
130 <pre><code>/scratch/<b>you</b>$ <span class="userinput">arv keep ls c1bad4b39ca5a924e481008009d94e32+210</span>
131 var-GS000016015-ASM.tsv.bz2
132 /scratch/<b>you</b>$ <span class="userinput">arv keep ls -s c1bad4b39ca5a924e481008009d94e32+210</span>
133 221887 var-GS000016015-ASM.tsv.bz2
134 </code></pre>
135 </notextile>
136
137 * @-s@ prints file sizes in kilobytes
138
139 You may also access through the Arvados Workbench using a URI similar to this, where the last part of the path is the Keep locator:
140
141 "https://workbench.{{ site.arvados_api_host }}/collections/c1bad4b39ca5a924e481008009d94e32+210":https://workbench.{{ site.arvados_api_host }}/collections/c1bad4b39ca5a924e481008009d94e32+210
142
143 You are now ready to proceed to the next tutorial, "running a crunch job.":tutorial-job1.html