forked from replikativ/replikativ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
604 lines (544 loc) · 44.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
<html><head><meta content="chrome=1" http-equiv="X-UA-Compatible" /><meta charset="utf-8" /><meta content="width=device-width, initial-scale=1, user-scalable=no" name="viewport" /><title>repository API</title><style>body {
padding:50px;
font:14px/1.5 Helvetica, Arial, sans-serif;
color:#777;
font-weight:300;
}
h1, h2, h3, h4, h5, h6 {
color:#222;
margin:0 0 20px;
}
p, ul, ol, table, pre, dl {
margin:0 0 20px;
}
h1, h2, h3 {
line-height:1.1;
}
h1 {
font-size:28px;
}
h2 {
color:#393939;
}
h4, h5, h6 {
color:#494949;
margin:0;
}
header h4{
margin: 10 0 0 0px;
}
a {
color:#39c;
font-weight:400;
text-decoration:none;
}
a small {
font-size:11px;
color:#777;
margin-top:-0.6em;
display:block;
}
.wrapper {
width:860px;
margin:0 auto;
}
.figure div.img {
text-align: center;
border-radius: 5px;
border: 1px solid #ddd;
padding: 10px;
}
blockquote {
border-left:1px solid #e5e5e5;
margin:0;
padding:0 0 0 20px;
font-style:italic;
}
code, pre {
font-family:Monaco, Bitstream Vera Sans Mono, Lucida Console, Terminal;
color:#333;
font-size:12px;
}
pre {
padding:8px 15px;
background: #f8f8f8;
border-radius:5px;
border:1px solid #e5e5e5;
overflow-x: auto;
}
table {
width:100%;
border-collapse:collapse;
}
th, td {
text-align:left;
padding:5px 10px;
border-bottom:1px solid #e5e5e5;
}
dt {
color:#444;
font-weight:700;
}
th {
color:#444;
}
img {
max-width:100%;
}
header {
width:270px;
float:left;
/*position:fixed;*/
}
header ul {
list-style:none;
height:40px;
padding:0;
background: #eee;
background: -moz-linear-gradient(top, #f8f8f8 0%, #dddddd 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f8f8f8), color-stop(100%,#dddddd));
background: -webkit-linear-gradient(top, #f8f8f8 0%,#dddddd 100%);
background: -o-linear-gradient(top, #f8f8f8 0%,#dddddd 100%);
background: -ms-linear-gradient(top, #f8f8f8 0%,#dddddd 100%);
background: linear-gradient(top, #f8f8f8 0%,#dddddd 100%);
border-radius:5px;
border:1px solid #d2d2d2;
box-shadow:inset #fff 0 1px 0, inset rgba(0,0,0,0.03) 0 -1px 0;
width:270px;
}
header li {
width:89px;
float:left;
border-right:1px solid #d2d2d2;
height:40px;
}
header ul a {
line-height:1;
font-size:11px;
color:#999;
display:block;
text-align:center;
padding-top:6px;
height:40px;
}
strong {
font-weight:700;
}
header ul li + li {
width:88px;
border-left:1px solid #fff;
}
header ul li + li + li {
border-right:none;
width:89px;
}
header ul a strong {
font-size:14px;
display:block;
color:#222;
}
section {
width: 60%;
float:right;
padding-bottom:50px;
padding-right: 10%;
}
small {
font-size:11px;
}
hr {
border:0;
background:#e5e5e5;
height:1px;
margin:0 0 20px;
}
footer {
width:270px;
float:left;
position:fixed;
bottom:50px;
}
header div.heading {
display:none;
}
@media print, screen and (max-width: 960px) {
div.wrapper {
width:auto;
margin:0;
}
header, section, footer {
float:none;
position:static;
width:auto;
}
header div.heading {
display:block;
}
section div.heading {
display:none;
}
section {
border:1px solid #e5e5e5;
border-width:1px 0;
padding:20px 0;
margin:0 0 20px;
}
header a small {
display:inline;
}
header ul {
position:absolute;
right:50px;
top:52px;
}
}
@media print, screen and (max-width: 720px) {
body {
word-wrap:break-word;
}
header {
padding:0;
}
header ul, header p.view {
position:static;
}
pre, code {
word-wrap:normal;
}
}
@media print, screen and (max-width: 480px) {
body {
padding:15px;
}
header ul {
display:none;
}
}
@media print {
body {
padding:0.4in;
font-size:12pt;
color:#444;
}
}
.highlight { background: #ffffff; }
.highlight .c { color: #999988; font-style: italic } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { font-weight: bold } /* Keyword */
.highlight .o { font-weight: bold } /* Operator */
.highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
.highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */
.highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .gd .x { color: #000000; background-color: #ffaaaa } /* Generic.Deleted.Specific */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #999999 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .gi .x { color: #000000; background-color: #aaffaa } /* Generic.Inserted.Specific */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #800080; font-weight: bold; } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { font-weight: bold } /* Keyword.Constant */
.highlight .kd { font-weight: bold } /* Keyword.Declaration */
.highlight .kn { font-weight: bold } /* Keyword.Namespace */
.highlight .kp { font-weight: bold } /* Keyword.Pseudo */
.highlight .kr { font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #445588; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #009999 } /* Literal.Number */
.highlight .s { color: #d14 } /* Literal.String */
.highlight .na { color: #008080 } /* Name.Attribute */
.highlight .nb { color: #0086B3 } /* Name.Builtin */
.highlight .nc { color: #445588; font-weight: bold } /* Name.Class */
.highlight .no { color: #008080 } /* Name.Constant */
.highlight .ni { color: #800080 } /* Name.Entity */
.highlight .ne { color: #990000; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #990000; font-weight: bold } /* Name.Function */
.highlight .nn { color: #555555 } /* Name.Namespace */
.highlight .nt { color: #000080 } /* Name.Tag */
.highlight .nv { color: #008080 } /* Name.Variable */
.highlight .ow { font-weight: bold } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mf { color: #009999 } /* Literal.Number.Float */
.highlight .mh { color: #009999 } /* Literal.Number.Hex */
.highlight .mi { color: #009999 } /* Literal.Number.Integer */
.highlight .mo { color: #009999 } /* Literal.Number.Oct */
.highlight .sb { color: #d14 } /* Literal.String.Backtick */
.highlight .sc { color: #d14 } /* Literal.String.Char */
.highlight .sd { color: #d14 } /* Literal.String.Doc */
.highlight .s2 { color: #d14 } /* Literal.String.Double */
.highlight .se { color: #d14 } /* Literal.String.Escape */
.highlight .sh { color: #d14 } /* Literal.String.Heredoc */
.highlight .si { color: #d14 } /* Literal.String.Interpol */
.highlight .sx { color: #d14 } /* Literal.String.Other */
.highlight .sr { color: #009926 } /* Literal.String.Regex */
.highlight .s1 { color: #d14 } /* Literal.String.Single */
.highlight .ss { color: #990073 } /* Literal.String.Symbol */
.highlight .bp { color: #999999 } /* Name.Builtin.Pseudo */
.highlight .vc { color: #008080 } /* Name.Variable.Class */
.highlight .vg { color: #008080 } /* Name.Variable.Global */
.highlight .vi { color: #008080 } /* Name.Variable.Instance */
.highlight .il { color: #009999 } /* Literal.Number.Integer.Long */
.type-csharp .highlight .k { color: #0000FF }
.type-csharp .highlight .kt { color: #0000FF }
.type-csharp .highlight .nf { color: #000000; font-weight: normal }
.type-csharp .highlight .nc { color: #2B91AF }
.type-csharp .highlight .nn { color: #000000 }
.type-csharp .highlight .s { color: #A31515 }
.type-csharp .highlight .sc { color: #A31515 }
</style></head><body><header><div class="heading"><h1>repository API</h1><h3>An introduction to the Repository functionality.</h3><hr /><div class="info"><h5>Author: christian weilbach<b> <a href="mailto:ch_weil topiq es">(ch_weil topiq es)</a></b></h5><h5>Library: v0.1.0-SNAPSHOT</h5><h5>Date: 19 Januar 2016</h5><h5>Website: <a href="http://github.com/replikativ/replikativ">http://github.com/replikativ/replikativ</a></h5><h5>Generated By: <a href="http://www.github.com/zcaudate/lein-midje-doc">MidjeDoc</a></h5></div><br /><hr /></div><h4><a href="#metadata">1 CDVCS metadata operations</a></h4><h4><a href="#usage">2 Usage</a></h4><h5> <i><a href="#cdvcs-format">2.1 CDVCS format</a></i></h5><h5> <i><a href="#metadata">2.1.1 Metadata</a></i></h5><h5> <i><a href="#convergent-replicated-data-type-(crdt)">2.1.2 Convergent Replicated Data Type (CRDT)</a></i></h5><h5> <i><a href="#value">2.1.3 Value</a></i></h5><h5> <i><a href="#forking-and-pulling">2.2 Forking and Pulling</a></i></h5><h5> <i><a href="#forking-(cloning)">2.2.1 Forking (Cloning)</a></i></h5><h5> <i><a href="#pull">2.2.2 Pull</a></i></h5><h5> <i><a href="#committing-and-merging">2.3 Committing and Merging</a></i></h5><h5> <i><a href="#commit">2.3.1 Commit</a></i></h5><h5> <i><a href="#merge">2.3.2 Merge</a></i></h5><br /></header><section><div class="heading"><h1>repository API</h1><h3>An introduction to the Repository functionality.</h3><hr /><div class="info"><h5>Author: christian weilbach<b> <a href="mailto:ch_weil topiq es">(ch_weil topiq es)</a></b></h5><h5>Library: v0.1.0-SNAPSHOT</h5><h5>Date: 19 Januar 2016</h5><h5>Website: <a href="http://github.com/replikativ/replikativ">http://github.com/replikativ/replikativ</a></h5><h5>Generated By: <a href="http://www.github.com/zcaudate/lein-midje-doc">MidjeDoc</a></h5></div><br /><hr /></div><div><a name="metadata"></a><h2><b>1 CDVCS metadata operations</b></h2></div><div><p>In the following we will explain how <em>replikativ</em> works by building a small CDVCS containing tagged bookmarks as an example.</p></div><div><a name="usage"></a><h2><b>2 Usage</b></h2></div><div><a name="cdvcs-format"></a><h3>2.1 CDVCS format</h3></div><div><p>Metadata (without id binding) looks like:</p></div><div><div class="highlight"><pre><span class="p">{</span><span class="ss">:commit-graph</span>
<span class="p">{</span><span class="o">#</span><span class="nv">uuid</span> <span class="s">"214bd0cd-c737-4c7e-a0f5-778aca769cb7"</span> <span class="p">[]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="o">#</span><span class="nv">uuid</span> <span class="s">"214bd0cd-c737-4c7e-a0f5-778aca769cb7"</span><span class="p">}}</span>
</pre></div>
</div><div><p>We need to rebind the <em>id-generating</em> function and <em>time-function</em> to have fixed values here for testing. Otherwise ids are cryptographic <code>UUID</code>s over their referenced values by default, so they cannot and may not conflict. UUID-5 is the only option if you want to conform to the standard, so <strong>don't</strong> rebind these functions. The UUIDs represent unchangable and global values. While time can be helpful to track in commits, it is not critical for synching metadata. We will zero it out for testing here. All function calls are in fact unit tests, you can run this documentation with <em><a href='http://docs.caudate.me/lein-midje-doc/'>midje-doc</a></em>.</p></div><div><div class="highlight"><pre><span class="p">(</span><span class="kd">defn </span><span class="nv">zero-date-fn</span> <span class="p">[]</span> <span class="p">(</span><span class="nf">java.util.Date.</span> <span class="mi">0</span><span class="p">))</span>
<span class="p">(</span><span class="kd">defn </span><span class="nv">test-env</span> <span class="p">[</span><span class="nv">f</span><span class="p">]</span>
<span class="p">(</span><span class="nb">binding </span><span class="p">[</span><span class="nv">*id-fn*</span> <span class="p">(</span><span class="k">let </span><span class="p">[</span><span class="nv">counter</span> <span class="p">(</span><span class="nf">atom</span> <span class="mi">0</span><span class="p">)]</span>
<span class="p">(</span><span class="k">fn </span><span class="p">([]</span> <span class="p">(</span><span class="nf">swap!</span> <span class="nv">counter</span> <span class="nv">inc</span><span class="p">))</span>
<span class="p">([</span><span class="nv">val</span><span class="p">]</span> <span class="p">(</span><span class="nf">swap!</span> <span class="nv">counter</span> <span class="nv">inc</span><span class="p">))))</span>
<span class="nv">*date-fn*</span> <span class="nv">zero-date-fn</span><span class="p">]</span>
<span class="p">(</span><span class="nf">f</span><span class="p">)))</span>
</pre></div>
</div><div><p>First we need to create the CDVCS. The new-cdvcs function returns a map containing both the metadata and value of the new CDVCS.</p></div><div><div class="highlight"><pre><span class="p">(</span><span class="nf">test-env</span>
<span class="o">#</span><span class="p">(</span><span class="nf">cdvcs/new-cdvcs</span> <span class="s">"mail:[email protected]"</span><span class="p">))</span>
<span class="nv">=></span>
<span class="p">{</span><span class="ss">:state</span>
<span class="o">#</span><span class="nv">replikativ.crdt.CDVCS</span><span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">1</span> <span class="p">[]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">1</span><span class="p">}</span>
<span class="ss">:version</span> <span class="mi">1</span><span class="p">}</span>,
<span class="ss">:prepared</span> <span class="p">[]</span>,
<span class="ss">:downstream</span>
<span class="p">{</span><span class="ss">:crdt</span> <span class="ss">:cdvcs</span>
<span class="ss">:op</span> <span class="p">{</span><span class="ss">:method</span> <span class="ss">:new-state</span>
<span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">1</span> <span class="p">[]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">1</span><span class="p">}</span>
<span class="ss">:version</span> <span class="mi">1</span><span class="p">}}</span>,
<span class="ss">:new-values</span>
<span class="p">{</span><span class="mi">1</span>
<span class="p">{</span><span class="ss">:transactions</span> <span class="p">[]</span>,
<span class="ss">:parents</span> <span class="p">[]</span>,
<span class="ss">:ts</span> <span class="o">#</span><span class="nv">inst</span> <span class="s">"1970-01-01T00:00:00.000-00:00"</span>,
<span class="ss">:author</span> <span class="s">"mail:[email protected]"</span>
<span class="ss">:crdt</span> <span class="ss">:cdvcs</span>
<span class="ss">:version</span> <span class="mi">1</span>
<span class="ss">:crdt-refs</span> <span class="o">#</span><span class="p">{}}}}</span>
</pre></div>
</div><div><a name="metadata"></a><h3><i>2.1.1 Metadata</i></h3></div><div><p>First we have a look at the metadata structure: </p></div><div><div class="highlight"><pre><span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">1</span> <span class="p">[]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">1</span><span class="p">}}</span>
</pre></div>
</div><div><ul><li><code>:commit-graph</code> contains the whole dependency graph for revisions and is the core data we use to resolve conflicts. It points reverse from head to the root commit of the CDVCS, which is the only commit with an empty parent vector.<ul><li><code>:heads</code> tracks all heads in the graph order</li></ul></li></ul></div><div><a name="convergent-replicated-data-type-(crdt)"></a><h3><i>2.1.2 Convergent Replicated Data Type (CRDT)</i></h3></div><div><p>It is noteworthy that the metadata is a <a href='http://hal.inria.fr/docs/00/55/55/88/PDF/techreport.pdf'>CRDT</a>. Since it needs to be synched globally (in a key value store), it needs to converge to be eventual consistent. When it is, synching new versions of metadata from remote sources can happen gradually and consistently converging to the global state and values of the CDVCS. </p></div><div><p>For each key the CRDT update function for value and new-value is described:</p></div><div><div class="highlight"><pre><span class="p">(</span><span class="nf">meta/downstream</span>
<span class="p">{</span> <span class="c1">;; only new keys (commits) can be added => (merge new-value value)</span>
<span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">1</span> <span class="p">[]</span> <span class="c1">;; keys: G-SET</span>
<span class="mi">2</span> <span class="p">[</span><span class="mi">1</span><span class="p">]}</span>, <span class="c1">;; parental values don't change</span>
<span class="c1">;; keys: G-SET</span>
<span class="c1">;; values: similar to OR-SET,</span>
<span class="c1">;; (heads) are merged with lca which is commutative and idempotent,</span>
<span class="c1">;; heads cannot become empty</span>
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">2</span><span class="p">}}</span>
<span class="c1">;; new metadata information:</span>
<span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">1</span> <span class="p">[]</span>
<span class="mi">2</span> <span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="mi">3</span> <span class="p">[</span><span class="mi">2</span><span class="p">]</span>
<span class="mi">1000</span> <span class="p">[</span><span class="mi">1</span><span class="p">]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">3</span><span class="p">}})</span>
<span class="nv">=></span> <span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">1</span> <span class="p">[]</span>
<span class="mi">2</span> <span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="mi">3</span> <span class="p">[</span><span class="mi">2</span><span class="p">]</span>
<span class="mi">1000</span> <span class="p">[</span><span class="mi">1</span><span class="p">]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">3</span><span class="p">}}</span>
</pre></div>
</div><div><p>The most sophisticated operation is merging heads through lca, which is necessary to resolve stale heads. This operation has currently square complexity on the number of heads.</p></div><div><p>The operation is commutative: </p></div><div><div class="highlight"><pre><span class="p">(</span><span class="nf">meta/downstream</span>
<span class="c1">;; new metadata information:</span>
<span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">1</span> <span class="p">[]</span>
<span class="mi">2</span> <span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="mi">3</span> <span class="p">[</span><span class="mi">2</span><span class="p">]</span>
<span class="mi">1000</span> <span class="p">[</span><span class="mi">1</span><span class="p">]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">3</span><span class="p">}}</span>
<span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">1</span> <span class="p">[]</span>
<span class="mi">2</span> <span class="p">[</span><span class="mi">1</span><span class="p">]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">2</span><span class="p">}})</span>
<span class="nv">=></span> <span class="p">(</span><span class="nf">meta/downstream</span>
<span class="c1">;; new metadata information:</span>
<span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">1</span> <span class="p">[]</span>
<span class="mi">2</span> <span class="p">[</span><span class="mi">1</span><span class="p">]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">2</span><span class="p">}}</span>
<span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">1</span> <span class="p">[]</span>
<span class="mi">2</span> <span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="mi">3</span> <span class="p">[</span><span class="mi">2</span><span class="p">]</span>
<span class="mi">1000</span> <span class="p">[</span><span class="mi">1</span><span class="p">]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">3</span><span class="p">}})</span>
</pre></div>
</div><div><p>And idempotent: </p></div><div><div class="highlight"><pre><span class="p">(</span><span class="nf">meta/downstream</span>
<span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">1</span> <span class="p">[]</span>
<span class="mi">2</span> <span class="p">[]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">2</span><span class="p">}}</span>
<span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">1</span> <span class="p">[]</span>
<span class="mi">2</span> <span class="p">[]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">2</span><span class="p">}})</span>
<span class="nv">=></span> <span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">1</span> <span class="p">[]</span>
<span class="mi">2</span> <span class="p">[]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">2</span><span class="p">}}</span>
</pre></div>
</div><div><p>Which we have shown for each field of the metadata map individually above.</p></div><div><a name="value"></a><h3><i>2.1.3 Value</i></h3></div><div><div class="highlight"><pre><span class="p">{</span><span class="o">#</span><span class="nv">uuid</span> <span class="s">"04eb5b1b-4d10-5036-b235-fa173253089a"</span>
<span class="p">{</span><span class="ss">:transactions</span> <span class="p">[[</span><span class="o">'</span><span class="p">(</span><span class="k">fn </span><span class="nv">add-links</span> <span class="p">[</span><span class="nv">old</span> <span class="nv">params</span><span class="p">]</span> <span class="p">(</span><span class="nb">merge-with </span><span class="nv">set/union</span> <span class="nv">old</span> <span class="nv">params</span><span class="p">))</span> <span class="c1">;; actually uuids pointing to fn and params</span>
<span class="p">{</span><span class="ss">:economy</span> <span class="o">#</span><span class="p">{</span><span class="s">"http://opensourceecology.org/"</span><span class="p">}}]]</span>,
<span class="ss">:ts</span> <span class="o">#</span><span class="nv">inst</span> <span class="s">"1970-01-01T00:00:00.000-00:00"</span>,
<span class="ss">:author</span> <span class="s">"mail:[email protected]"</span>,
<span class="ss">:parents</span> <span class="p">[</span><span class="mi">2</span> <span class="mi">3</span><span class="p">]</span>, <span class="c1">;; normally singular, with merge sequence of parent commits applied in ascending order.</span>
<span class="ss">:crdt-refs</span> <span class="o">#</span><span class="p">{}</span>
<span class="p">}}</span>
</pre></div>
</div><div><p>The value consists of one or more transactions, each a pair of a parameter map (data) and a freely chosen data (code) to describe the transaction. The code needn't be freely evaled, but can be mapped to a limit set of application specific operations. That way it can be safely resolved via a hardcoded hash-map and will still be invariant to version changes in code. Read: You should use a literal code description instead of symbols where possible, even if this induces a small overhead.</p></div><div><a name="forking-and-pulling"></a><h3>2.2 Forking and Pulling</h3></div><div><a name="forking-(cloning)"></a><h3><i>2.2.1 Forking (Cloning)</i></h3></div><div><p>Forking yields a copy (clone).</p></div><div><div class="highlight"><pre><span class="p">(</span><span class="nf">test-env</span>
<span class="o">#</span><span class="p">(</span><span class="nf">cdvcs/fork</span> <span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">1</span> <span class="p">[]</span>
<span class="mi">3</span> <span class="p">[</span><span class="mi">1</span><span class="p">]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">3</span><span class="p">}}))</span>
<span class="nv">=></span>
<span class="p">{</span><span class="ss">:state</span>
<span class="o">#</span><span class="nv">replikativ.crdt.CDVCS</span><span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">1</span> <span class="p">[]</span>
<span class="mi">3</span> <span class="p">[</span><span class="mi">1</span><span class="p">]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">3</span><span class="p">}}</span>,
<span class="ss">:prepared</span> <span class="p">[]</span>,
<span class="ss">:downstream</span>
<span class="p">{</span><span class="ss">:crdt</span> <span class="ss">:cdvcs</span>
<span class="ss">:op</span> <span class="p">{</span><span class="ss">:method</span> <span class="ss">:new-state</span>
<span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">1</span> <span class="p">[]</span>
<span class="mi">3</span> <span class="p">[</span><span class="mi">1</span><span class="p">]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">3</span><span class="p">}</span>
<span class="ss">:version</span> <span class="mi">1</span><span class="p">}}}</span>
</pre></div>
</div><div><a name="pull"></a><h3><i>2.2.2 Pull</i></h3></div><div><p>Pulling happens much the same.</p></div><div><div class="highlight"><pre><span class="p">(</span><span class="nf">reset!</span> <span class="nv">meta/lca-cache</span> <span class="p">{})</span>
</pre></div>
</div><div><div class="highlight"><pre><span class="p">(</span><span class="nf">test-env</span>
<span class="o">#</span><span class="p">(</span><span class="nf">cdvcs/pull</span> <span class="p">{</span><span class="ss">:state</span> <span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">1</span> <span class="p">[]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">1</span><span class="p">}}</span>
<span class="ss">:prepared</span> <span class="p">[]}</span>
<span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">1</span> <span class="p">[]</span>
<span class="mi">3</span> <span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="mi">4</span> <span class="p">[</span><span class="mi">3</span><span class="p">]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">4</span><span class="p">}}</span>
<span class="mi">4</span><span class="p">))</span>
<span class="nv">=></span>
<span class="p">{</span><span class="ss">:downstream</span>
<span class="p">{</span><span class="ss">:crdt</span> <span class="ss">:cdvcs</span>
<span class="ss">:op</span> <span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">4</span> <span class="p">[</span><span class="mi">3</span><span class="p">]</span>, <span class="mi">3</span> <span class="p">[</span><span class="mi">1</span><span class="p">]</span>, <span class="mi">1</span> <span class="p">[]}</span>,
<span class="ss">:method</span> <span class="ss">:pull</span>
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">4</span><span class="p">}</span>
<span class="ss">:version</span> <span class="mi">1</span><span class="p">}}</span>,
<span class="ss">:state</span>
<span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">1</span> <span class="p">[]</span>, <span class="mi">3</span> <span class="p">[</span><span class="mi">1</span><span class="p">]</span>, <span class="mi">4</span> <span class="p">[</span><span class="mi">3</span><span class="p">]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">4</span><span class="p">}}</span>,
<span class="ss">:prepared</span> <span class="p">[]}</span>
</pre></div>
</div><div><a name="committing-and-merging"></a><h3>2.3 Committing and Merging</h3></div><div><a name="commit"></a><h3><i>2.3.1 Commit</i></h3></div><div><p>Commit to apply changes to a CDVCS.</p></div><div><div class="highlight"><pre><span class="p">(</span><span class="nf">test-env</span>
<span class="o">#</span><span class="p">(</span><span class="nf">cdvcs/commit</span> <span class="p">{</span><span class="ss">:state</span> <span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">10</span> <span class="p">[]</span>
<span class="mi">30</span> <span class="p">[</span><span class="mi">10</span><span class="p">]</span>
<span class="mi">40</span> <span class="p">[</span><span class="mi">30</span><span class="p">]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">40</span><span class="p">}}</span>
<span class="ss">:prepared</span> <span class="p">[[{</span><span class="ss">:economy</span>
<span class="o">#</span><span class="p">{</span><span class="s">"http://opensourceecology.org/"</span><span class="p">}</span>
<span class="ss">:politics</span> <span class="o">#</span><span class="p">{</span><span class="s">"http://www.economist.com/"</span><span class="p">}}</span>
<span class="o">'</span><span class="p">(</span><span class="k">fn </span><span class="nb">merge </span><span class="p">[</span><span class="nv">old</span> <span class="nv">params</span><span class="p">]</span> <span class="p">(</span><span class="nb">merge-with </span><span class="nv">set/union</span> <span class="nv">old</span> <span class="nv">params</span><span class="p">))]]}</span>
<span class="s">"mail:[email protected]"</span><span class="p">))</span>
<span class="nv">=></span>
<span class="p">{</span><span class="ss">:new-values</span>
<span class="p">{</span><span class="mi">3</span>
<span class="p">{</span><span class="ss">:transactions</span> <span class="p">[[</span><span class="mi">1</span> <span class="mi">2</span><span class="p">]]</span>,
<span class="ss">:ts</span> <span class="o">#</span><span class="nv">inst</span> <span class="s">"1970-01-01T00:00:00.000-00:00"</span>,
<span class="ss">:parents</span> <span class="p">[</span><span class="mi">40</span><span class="p">]</span>,
<span class="ss">:crdt-refs</span> <span class="o">#</span><span class="p">{}</span>
<span class="ss">:crdt</span> <span class="ss">:cdvcs</span>
<span class="ss">:version</span> <span class="mi">1</span>
<span class="ss">:author</span> <span class="s">"mail:[email protected]"</span><span class="p">}</span>,
<span class="mi">2</span> <span class="o">'</span><span class="p">(</span><span class="k">fn </span><span class="nb">merge </span><span class="p">[</span><span class="nv">old</span> <span class="nv">params</span><span class="p">]</span> <span class="p">(</span><span class="nb">merge-with </span><span class="nv">set/union</span> <span class="nv">old</span> <span class="nv">params</span><span class="p">))</span>,
<span class="mi">1</span>
<span class="p">{</span><span class="ss">:politics</span> <span class="o">#</span><span class="p">{</span><span class="s">"http://www.economist.com/"</span><span class="p">}</span>,
<span class="ss">:economy</span> <span class="o">#</span><span class="p">{</span><span class="s">"http://opensourceecology.org/"</span><span class="p">}}}</span>,
<span class="ss">:downstream</span>
<span class="p">{</span><span class="ss">:crdt</span> <span class="ss">:cdvcs</span>
<span class="ss">:op</span> <span class="p">{</span><span class="ss">:method</span> <span class="ss">:commit</span>
<span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">3</span> <span class="p">[</span><span class="mi">40</span><span class="p">]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">3</span><span class="p">}</span>
<span class="ss">:version</span> <span class="mi">1</span><span class="p">}}</span>,
<span class="ss">:state</span>
<span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">3</span> <span class="p">[</span><span class="mi">40</span><span class="p">]</span>, <span class="mi">10</span> <span class="p">[]</span>, <span class="mi">30</span> <span class="p">[</span><span class="mi">10</span><span class="p">]</span>, <span class="mi">40</span> <span class="p">[</span><span class="mi">30</span><span class="p">]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">3</span><span class="p">}}</span>,
<span class="ss">:prepared</span> <span class="p">[]}</span>
</pre></div>
</div><div><a name="merge"></a><h3><i>2.3.2 Merge</i></h3></div><div><p>You can check whether a merge is necessary (there are multiple heads):</p></div><div><div class="highlight"><pre><span class="p">(</span><span class="nf">test-env</span>
<span class="o">#</span><span class="p">(</span><span class="nf">cdvcs/multiple-heads?</span> <span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">10</span> <span class="p">[]</span>
<span class="mi">30</span> <span class="p">[</span><span class="mi">10</span><span class="p">]</span>
<span class="mi">40</span> <span class="p">[</span><span class="mi">10</span><span class="p">]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">40</span> <span class="mi">30</span><span class="p">}}))</span>
<span class="nv">=></span> <span class="nv">true</span>
</pre></div>
</div><div><p>Merging is like pulling but resolving the commit-graph of the conflicting head commits with a new commit, which can apply further corrections atomically. You have to supply the remote-metadata and a vector of parents, which are applied to the CDVCS value in order before the merge commit.</p></div><div><div class="highlight"><pre><span class="p">(</span><span class="nf">test-env</span>
<span class="o">#</span><span class="p">(</span><span class="nf">cdvcs/merge</span> <span class="p">{</span><span class="ss">:state</span> <span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">10</span> <span class="p">[]</span>
<span class="mi">30</span> <span class="p">[</span><span class="mi">10</span><span class="p">]</span>
<span class="mi">40</span> <span class="p">[</span><span class="mi">10</span><span class="p">]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">40</span><span class="p">}}</span>
<span class="ss">:prepared</span> <span class="p">[]}</span>
<span class="s">"mail:[email protected]"</span>
<span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">10</span> <span class="p">[]</span>
<span class="mi">20</span> <span class="p">[</span><span class="mi">10</span><span class="p">]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">20</span><span class="p">}}</span>
<span class="p">[</span><span class="mi">40</span> <span class="mi">20</span><span class="p">]</span>
<span class="p">[]))</span>
<span class="nv">=></span>
<span class="p">{</span><span class="ss">:new-values</span>
<span class="p">{</span><span class="mi">1</span>
<span class="p">{</span><span class="ss">:transactions</span> <span class="p">[]</span>,
<span class="ss">:ts</span> <span class="o">#</span><span class="nv">inst</span> <span class="s">"1970-01-01T00:00:00.000-00:00"</span>,
<span class="ss">:parents</span> <span class="p">[</span><span class="mi">40</span> <span class="mi">20</span><span class="p">]</span>,
<span class="ss">:crdt-refs</span> <span class="o">#</span><span class="p">{}</span>
<span class="ss">:crdt</span> <span class="ss">:cdvcs</span>
<span class="ss">:version</span> <span class="mi">1</span>
<span class="ss">:author</span> <span class="s">"mail:[email protected]"</span><span class="p">}}</span>,
<span class="ss">:downstream</span> <span class="p">{</span><span class="ss">:crdt</span> <span class="ss">:cdvcs</span>
<span class="ss">:op</span> <span class="p">{</span><span class="ss">:method</span> <span class="ss">:merge</span>
<span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">1</span> <span class="p">[</span><span class="mi">40</span> <span class="mi">20</span><span class="p">]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">1</span><span class="p">}</span>
<span class="ss">:version</span> <span class="mi">1</span><span class="p">}}</span>,
<span class="ss">:state</span>
<span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">1</span> <span class="p">[</span><span class="mi">40</span> <span class="mi">20</span><span class="p">]</span>, <span class="mi">20</span> <span class="p">[</span><span class="mi">10</span><span class="p">]</span>, <span class="mi">10</span> <span class="p">[]</span>, <span class="mi">30</span> <span class="p">[</span><span class="mi">10</span><span class="p">]</span>, <span class="mi">40</span> <span class="p">[</span><span class="mi">10</span><span class="p">]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">1</span><span class="p">}}</span>,
<span class="ss">:prepared</span> <span class="p">[]}</span>
</pre></div>
</div><div><p>When there are pending commits, you need to resolve them first as well.</p></div><div><div class="highlight"><pre><span class="p">(</span><span class="nf">test-env</span>
<span class="o">#</span><span class="p">(</span><span class="nf">try</span>
<span class="p">(</span><span class="nf">cdvcs/merge</span> <span class="p">{</span><span class="ss">:state</span> <span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">10</span> <span class="p">[]</span>
<span class="mi">30</span> <span class="p">[</span><span class="mi">10</span><span class="p">]</span>
<span class="mi">40</span> <span class="p">[</span><span class="mi">10</span><span class="p">]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">40</span><span class="p">}}</span>
<span class="ss">:prepared</span> <span class="p">[[{</span><span class="ss">:economy</span> <span class="o">#</span><span class="p">{</span><span class="s">"http://opensourceecology.org/"</span><span class="p">}</span>
<span class="ss">:politics</span> <span class="o">#</span><span class="p">{</span><span class="s">"http://www.economist.com/"</span><span class="p">}}</span>
<span class="o">'</span><span class="p">(</span><span class="k">fn </span><span class="nv">merge-bookmarks</span> <span class="p">[</span><span class="nv">old</span> <span class="nv">params</span><span class="p">]</span>
<span class="p">(</span><span class="nb">merge-with </span><span class="nv">set/union</span> <span class="nv">old</span> <span class="nv">params</span><span class="p">))]]}</span>
<span class="s">"mail:[email protected]"</span>
<span class="p">{</span><span class="ss">:commit-graph</span> <span class="p">{</span><span class="mi">10</span> <span class="p">[]</span>
<span class="mi">20</span> <span class="p">[</span><span class="mi">10</span><span class="p">]}</span>,
<span class="ss">:heads</span> <span class="o">#</span><span class="p">{</span><span class="mi">20</span><span class="p">}}</span>
<span class="p">[</span><span class="mi">40</span> <span class="mi">20</span><span class="p">]</span>
<span class="p">[])</span>
<span class="p">(</span><span class="nf">catch</span> <span class="nv">clojure.lang.ExceptionInfo</span> <span class="nv">e</span>
<span class="p">(</span><span class="nb">= </span><span class="p">(</span><span class="nb">-> </span><span class="nv">e</span> <span class="nv">ex-data</span> <span class="ss">:type</span><span class="p">)</span> <span class="ss">:transactions-pending-might-conflict</span><span class="p">))))</span>
<span class="nv">=></span> <span class="nv">true</span>
</pre></div>
</div><div><p>Have a look at the <a href='replication.html'>replication API</a>, the [stage API](http://whilo.github.io/replikativ/stage.html) and the [pull hooks](http://whilo.github.io/replikativ/hooks.html) as well. Further documentation will be added, have a look at the <a href='https://github.com/ghubber/replikativ/blob/master/test/replikativ/core_test.clj'>test/replikativ/core_test.clj</a> tests or the <a href='doc/index.html'>API docs</a> for implementation details.</p></div></section></body><script type="text/javascript">var metas = document.getElementsByTagName('meta');
var i;
if (navigator.userAgent.match(/iPhone/i)) {
for (i=0; i<metas.length; i++) {
if (metas[i].name == "viewport") {
metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0";
}
}
document.addEventListener("gesturestart", gestureStart, false);
}
function gestureStart() {
for (i=0; i<metas.length; i++) {
if (metas[i].name == "viewport") {
metas[i].content = "width=device-width, minimum-scale=0.25, maximum-scale=1.6";
}
}
}</script></html>