Amir

What Can Be Implemented
Anonymously ?
Paper by Rachid Guerraui and Eric Ruppert
Presentation by Amir Anter
1
Talk outline
What is anonymously ?
Motivation
Anonymously implementation
Counter
Snapshot
Consensus
Summary







2
Talk outline
What is anonymously ?
Anonymously implementation
Counter
Snapshot
Consensus
Summary






3
What is anonymously ?
There is no unique identifiers for the processes.

4
Leader election in rings
2
p0
1
1
2
p2
2
p1
1
• Each process has to decide whether it is a leader or not
• Termination states are partitioned to elected and not-elected.
• In every execution, exactly one process enters an elected
state, all others enter a non-elected state.
• We assume rings are oriented.
5
Leader election in anonymous rings
2
p0
1
1
2
p2
2
p1
1
• A ring algorithm is anonymous if processes don’t have an ID
they can use in the algorithm (all perform the same code)
An anonymous leader election algorithm is…
Impossible!!
6
Motivation
Sensor networks – Might not have id’s
Privacy:




7
Web servers
Peer-to-peer sharing systems
Talk outline
What is anonymously?
Anonymously implementation
Weak Counter
Snapshot
Consensus
Summary






8
Anonymously Implementation
Number of processes is know – n.
Shared memory – multi-reader, multi-writer.
Using registers
Crash failures may occur
Deterministic
Asynchronous






9
Wait freedom
Definition:
An algorithm is wait-free if a process invoking it will finish
after a finite number of steps
10
Talk outline






What is anonymously?
Anonymously implementation
Weak Counter
Snapshot
Consensus
Summary
11
Atomic Counter
Read-Modify-Write operation:
Fetch-and-add(w, d)
do atomically
prev:=w
w:= prev+d
return prev
12
Atomic Counter
Example: the sequential spec of a counter
H0:
H1:
H2:
H3:
H4:
.
.
.
13
c.f&i()
c.f&i()
c.f&i()
c.f&i()
c:0
c:0 c.f&i() c:1
c:0 c.f&i() c:1 c.f&i() c:2
c:0 c.f&i() c:1 c.f&i() c:2 c.f&i() c:3
Atomic Counter
It has been shown by Herlihy that fetch& increment
object has no wait-free implementation from registers,
even for the non anonymous case.
14
Anonymous Counter
So how can we implement a counter only from
registers and also anonymously ?!
15
Weak Counters

Single operation: GetTimestamp


Returns an integer
Properties:




16
Let GetTimestamp(t) = x, GetTimestamp(t’)=x’, If t≥t’ then x
≥x’.
If GetTimestamp was invoked n times then each of those
invocation returned a value x ≤n.
Weaker version of fetch&increment.
Strong enough for our purposes.
Weak Counters
Example: the sequential spec of a weak
counter
H0:
H1:
H2:
H3:
H4:
.
.
.
17
c.f&i()
c.f&i()
c.f&i()
c.f&i()
c:0
c:0 c.f&i() c:1
c:0 c.f&i() c:1 c.f&i() c:1
c:0 c.f&i() c:1 c.f&i() c:1 c.f&i() c:2
Weak Counters
•
Array A[1,2,…] of binary registers.
•
Initially each register A[i]=0.
•
Invariant:
•
A
18
If A[k]=1, then all entries A[1..k]=1.
1
2
3
4
1
1
1
0
0
0
Weak Counters
A
19
1
2
3
4
0
0
0
0
0
0
Weak Counters
a
- Last location returned by the process’s previous GetTimestamp operation.
20
Weak Counters
L
-Shared register initialized to 0.
-When process change some A[b] to 1, it also writes b to L.
21
Weak Counters
j
-Local variable
-The number of times the process has seen L changes.
22
Weak Counters
t
-Local variable
-The largest value the process has seen in L.
23
Weak Counters
A
1
2
3
4
1
1
0
0
• Line 3, iteration # 1: a=1 , b=2 , l=2
• A[2]=1
24
0
0
Weak Counters
A
1
2
3
4
1
1
0
0
• Line 3, iteration # 2: a=1 , b=4 , l=2
• A[4]=0
25
0
0
Weak Counters
A
1
2
3
4
1
1
0
0
• Line 11, iteration # 1: a=1 , b=4
• mid=2
• A[2]=1  a=3
26
0
0
Weak Counters
A
1
2
3
4
1
1
0
0
• Line 11, iteration # 2: a=3 , b=4
• mid=3
• A[3]=0  b=3
27
0
0
Weak Counters
A
1
2
3
4
1
1
1
0
• Line 11, iteration # 3
• a=3=b  A[3]=1 , L=3
28
0
0
Weak Counters
•
Wait freedom


The second loop stops – binary search.
The first loop stops

•
In any finite execution in which k GetTimestamp operations
are invoked:


