eventual consistency

118
Terracotta Ehcache Consistency Strong and Eventual Abhishek Sanoujam March 29, 2011

Upload: abhishek-sanoujam

Post on 20-May-2015

1.381 views

Category:

Technology


3 download

DESCRIPTION

Slides explaining the consistency modes for Terracotta clustered ehcache.

TRANSCRIPT

Page 1: Eventual consistency

Terracotta Ehcache ConsistencyStrong and EventualAbhishek SanoujamMarch 29, 2011

Page 2: Eventual consistency

Terracotta Ehcache Consistency

Ehcache-2.4 + Terracotta 3.5

Search– http://ehcache.org/documentation/search.html

New Consistency modes– http://ehcache.org/documentation/terracotta/

consistency_options.html

Nonstop feature– http://ehcache.org/documentation/terracotta/non_stop_cache.html

Rejoin Explicit locking api merged to Ehcache interface Various other perf improvements and bug fixes

– http://ehcache.org

2

Page 3: Eventual consistency

Terracotta Ehcache Consistency

Terracotta Ehcache Consistency

3

Page 4: Eventual consistency

Terracotta Ehcache Consistency

Terracotta Ehcache Consistency

New attribute “consistency” in “terracotta” sub-element of “cache” in ehcache.xml

3

Page 5: Eventual consistency

Terracotta Ehcache Consistency

Terracotta Ehcache Consistency

New attribute “consistency” in “terracotta” sub-element of “cache” in ehcache.xml<cache name=”sampleCache”> <terracotta consistency=”strong|eventual” />

</cache>

3

Page 6: Eventual consistency

Terracotta Ehcache Consistency

Terracotta Ehcache Consistency

New attribute “consistency” in “terracotta” sub-element of “cache” in ehcache.xml<cache name=”sampleCache”> <terracotta consistency=”strong|eventual” />

</cache>

Consistency can be “strong” or “eventual”

3

Page 7: Eventual consistency

Terracotta Ehcache Consistency

Terracotta Ehcache Consistency

New attribute “consistency” in “terracotta” sub-element of “cache” in ehcache.xml<cache name=”sampleCache”> <terracotta consistency=”strong|eventual” />

</cache>

Consistency can be “strong” or “eventual” Old “coherent” attribute deprecated

3

Page 8: Eventual consistency

Terracotta Ehcache Consistency

Terracotta Ehcache Consistency

New attribute “consistency” in “terracotta” sub-element of “cache” in ehcache.xml<cache name=”sampleCache”> <terracotta consistency=”strong|eventual” />

</cache>

Consistency can be “strong” or “eventual” Old “coherent” attribute deprecated With “strong” consistency, changes made by any node in

the cluster are visible instantly

3

Page 9: Eventual consistency

Terracotta Ehcache Consistency

Terracotta Ehcache Consistency

New attribute “consistency” in “terracotta” sub-element of “cache” in ehcache.xml<cache name=”sampleCache”> <terracotta consistency=”strong|eventual” />

</cache>

Consistency can be “strong” or “eventual” Old “coherent” attribute deprecated With “strong” consistency, changes made by any node in

the cluster are visible instantly With “eventual” consistency, changes made by any node

are visible to other nodes eventually

3

Page 10: Eventual consistency

Terracotta Ehcache Consistency

Terracotta Ehcache Consistency

New attribute “consistency” in “terracotta” sub-element of “cache” in ehcache.xml<cache name=”sampleCache”> <terracotta consistency=”strong|eventual” />

</cache>

Consistency can be “strong” or “eventual” Old “coherent” attribute deprecated With “strong” consistency, changes made by any node in

the cluster are visible instantly With “eventual” consistency, changes made by any node

are visible to other nodes eventually http://ehcache.org/documentation/terracotta/consistency_options.html

3

Page 11: Eventual consistency

Terracotta Ehcache Consistency

Strong Consistency

4

Page 12: Eventual consistency

