Consistency Model

Introduction

The three main properties of correctness,scalability and fault tolerance, consistency model takes care of the correctness aspect. It applies to any distributed systems, it cant be avoided

Distributed systems involve concurrent reads and writes

Distributed Shared Memory(DSM)

Each machine in the network can access a common address space, they also have a local copy of all memory

Pasted image 20231019114859.png
Even though theres 3 programs running, but its a sequential code since p2 busy waits for p1 to be done and p3 wait for p2 to be done to access both v1 and v2

Naive DSM protocol

On read:
ready any variable from local memory
On write:
perform asynchronous write, sends an update message to all other machine, do not wait

Problem

Causality violation

Pasted image 20231019115627.png
p2 might not get the most updated value of v1 and it sends done2 to p3 before v1 can reach p3 This will lead to p3 to carry out f3 with outdated value of v1 and wrong value of v2 since v2 is computed base on outdated value of v1 and hence lead to unexpected outcome

Summary

This protocol is fast but has unexpected consequences to user applications if protocol features are not known

What is consistency model

Strict Consistency

Excercise

Pasted image 20231019123441.png
W(v1)P1 -> w(done1)P1
w(done1)P1 -> r(done1)P2
r(done1)p2 -> r(v1)p2

hence w(v1)p1 -> r(v1)p2
Therefore, during r(done1)P2, we already have w(v1)P1 and therefore, while reading updated done1, we already have updated v1.

Sequential Consistency

Example

Pasted image 20231030122038.png

Question

Is this situation ever possible if the system implements Sequential Consistency?

Infer

Read 2.2 -> Write 1.1 (by construction)
Write 1.1 -> write1.2 (by rule 1)
Write 1.2 -> Read 2.1 (by construction)
Read 2.1 -> Read 2.2(by rule 1)

Answer

Therefore Read 2.2 -> Read 2.1 Which is a contradiction

Naive DSM protocol and sequential consistency

Pasted image 20231030122829.png
When you read, you read from the memory, and when you write you send the write to other machine's memory

Possible violation

Violation #1ReadWriteWriteThis may happenbefore write1 finishw1w2You cannot establish any order of which event happen before which other eventViolation #2

  1. All operations in one machine are executed in order (e.g. in program order)
    1. Naïve DSM protocol does not wait for the Write to complete. Thus can go ahead to read from local memory before the preceding write finishes. This violates Rule #1 of sequential consistency.
  2. All machines observe results according to some total order (i.e. reads see most recent writes)
    1. We note that two machines can issue concurrent Writes and different machines can receive these writes in different order, thus violating the total order enforced by sequential consistency model.

Causal Consistency

All causally-related read/write ops were executed in an order that reflects their causality

Rules

  1. All operations in one machine are executed in order (e.g. in program order)
    1. Read/Write operations in the same machines are causally related w.r.t. the order they appear
  2. All causally-related operations are executed according to some order capturing their causality
    1. Concurrent operations may be observed in different order by different machines

Example

Pasted image 20231030122038.png

Question

Is this situation ever possible if the system implements causal Consistency?

Infer

  1. Read 2.2 -> Write 1.1 (by construction)
  2. Write 1.2 -> Read 2.1 (causal order)
  3. Read 2.1 -> Read 2.2(causal order)
  4. write 1.1 -> write 1.2 (causal order)

Therefore base on 1 and 5, Read 2.1 -> write 1.2

Advantages

Total Store Order

Machines might be able to change the order of read and write if they are on different objects, it does have to respect the program order

Example

a machine might execute w(x)a and r(y)? in any order. However, it cannot reorder, w(x)a and r(x)?

Rules

  1. Read by other machines cannot return a new value of an object until the respective write to the same object is observed by all machines.

Implementation

  1. Store buffer
    1. fast, faster than Dram
    2. periodically flush to DSM
    3. For Write
  2. Invalidation
    1. During Read
    2. Invalidate all remote/local copies (other machine will be force to go to the share memory instead of their own memory)

Eventual Consistency

Rules

Advantage

If a machine is disconnected from the network can still allow operation

Disadvantage

Stale reads
Writes are not ordered, they may create conflicts later

Eventual vs Sequential Consistency

Example

File Synchorizer: A set of machines containing common files.

Goal

Dealing with Conflicts

Depends on the type of application

Case Study: IVY

Read Protocol

Write Protocol

Properties