Skip to content

Commit

Permalink
Add support for a synchronous delete, via observe operation.
Browse files Browse the repository at this point in the history
This change adds support for a synchronous delete, including
detection of full delete versus logical delete.

The main use case behind this feature is that if using
Couchbase Server 2.0, and wanting to query views, one may
wish to ensure a delete has been persisted to know that
a subsequent query with .setStale(false) will take the
deletion into account when generating the index.

Change-Id: I99ad5b5089992a7df2c2ab12e487d043265df21f
Reviewed-on: http://review.couchbase.org/19778
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
Tested-by: Matt Ingenthron <matt@couchbase.com>
  • Loading branch information
ragsns authored and ingenthr committed Aug 19, 2012
1 parent 4460d26 commit 47bc98a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
45 changes: 44 additions & 1 deletion src/main/java/com/couchbase/client/CouchbaseClient.java
Expand Up @@ -59,6 +59,7 @@
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -805,6 +806,47 @@ public Boolean unlock(final String key,
return unlock(key, casId, transcoder);
}

/**
* Delete a value and Observe.
*
* @param key the key to set
* @param req the Persistence to Master value
* @param rep the Persistence to Replicas
* @return whether or not the operation was performed
*
*/
public Future<Boolean> delete(String key,
PersistTo req, ReplicateTo rep) {
OperationFuture<Boolean> deleteOp = delete(key);
try {
if (deleteOp.get()) {
observePoll(key, 0L, req, rep);
}
} catch (InterruptedException e) {
deleteOp.set(false, deleteOp.getStatus());
} catch (ExecutionException e) {
deleteOp.set(false, deleteOp.getStatus());
} catch (TimeoutException e) {
deleteOp.set(false, deleteOp.getStatus());
} catch (IllegalArgumentException e) {
deleteOp.set(false, deleteOp.getStatus());
} catch (RuntimeException e) {
deleteOp.set(false, deleteOp.getStatus());
}
return (deleteOp);
}
/**
* Delete a value with Observe.
*
* @param key the key to set
* @param req the Persistence to Master value
* @return whether or not the operation was performed
*
*/
public Future<Boolean> delete(String key, PersistTo req) {
return delete(key, req, ReplicateTo.ZERO);
}

/**
* Set a value and Observe.
*
Expand Down Expand Up @@ -1028,6 +1070,7 @@ private void observePoll(String key, long cas,
// Other than Master
switch (persist) {
case MASTER:
case ONE:
persists=0;
break;
case TWO:
Expand Down Expand Up @@ -1096,7 +1139,7 @@ private void observePoll(String key, long cas,
try {
Thread.sleep(400);
} catch (InterruptedException e) {
getLogger().error("Interrupted while in observe loop.", e);
getLogger().error("Interrupted while in observe loop.", e);
}
} while (loop++ < 10);

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/couchbase/client/CouchbaseClientIF.java
Expand Up @@ -67,5 +67,9 @@ OperationFuture<Boolean> set(String key, int exp,
String value, PersistTo persist);
OperationFuture<Boolean> set(String key, int exp,
String value, PersistTo persist, ReplicateTo replicate);
Future<Boolean> delete(String key, PersistTo persist);
Future<Boolean> delete(String key, PersistTo persist,
ReplicateTo replicate);

int getNumVBuckets();
}

0 comments on commit 47bc98a

Please sign in to comment.