Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add support for TAP request/response with checkpoint info

Change-Id: If646c70aaa345f3dd1191257dfcedc1aaacdc7b1
Reviewed-on: http://review.couchbase.org/13571
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
Tested-by: Matt Ingenthron <matt@couchbase.com>
  • Loading branch information...
commit 8fa20606020d440d755f2aed473011db17d7c3bf 1 parent b9cf1f4
@mschoch mschoch authored ingenthr committed
View
28 src/main/java/net/spy/memcached/tapmessage/RequestMessage.java
@@ -23,8 +23,10 @@
package net.spy.memcached.tapmessage;
import java.nio.ByteBuffer;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.UUID;
/**
@@ -34,11 +36,13 @@
public class RequestMessage extends BaseMessage{
private boolean hasBackfill;
private boolean hasVBucketList;
+ private boolean hasVBucketCheckpoints;
private boolean hasFlags;
private List<TapRequestFlag> flagList;
private short[] vblist;
private String name;
private long backfilldate;
+ private Map<Short, Long> vBucketCheckpoints;
/**
* Create a tap request message. These messages are used to start tap streams.
@@ -46,6 +50,7 @@
public RequestMessage() {
flagList = new LinkedList<TapRequestFlag>();
vblist = new short[0];
+ vBucketCheckpoints = new HashMap<Short, Long>();
name = UUID.randomUUID().toString();
backfilldate = -1;
totalbody += name.length();
@@ -74,6 +79,10 @@ public void setFlags(TapRequestFlag f) {
hasVBucketList = true;
totalbody += 2;
}
+ if (f.equals(TapRequestFlag.CHECKPOINT)) {
+ hasVBucketCheckpoints = true;
+ totalbody += 2;
+ }
flagList.add(f);
}
}
@@ -109,6 +118,18 @@ public void setVbucketlist(short[] vbs) {
}
/**
+ * Sets a map of vbucket checkpoints.
+ *
+ * @param vbchkpnts - A map of vbucket checkpoint identifiers
+ */
+ public void setvBucketCheckpoints(Map<Short, Long> vbchkpnts) {
+ int oldSize = (vBucketCheckpoints.size()) * 10;
+ int newSize = (vbchkpnts.size()) * 10;
+ totalbody += newSize - oldSize;
+ vBucketCheckpoints = vbchkpnts;
+ }
+
+ /**
* Sets a name for this tap stream. If the tap stream fails this name can be
* used to try to restart the tap stream from where it last left off.
*
@@ -156,6 +177,13 @@ public ByteBuffer getBytes() {
bb.putShort(vblist[i]);
}
}
+ if (hasVBucketCheckpoints) {
+ bb.putShort((short)vBucketCheckpoints.size());
+ for (Short vBucket : vBucketCheckpoints.keySet()) {
+ bb.putShort(vBucket);
+ bb.putLong(vBucketCheckpoints.get(vBucket));
+ }
+ }
return (ByteBuffer) bb.flip();
}
View
32 src/main/java/net/spy/memcached/tapmessage/ResponseMessage.java
@@ -52,6 +52,7 @@
private final int itemflags;
private int itemexpiry;
private final int vbucketstate;
+ private final long checkpoint;
private final byte[] key;
private final byte[] value;
private final byte[] revid;
@@ -90,6 +91,7 @@ public ResponseMessage(byte[] b) {
}
itemexpiry = decodeInt(b, ITEM_EXPIRY_OFFSET);
vbucketstate = 0;
+ checkpoint = 0;
revid = new byte[engineprivate];
System.arraycopy(b, KEY_OFFSET, revid, 0, engineprivate);
key = new byte[keylength];
@@ -102,6 +104,7 @@ public ResponseMessage(byte[] b) {
vbucketstate = 0;
revid = new byte[engineprivate];
System.arraycopy(b, 32, revid, 0, engineprivate);
+ checkpoint = 0;
key = new byte[keylength];
System.arraycopy(b, 32 + engineprivate, key, 0, keylength);
value = new byte[0];
@@ -109,6 +112,24 @@ public ResponseMessage(byte[] b) {
itemflags = 0;
itemexpiry = 0;
vbucketstate = decodeInt(b, ITEM_FLAGS_OFFSET);
+ checkpoint = 0;
+ key = new byte[0];
+ value = new byte[0];
+ revid = new byte[0];
+ } else if (opcode.equals(TapOpcode.START_CHECKPOINT)
+ || opcode.equals(TapOpcode.END_CHECKPOINT)) {
+ itemflags = 0;
+ itemexpiry = 0;
+ vbucketstate = 0;
+ checkpoint = decodeLong(b, KEY_OFFSET);
+ key = new byte[0];
+ value = new byte[0];
+ revid = new byte[0];
+ } else if (opcode.equals(TapOpcode.OPAQUE)) {
+ itemflags = 0;
+ itemexpiry = 0;
+ vbucketstate = decodeInt(b, ITEM_FLAGS_OFFSET);
+ checkpoint = 0;
key = new byte[0];
value = new byte[0];
revid = new byte[0];
@@ -116,6 +137,7 @@ public ResponseMessage(byte[] b) {
itemflags = 0;
itemexpiry = 0;
vbucketstate = 0;
+ checkpoint = 0;
key = new byte[0];
value = new byte[0];
revid = new byte[0];
@@ -188,6 +210,16 @@ public int getVBucketState() {
}
/**
+ * Gets the checkpoint of the vbucket. Only returned with a start/end
+ * checkpoint message.
+ *
+ * @return the checkpoint
+ */
+ public long getCheckpoint() {
+ return checkpoint;
+ }
+
+ /**
* Gets the value of the items flag field. Only returned with a tap mutation
* message.
*
Please sign in to comment.
Something went wrong with that request. Please try again.