Terracotta Ehcache Consistency

Strong Consistency

Changes are visible cluster-wide instantly

4

Page 13: Eventual consistency

Terracotta Ehcache Consistency

Strong Consistency

Changes are visible cluster-wide instantly Reads/Writes uses clustered locks

– Clustered locks same as normal read-write locks, but valid through the cluster

– Multiple reads possible– Writes are mutually exclusive to other writes and reads

4

Page 14: Eventual consistency

Terracotta Ehcache Consistency

Strong Consistency

Changes are visible cluster-wide instantly Reads/Writes uses clustered locks

– Clustered locks same as normal read-write locks, but valid through the cluster

– Multiple reads possible– Writes are mutually exclusive to other writes and reads

Honors happens-before cluster wide (using clustered locks)

4

Page 15: Eventual consistency

Terracotta Ehcache Consistency

Strong Consistency

Changes are visible cluster-wide instantly Reads/Writes uses clustered locks

– Clustered locks same as normal read-write locks, but valid through the cluster

– Multiple reads possible– Writes are mutually exclusive to other writes and reads

Honors happens-before cluster wide (using clustered locks) Supports other concurrent apis

– putIfAbsent(Element element)– removeElement(Element element)– replace(Element element)– replace(Element old, Element element)

4

Page 16: Eventual consistency

Terracotta Ehcache Consistency

Strong Consistency

Changes are visible cluster-wide instantly Reads/Writes uses clustered locks

– Clustered locks same as normal read-write locks, but valid through the cluster

– Multiple reads possible– Writes are mutually exclusive to other writes and reads

Honors happens-before cluster wide (using clustered locks) Supports other concurrent apis

– putIfAbsent(Element element)– removeElement(Element element)– replace(Element element)– replace(Element old, Element element)

Works with explicit locking apis

4

Page 17: Eventual consistency

Terracotta Ehcache Consistency

Eventual Consistency

5

Page 18: Eventual consistency

Terracotta Ehcache Consistency

Eventual Consistency

Changes are visible to other nodes eventually (in order of ms)

5

Page 19: Eventual consistency

Terracotta Ehcache Consistency

Eventual Consistency

Changes are visible to other nodes eventually (in order of ms) L2 notifies clients about which keys were updated

5

Page 20: Eventual consistency

Terracotta Ehcache Consistency

Eventual Consistency

Changes are visible to other nodes eventually (in order of ms) L2 notifies clients about which keys were updated On receiving update from L2, those mappings are removed from

clients local cache

5

Page 21: Eventual consistency

Terracotta Ehcache Consistency

Eventual Consistency

Changes are visible to other nodes eventually (in order of ms) L2 notifies clients about which keys were updated On receiving update from L2, those mappings are removed from

clients local cache Can read stale data for some time (in order of msecs)

5

Page 22: Eventual consistency

Terracotta Ehcache Consistency

Eventual Consistency

Changes are visible to other nodes eventually (in order of ms) L2 notifies clients about which keys were updated On receiving update from L2, those mappings are removed from

clients local cache Can read stale data for some time (in order of msecs) Suitable for apps that can tolerate reading stale data

5

Page 23: Eventual consistency

Terracotta Ehcache Consistency

Eventual Consistency

Changes are visible to other nodes eventually (in order of ms) L2 notifies clients about which keys were updated On receiving update from L2, those mappings are removed from

clients local cache Can read stale data for some time (in order of msecs) Suitable for apps that can tolerate reading stale data No need of locks for reads/writes

– Better performance compared to strong consistency

5

Page 24: Eventual consistency

Terracotta Ehcache Consistency

Eventual Consistency

Changes are visible to other nodes eventually (in order of ms) L2 notifies clients about which keys were updated On receiving update from L2, those mappings are removed from

clients local cache Can read stale data for some time (in order of msecs) Suitable for apps that can tolerate reading stale data No need of locks for reads/writes

– Better performance compared to strong consistency Supports other concurrent apis