29
If j≥n then return t
O(k) registers are accessed.
Any operation takes O(log k).
Weak Counters
30
Talk outline






What is anonymously?
Anonymously implementation
Weak Counter
Snapshot
Consensus
Summary
31
Snapshot object


R[1…n] registers
Operations

Scan


Returns a vector V, where V is an n-element vector called a view (with
a value for each segment).
Update(d)

Process i writes d to R[i]
V[i] must return the value of the latest Updatei operation (or
the initial value if there were none)
Scan returns a snapshot of the segments array
that existed at some point during the execution!
32
A wait-free simulation of atomic snapshot
Initially segment[i].ts=0, segment[i].data=vi, segment[i].view=<v0, …, vn-1>
Updatei(S, d)
1.
view:=scan()
2.
Segment[i]=<segment[i].ts+1, d, view>
Scani(S)
1.
for all j <> i c[j]=Segment[j]
2.
while true do
3.
for all j a[j] = Segment[j]
4.
for all j b[j] = Segment[j]
5.
if, for all j a[j]=b[j] ; Comparison includes timestamp!
6.
return <b[0].data, …, b[n-1].data> ; Direct scan
7.
else if, for some j ≠ i, b[j].ts - c[j].ts ≥ 2
8.
33
return b[j].view ; Indirect scan
Anonymous snapshot object


R[1…m] registers
Operations

Scan


Update(i,x)

34
Returns a vector V, where V is an m-element vector called a view (with
a value for each segment).
Writes x to R[i]
Anonymous snapshot object
35
Anonymous snapshot object


The algorithm is anonymous and wait-free.
The average number of steps per operation in any finite
execution is O(m  n 2 )
36
Talk outline






What is anonymously?
Anonymously implementation
Weak Counter
Snapshot
Consensus
Summary
37
Consensus Object
The Consensus object: each
process has a private input
32
19
© 2003 Herlihy and Shavit
38
They Agree on Some Process’
Input
19
21
13
19
© 2003 Herlihy and Shavit
19
15
Formally: Consensus Object
- Supports a single operation: decide
- Each process pi calls decide with some input vi
from some domain. decide returns a value from
the same domain.
- The following requirements must be met:
Agreement: In any execution E, all decide
operations must return the same value.
Validity: The values returned by the
operations must equal one of the inputs.
39
FIFO queue + registers can implement
2-process consensus
Initially Q=<0> and Prefer[i]=null, i=0,1
Decide(v) ; code for pi, i=0,1
1. Prefer[i]:=v
2. qval=Q.deq()
3. if (qval = 0) then return v
4. else return Prefer[1-i]
There is a proof that wait-free consensus for 2 or more processes cannot
be solved by registers.
40
Anonymous Consensus
So how can we implement it only from registers
and also anonymously ?!
41
Obstruction freedom

Obstruction-freedom guarantees that a process will
complete its algorithm whenever it has an opportunity to
take enough steps without interruption by other
processes.
42
Consensus
43
Consensus

The algorithm is using 8n+2 registers.

Anonymous



44
Uses anonymous snapshot object.
Obstruction free
Correct
Consensus - Obstruction freedom

45
Let’s see that if process is running by itself it eventually halts.
Consensus - Obstruction freedom



46
Let C be any configuration.
m is the maximum value of R in C.
P run by itself forever from C.
Consensus - Obstruction freedom



47
lap increases at least once every 4n 1 iterations
Eventually lap  m  1 and j  1
Now P will write values larger than m to Rv in the next 4n 1 iterations.
0
Consensus - correctness



48
Let P’ be a process that decides 0 (without loss of generality).
Let T be the time P’ last scans R and S’ that scan.
We shall show that every other process that terminates also
decides 0.
Consensus - correctness


49
Let m be the minimum value in S '0
All values in S '1 are less than m.
Consensus - correctness

50
Claim 1: After T, at most n UPDATES write smaller value
than m to R.
Consensus - correctness


51
Proof: n+1 writes, let’s look at the first process P that writes to R in the
second time.
4n+1>n  one of the values in R0 is at least m, from line 10 we get
that P local lap  m  P will write at least m to R.
Consensus - correctness

52
Claim 2: After T, at most n UPDATES write a value to
R1
Consensus - correctness



53
Proof: n+1 writes, let’s look at the iteration of the first process P that
writes to R in the second time.
At most n values are greater than m in R1
From claim 1, at most n values are smaller than m in R0
Consensus - correctness

54
We get that R0 [i]  m  R1[i] for at least 4n 1 n  n  2n 1
values of i. P will change its local value to 0 in line 5.
Talk outline






What is anonymously?
Anonymously implementation
Weak Counter
Snapshot
Consensus
Summary
55
Summary




We showed anonymous algorithms by using only
read/write registers.
Weak counter – wait free implementation
Snapshot object – wait free implementations
Consensus – obstruction free implementation
56
Thank you!
57