Committed by
Gerrit Code Review
Ensure local read/write operations are causally consistent when a ConsistentMap …
…is build with weakConsistency option Change-Id: I1ec96048b646f5074e5e50001e08753212b98395
Showing
2 changed files
with
20 additions
and
2 deletions
... | @@ -26,8 +26,12 @@ import com.google.common.cache.CacheLoader; | ... | @@ -26,8 +26,12 @@ import com.google.common.cache.CacheLoader; |
26 | import com.google.common.cache.LoadingCache; | 26 | import com.google.common.cache.LoadingCache; |
27 | 27 | ||
28 | /** | 28 | /** |
29 | - * Extension of DefaultAsyncConsistentMap that provides a weaker read consistency | 29 | + * Extension of {@link DefaultAsyncConsistentMap} that provides a weaker read consistency |
30 | * guarantee in return for better read performance. | 30 | * guarantee in return for better read performance. |
31 | + * <p> | ||
32 | + * For read/write operations that are local to a node this map implementation provides | ||
33 | + * guarantees similar to a ConsistentMap. However for read/write operations executed | ||
34 | + * across multiple nodes this implementation only provides eventual consistency. | ||
31 | * | 35 | * |
32 | * @param <K> key type | 36 | * @param <K> key type |
33 | * @param <V> value type | 37 | * @param <V> value type |
... | @@ -68,4 +72,10 @@ public class AsyncCachingConsistentMap<K, V> extends DefaultAsyncConsistentMap<K | ... | @@ -68,4 +72,10 @@ public class AsyncCachingConsistentMap<K, V> extends DefaultAsyncConsistentMap<K |
68 | } | 72 | } |
69 | return cache.getUnchecked(key); | 73 | return cache.getUnchecked(key); |
70 | } | 74 | } |
75 | + | ||
76 | + @Override | ||
77 | + protected void beforeUpdate(K key) { | ||
78 | + super.beforeUpdate(key); | ||
79 | + cache.invalidate(key); | ||
80 | + } | ||
71 | } | 81 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -405,6 +405,14 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V | ... | @@ -405,6 +405,14 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V |
405 | .thenApply(v -> v.updated()); | 405 | .thenApply(v -> v.updated()); |
406 | } | 406 | } |
407 | 407 | ||
408 | + /** | ||
409 | + * Pre-update hook for performing required checks/actions before going forward with an update operation. | ||
410 | + * @param key map key. | ||
411 | + */ | ||
412 | + protected void beforeUpdate(K key) { | ||
413 | + checkIfUnmodifiable(); | ||
414 | + } | ||
415 | + | ||
408 | private Map.Entry<K, Versioned<V>> mapRawEntry(Map.Entry<String, Versioned<byte[]>> e) { | 416 | private Map.Entry<K, Versioned<V>> mapRawEntry(Map.Entry<String, Versioned<byte[]>> e) { |
409 | return Maps.immutableEntry(dK(e.getKey()), e.getValue().<V>map(serializer::decode)); | 417 | return Maps.immutableEntry(dK(e.getKey()), e.getValue().<V>map(serializer::decode)); |
410 | } | 418 | } |
... | @@ -413,7 +421,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V | ... | @@ -413,7 +421,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V |
413 | Match<V> oldValueMatch, | 421 | Match<V> oldValueMatch, |
414 | Match<Long> oldVersionMatch, | 422 | Match<Long> oldVersionMatch, |
415 | V value) { | 423 | V value) { |
416 | - checkIfUnmodifiable(); | 424 | + beforeUpdate(key); |
417 | return database.mapUpdate(name, | 425 | return database.mapUpdate(name, |
418 | keyCache.getUnchecked(key), | 426 | keyCache.getUnchecked(key), |
419 | oldValueMatch.map(serializer::encode), | 427 | oldValueMatch.map(serializer::encode), | ... | ... |
-
Please register or login to post a comment