– putIfAbsent(Element element)– removeElement(Element element)– replace(Element element)– replace(Element old, Element element)

5

Page 25: Eventual consistency

Terracotta Ehcache Consistency

Eventual Consistency

Changes are visible to other nodes eventually (in order of ms) L2 notifies clients about which keys were updated On receiving update from L2, those mappings are removed from

clients local cache Can read stale data for some time (in order of msecs) Suitable for apps that can tolerate reading stale data No need of locks for reads/writes

– Better performance compared to strong consistency Supports other concurrent apis

– putIfAbsent(Element element)– removeElement(Element element)– replace(Element element)– replace(Element old, Element element)

Works with explicit locking apis– provides more control over locking

5

Page 26: Eventual consistency

Terracotta Ehcache Consistency

Old “coherent” attribute deprecated

6

Page 27: Eventual consistency

Terracotta Ehcache Consistency

Old “coherent” attribute deprecated

Old “coherent” attribute deprecated

6

Page 28: Eventual consistency

Terracotta Ehcache Consistency

Old “coherent” attribute deprecated

Old “coherent” attribute deprecated coherent=”true” translates to consistency=”strong”

6

Page 29: Eventual consistency

Terracotta Ehcache Consistency

Old “coherent” attribute deprecated

Old “coherent” attribute deprecated coherent=”true” translates to consistency=”strong” coherent=”false” translates to consistency=”eventual”

6

Page 30: Eventual consistency

Terracotta Ehcache Consistency

Old “coherent” attribute deprecated

Old “coherent” attribute deprecated coherent=”true” translates to consistency=”strong” coherent=”false” translates to consistency=”eventual” Old coherent=”false” meant bulk-load mode (incoherent

mode)– Cannot be set in config (use “eventual” consistency instead)– possible through api only now

• setNodeBulkLoadEnabled(true)• setNodeBulkLoadEnabled(false)

6

Page 31: Eventual consistency

Terracotta Ehcache Consistency

Bulk-load mode

7

Page 32: Eventual consistency

Terracotta Ehcache Consistency

Bulk-load mode

coherent=”false” - bulk load mode or incoherent mode

7

Page 33: Eventual consistency

Terracotta Ehcache Consistency

Bulk-load mode

coherent=”false” - bulk load mode or incoherent mode No locks are required for reads/writes

7

Page 34: Eventual consistency

Terracotta Ehcache Consistency

Bulk-load mode

coherent=”false” - bulk load mode or incoherent mode No locks are required for reads/writes Writes are batched heavily in the client (L1)

7

Page 35: Eventual consistency

Terracotta Ehcache Consistency

Bulk-load mode

coherent=”false” - bulk load mode or incoherent mode No locks are required for reads/writes Writes are batched heavily in the client (L1) Warmup of large caches happens pretty fast

7

Page 36: Eventual consistency

Terracotta Ehcache Consistency

Bulk-load mode

coherent=”false” - bulk load mode or incoherent mode No locks are required for reads/writes Writes are batched heavily in the client (L1) Warmup of large caches happens pretty fast Once values are fetched, changes/updates by other nodes visible after

specific time (5 mins by default)

7

Page 37: Eventual consistency

Terracotta Ehcache Consistency

Bulk-load mode

coherent=”false” - bulk load mode or incoherent mode No locks are required for reads/writes Writes are batched heavily in the client (L1) Warmup of large caches happens pretty fast Once values are fetched, changes/updates by other nodes visible after

specific time (5 mins by default) Possible through api only

7

Page 38: Eventual consistency

Terracotta Ehcache Consistency

Bulk-load mode

coherent=”false” - bulk load mode or incoherent mode No locks are required for reads/writes Writes are batched heavily in the client (L1) Warmup of large caches happens pretty fast Once values are fetched, changes/updates by other nodes visible after

specific time (5 mins by default) Possible through api only Old api’s are deprecated

