mikewalch commented on a change in pull request #48: Added conditional writer
to tour
URL: https://github.com/apache/accumulo-website/pull/48#discussion_r155815228
##########
File path: tour/conditional-writer.md
##########
@@ -1,3 +1,119 @@
---
title: Conditional Writer
---
+
+When read-modify-write operations run concurrently, its possible changes made
+by some operations will be overwritten by others. The following sequence of
+events shows an example of this.
+
+ 1. Thread 0 sets the key `id0001:location:home` to `1007 Mountain Dr, Gotham,
New York`
+ 2. Thread 1 reads `id0001:location:home`
+ 3. Thread 2 reads `id0001:location:home`
+ 4. Thread 1 replaces `Dr` with `Drive`
+ 5. Thread 2 replaces `New York` with `NY`
+ 6. Thread 1 sets key `id0001:location:home` to `1007 Mountain Drive, Gotham,
New York`
+ 7. Thread 2 sets key `id0001:location:home` to `1007 Mountain Dr, Gotham, NY`
+
+In this situation the changes made by Thread 1 are lost, ending up with `1007
+Mountain Dr, Gotham, NY` instead of `1007 Mountain Drive, Gotham, NY`. To
+correctly handle this, Accumulo offers the [ConditionalWriter]. The
+ConditionalWriter atomically checks conditions on a row and only applies a
+mutation when all are satisfied.
+
+## Exercise
+
+The following code simulates the concurrency situation above. Because it uses
+a BatchWriter it will lose modifications.
+
+```java
+ static String getAddress(Connector conn, String id) {
Review comment:
More imports are needed at top of file. We could move to wild card imports.
Below worked for me. However, this should be tested with other exercises.
```java
// Classes you will use along the tour
import java.util.*;
import java.nio.file.*;
import java.util.concurrent.*;
import java.util.function.*;
import org.apache.accumulo.core.client.*;
import org.apache.accumulo.core.client.Scanner;
import org.apache.accumulo.core.data.*;
import org.apache.accumulo.core.security.*;
import org.apache.accumulo.minicluster.MiniAccumuloCluster;
import org.apache.hadoop.io.Text;
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services