– setNodeCoherent(boolean coherent)– isNodeCoherent()– isClusterCoherent()– waitUntilClusterCoherent()

7

Page 39: Eventual consistency

Terracotta Ehcache Consistency

Bulk-load mode

coherent=”false” - bulk load mode or incoherent mode No locks are required for reads/writes Writes are batched heavily in the client (L1) Warmup of large caches happens pretty fast Once values are fetched, changes/updates by other nodes visible after

specific time (5 mins by default) Possible through api only Old api’s are deprecated

– setNodeCoherent(boolean coherent)– isNodeCoherent()– isClusterCoherent()– waitUntilClusterCoherent()

New api’s added in Ehcache interface:– setNodeBulkLoadEnabled(boolean enabledBulkLoad)– isNodeBulkLoadEnabled()– isClusterBulkLoadEnabled()– waitUntilClusterBulkLoadComplete()

7

Page 40: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Page 41: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

Page 42: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

Page 43: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

Page 44: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

Page 45: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

Page 46: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

(k1, )v1

Page 47: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

(k1, )v1

(k1, v1)

Page 48: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)

(k1, )v1

(k1, v1)

Page 49: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )v1

(k1, v1)

Page 50: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

acquireLock(READ) acquireLock

(READ)

v1

(k1, v1)

Page 51: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

acquireLock(READ) acquireLock

(READ)

v1

recall

(k1, v1)

Page 52: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

acquireLock(READ) acquireLock

(READ)

v1

recall

(k1, v1)

Page 53: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

v1

recall

(k1, v1)

Page 54: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

v1

recall

(k1, v1)

Page 55: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

get(k1)get(k1)

v1

recall

(k1, v1)

Page 56: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

get(k1)get(k1)v1 v1

v1

recall

(k1, v1)

Page 57: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

get(k1)

(k1, v1) (k1, v1)

get(k1)v1 v1

v1

recall

(k1, v1)

Page 58: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

get(k1)

(k1, v1) (k1, v1)

get(k1)v1 v1

put(k1, v2)

v1

recall

(k1, v1)

Page 59: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

get(k1)

(k1, v1) (k1, v1)

get(k1)v1 v1

put(k1, v2)

v1

recall

(k1, v1)

Page 60: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

get(k1)

(k1, v1) (k1, v1)

get(k1)v1 v1

put(k1, v2)

recall recall

v1

recall

(k1, v1)

Page 61: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

get(k1)get(k1)v1 v1

put(k1, v2)

recall recall

v1

recall

Page 62: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

get(k1)get(k1)v1 v1

put(k1, v2)

recall recall

v1

recall

Page 63: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

recall recall

v1

recall

Page 64: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

recall recall

v2

recall

Page 65: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

recall recall

v2

recall

(k1, v2)

Page 66: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

recall recall

v2

recall

(k1, v2)

Page 67: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

recall recall

v2

recall

(k1, v2)

Page 68: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

recall recall

v2

recall

(k1, v2)

Page 69: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

recall recall

v2

recall

(k1, v2)

Page 70: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

recall recall

v2

recall

(k1, v2)

Page 71: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

recall recall

v2

recall

(k1, v2)

Page 72: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

recall recall

v2

recall

(k1, v2)

Page 73: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

recall recall

v2

v2 v2

recall

(k1, v2)

Page 74: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

recall recall

v2

v2 v2

(k1, v2) (k1, v2)

recall

(k1, v2)

Page 75: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

recall recall

v2

v2 v2

(k1, v2) (k1, v2)

recall

(k1, v2)

Page 76: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

recall recall

v2

v2 v2

(k1, v2) (k1, v2)

recall

(k1, v2)

Page 77: Eventual consistency

Terracotta Ehcache Consistency

How it works - Strong Consistency

8

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

acquireLock(WRITE)

Node B (L1)

put(k1, v1)

grant lock

put(k1, v1)

get(k1)get(k1)

(k1, )

grant readlock

acquireLock(READ) acquireLock

(READ)

grant readlock

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

recall recall

v2

v2 v2

(k1, v2) (k1, v2)

recall

(k1, v2)

v2 v2

Page 78: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Page 79: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

Page 80: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

Page 81: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

Page 82: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

(k1, )v1

Page 83: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

(k1, )v1

(k1, v1)

Page 84: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

get(k1)

(k1, )v1

(k1, v1)

Page 85: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

get(k1)get(k1)

(k1, )v1

(k1, v1)

Page 86: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

get(k1)get(k1)

(k1, )

get(k1)get(k1)

v1

(k1, v1)

Page 87: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

get(k1)get(k1)

(k1, )

get(k1)get(k1)v1 v1

v1

(k1, v1)

Page 88: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

get(k1)get(k1)

(k1, )

get(k1)

(k1, v1) (k1, v1)

get(k1)v1 v1

v1

(k1, v1)

Page 89: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

get(k1)get(k1)

(k1, )

get(k1)

(k1, v1) (k1, v1)

get(k1)v1 v1

put(k1, v2)

v1

(k1, v1)

Page 90: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

get(k1)get(k1)

(k1, )

get(k1)

(k1, v1) (k1, v1)

get(k1)v1 v1put(k1, v2)

put(k1, v2)

v1

(k1, v1)

Page 91: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

get(k1)get(k1)

(k1, )

get(k1)

(k1, v1) (k1, v1)

get(k1)v1 v1put(k1, v2)

put(k1, v2)

v2

(k1, v1)

Page 92: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

get(k1)get(k1)

(k1, )

get(k1)

(k1, v1) (k1, v1)

get(k1)v1 v1put(k1, v2)

put(k1, v2)

v2

(k1, v1)(k1, v2)

Page 93: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

get(k1)get(k1)

(k1, )

get(k1)

(k1, v1) (k1, v1)

get(k1)v1 v1put(k1, v2)

put(k1, v2)

v2

(k1, v1)(k1, v2)

Page 94: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

get(k1)get(k1)

(k1, )

get(k1)

(k1, v1) (k1, v1)

get(k1)v1 v1put(k1, v2)

put(k1, v2)

v2

v1

(k1, v1)(k1, v2)

Page 95: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

get(k1)get(k1)

(k1, )

get(k1)

(k1, v1) (k1, v1)

get(k1)v1 v1put(k1, v2)

put(k1, v2)

v2

v1

(k1, v1)(k1, v2)

Page 96: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

get(k1)get(k1)

(k1, )

get(k1)

(k1, v1) (k1, v1)

get(k1)v1 v1put(k1, v2)

put(k1, v2)

v2

v1 v1

(k1, v1)(k1, v2)

Page 97: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

get(k1)get(k1)

(k1, )

get(k1)

(k1, v1) (k1, v1)

get(k1)v1 v1put(k1, v2)

put(k1, v2)

v2

k1 k1

v1 v1

(k1, v1)(k1, v2)

Page 98: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

get(k1)get(k1)

(k1, )

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

v2

k1 k1

v1 v1

(k1, v1)(k1, v2)

Page 99: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

get(k1)get(k1)

(k1, )

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

v2

k1 k1

v1 v1

(k1, v1)(k1, v2)

Page 100: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

get(k1)get(k1)

(k1, )

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

v2

k1 k1

v1 v1

(k1, v1)(k1, v2)

Page 101: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

get(k1)get(k1)

(k1, )

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

v2

k1 k1

v1 v1

v2 v2

(k1, v1)(k1, v2)

Page 102: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

get(k1)get(k1)

(k1, )

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

v2

k1 k1

(k1, v2) (k1, v2)

v1 v1

v2 v2

(k1, v1)(k1, v2)

Page 103: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

get(k1)get(k1)

(k1, )

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

v2

k1 k1

(k1, v2) (k1, v2)

v1 v1v2 v2

v2 v2

(k1, v1)(k1, v2)

Page 104: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

get(k1)get(k1)

(k1, )

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

v2

k1 k1

(k1, v2) (k1, v2)

v1 v1v2 v2

v2 v2

(k1, v1)(k1, v2)

Page 105: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

get(k1)get(k1)

(k1, )

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

v2

k1 k1

(k1, v2) (k1, v2)

v1 v1v2 v2

v2 v2

(k1, v1)(k1, v2)

Page 106: Eventual consistency

Terracotta Ehcache Consistency

How it works - Eventual Consistency

9

Terracotta Server Array (L2)

Node A (L1)

Node C (L1)

Node B (L1)

put(k1, v1)

put(k1, v1)

get(k1)get(k1)

(k1, )

get(k1)get(k1)v1 v1

put(k1, v2)

put(k1, v2)

v2

k1 k1

(k1, v2) (k1, v2)

v1 v1v2 v2

v2 v2

(k1, v2)

Page 107: Eventual consistency

Terracotta Ehcache Consistency

How it works - Bulk load mode

10

Page 108: Eventual consistency

Terracotta Ehcache Consistency

How it works - Bulk load mode

Similar to eventual consistency– No locks required

10

Page 109: Eventual consistency

Terracotta Ehcache Consistency

How it works - Bulk load mode

Similar to eventual consistency– No locks required

Puts are batched heavily in the L1

10

Page 110: Eventual consistency

Terracotta Ehcache Consistency

How it works - Bulk load mode

Similar to eventual consistency– No locks required

Puts are batched heavily in the L1 The L2 don’t send out invalidation notifications

10

Page 111: Eventual consistency

Terracotta Ehcache Consistency

How it works - Bulk load mode

Similar to eventual consistency– No locks required

Puts are batched heavily in the L1 The L2 don’t send out invalidation notifications Invalidations in the local cache happen based on time (5

mins by default)

10

Page 112: Eventual consistency

Terracotta Ehcache Consistency

How it works - Bulk load mode

Similar to eventual consistency– No locks required

Puts are batched heavily in the L1 The L2 don’t send out invalidation notifications Invalidations in the local cache happen based on time (5

mins by default) Apps read stale data for the specified time interval

– configurable via tc property “ehcache.storageStrategy.dcv2.localcache.incoherentReadTimeout”

10

Page 113: Eventual consistency

Terracotta Ehcache Consistency

Comparison

Strong consistency– Reads/Writes happen under locks– Invalidations of local cache happens when a node acquires

WRITE locks

Eventual Consistency– Reads/Writes do not require locks– L2 notifies about changes to interested nodes– L1 invalidates local cache upon receiving notification from L2– Notifications are batched and sent to only interested nodes

Bulk-load mode– No locks required– Invalidations happen based on time (5 mins by default)– Puts are batched heavily in the L1

11

Page 114: Eventual consistency

Terracotta Ehcache Consistency

Summary

Strong consistency– Pros

• Provides coherent data across the cluster• Changes visible to all nodes instantly• Honors happens-before cluster wide

– Cons• If coherent cache not desired, suffers from performance• Needs locks for both reads and writes• May result in lock hopping when data not partitioned leading to perf

degradation

12

Page 115: Eventual consistency

Terracotta Ehcache Consistency

Summary

13

Page 116: Eventual consistency

Terracotta Ehcache Consistency

Summary

Eventual Consistency– Pros

• No need of locks for reads/writes• Better performance• Changes are visible across cluster in order of ms

– Cons• Application can read stale data for some time

13

Page 117: Eventual consistency

Terracotta Ehcache Consistency

Summary

Eventual Consistency– Pros

• No need of locks for reads/writes• Better performance• Changes are visible across cluster in order of ms

– Cons• Application can read stale data for some time

Bulk Load mode– Pros

• No need of locks for reads/writes• Better performance for puts, useful for cache warmup

– Cons• Application can read stale data for longer amount of time• Values once fetched, will see changes after specific amount of time

13