Skip to content

Commit

Permalink
Merge pull request #166 from naver/minkikim89/1.11.0_fix
Browse files Browse the repository at this point in the history
FIX: select separator depending on node version(v1.11.0)
  • Loading branch information
jhpark816 authored Jun 19, 2018
2 parents 5132d65 + 634acff commit 45fd0bf
Show file tree
Hide file tree
Showing 20 changed files with 168 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/spy/memcached/MemcachedConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -1153,9 +1153,9 @@ public CountDownLatch broadcastOperation(final BroadcastOpFactory of,
final CountDownLatch latch=new CountDownLatch(locator.getAll().size());
for(MemcachedNode node : nodes) {
Operation op = of.newOp(node, latch);
op.setHandlingNode(node);
op.initialize();
node.addOp(op);
op.setHandlingNode(node);
addedQueue.offer(node);
}
Selector s=selector.wakeup();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/spy/memcached/MemcachedNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ public interface MemcachedNode {
*/
boolean enabledMGetOp();

/**
* Check the enable SpaceSeparate operation.
*/
boolean enabledSpaceSeparate();

/**
* Get the number of bytes remaining to write.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/spy/memcached/MemcachedNodeROImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ public void setSk(SelectionKey to) {

public boolean enabledMGetOp() { throw new UnsupportedOperationException(); }

public boolean enabledSpaceSeparate() {
throw new UnsupportedOperationException();
}

public void setupResend(boolean cancelWrite, String cause) {
throw new UnsupportedOperationException();
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/spy/memcached/collection/BTreeGetBulk.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import java.util.List;

public interface BTreeGetBulk<T> {


public void setKeySeparator(String keySeparator);

public String getSpaceSeparatedKeys();

public String getRepresentKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public abstract class BTreeGetBulkImpl<T> implements BTreeGetBulk<T> {

private static final String command = "bop mget";

private String keySeparator;
private String spaceSeparatedKeys;

protected String str;
Expand Down Expand Up @@ -67,6 +68,10 @@ protected BTreeGetBulkImpl(List<String> keyList, long from, long to,
this.reverse = (from > to);
}

public void setKeySeparator(String keySeparator) {
this.keySeparator = keySeparator;
}

public String getSpaceSeparatedKeys() {
if (spaceSeparatedKeys != null) {
return spaceSeparatedKeys;
Expand All @@ -77,7 +82,7 @@ public String getSpaceSeparatedKeys() {
for (int i = 0; i < numkeys; i++) {
sb.append(keyList.get(i));
if ((i + 1) < numkeys) {
sb.append(" ");
sb.append(keySeparator);
}
}
spaceSeparatedKeys = sb.toString();
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/spy/memcached/collection/BTreeSMGet.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
public interface BTreeSMGet<T> {

public int headerCount = 4;


public void setKeySeparator(String keySeparator);

public String getSpaceSeparatedKeys();

public String getRepresentKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class BTreeSMGetWithByteTypeBkey<T> implements BTreeSMGet<T> {
protected String str;

protected List<String> keyList;
private String keySeparator;
private String spaceSeparatedKeys;

protected int lenKeys;
Expand Down Expand Up @@ -59,6 +60,10 @@ public BTreeSMGetWithByteTypeBkey(List<String> keyList, byte[] from,
this.smgetMode = smgetMode;
this.reverse = BTreeUtil.compareByteArraysInLexOrder(from, to) > 0;
}

public void setKeySeparator(String keySeparator) {
this.keySeparator = keySeparator;
}

public String getSpaceSeparatedKeys() {
if (spaceSeparatedKeys != null) {
Expand All @@ -70,7 +75,7 @@ public String getSpaceSeparatedKeys() {
for (int i = 0; i < numkeys; i++) {
sb.append(keyList.get(i));
if ((i + 1) < numkeys) {
sb.append(" ");
sb.append(keySeparator);
}
}
spaceSeparatedKeys = sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class BTreeSMGetWithByteTypeBkeyOld<T> implements BTreeSMGet<T> {
protected String str;

protected List<String> keyList;
private String keySeparator;
private String spaceSeparatedKeys;

protected int lenKeys;
Expand Down Expand Up @@ -57,6 +58,10 @@ public BTreeSMGetWithByteTypeBkeyOld(List<String> keyList, byte[] from,
this.count = count;
this.reverse = BTreeUtil.compareByteArraysInLexOrder(from, to) > 0;
}

public void setKeySeparator(String keySeparator) {
this.keySeparator = keySeparator;
}

public String getSpaceSeparatedKeys() {
if (spaceSeparatedKeys != null) {
Expand All @@ -68,7 +73,7 @@ public String getSpaceSeparatedKeys() {
for (int i = 0; i < numkeys; i++) {
sb.append(keyList.get(i));
if ((i + 1) < numkeys) {
sb.append(" ");
sb.append(keySeparator);
}
}
spaceSeparatedKeys = sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class BTreeSMGetWithLongTypeBkey<T> implements BTreeSMGet<T> {
protected String str;

protected List<String> keyList;
private String keySeparator;
private String spaceSeparatedKeys;

protected int lenKeys;
Expand Down Expand Up @@ -62,7 +63,11 @@ public BTreeSMGetWithLongTypeBkey(List<String> keyList, long from, long to,
this.smgetMode = smgetMode;
this.reverse = (from > to);
}


public void setKeySeparator(String keySeparator) {
this.keySeparator = keySeparator;
}

public String getSpaceSeparatedKeys() {
if (spaceSeparatedKeys != null) {
return spaceSeparatedKeys;
Expand All @@ -73,7 +78,7 @@ public String getSpaceSeparatedKeys() {
for (int i = 0; i < numkeys; i++) {
sb.append(keyList.get(i));
if ((i + 1) < numkeys) {
sb.append(" ");
sb.append(keySeparator);
}
}
spaceSeparatedKeys = sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class BTreeSMGetWithLongTypeBkeyOld<T> implements BTreeSMGet<T> {
protected String str;

protected List<String> keyList;
private String keySeparator;
private String spaceSeparatedKeys;

protected int lenKeys;
Expand Down Expand Up @@ -60,7 +61,11 @@ public BTreeSMGetWithLongTypeBkeyOld(List<String> keyList, long from, long to,
this.count = count;
this.reverse = (from > to);
}


public void setKeySeparator(String keySeparator) {
this.keySeparator = keySeparator;
}

public String getSpaceSeparatedKeys() {
if (spaceSeparatedKeys != null) {
return spaceSeparatedKeys;
Expand All @@ -71,7 +76,7 @@ public String getSpaceSeparatedKeys() {
for (int i = 0; i < numkeys; i++) {
sb.append(keyList.get(i));
if ((i + 1) < numkeys) {
sb.append(" ");
sb.append(keySeparator);
}
}
spaceSeparatedKeys = sb.toString();
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/net/spy/memcached/collection/MapDelete.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ public class MapDelete extends CollectionDelete {
private static final String command = "mop delete";

protected List<String> mkeyList;
private String keySeparator;
private String spaceSeparatedKeys;
protected byte[] additionalArgs;

public MapDelete(List<String> mkeyList, boolean noreply) {
this.mkeyList = mkeyList;
this.noreply = noreply;
if (mkeyList.size() == 0) {
this.additionalArgs = null;
} else {
this.additionalArgs = getSpaceSeparatedMkeys().getBytes();
}
}

public MapDelete(List<String> mkeyList, boolean noreply, boolean dropIfEmpty) {
this(mkeyList, noreply);
this.dropIfEmpty = dropIfEmpty;
}

public void setKeySeparator(String keySeparator) {
this.keySeparator = keySeparator;
}

public String getSpaceSeparatedMkeys() {
if (spaceSeparatedKeys != null) {
return spaceSeparatedKeys;
Expand All @@ -50,7 +50,7 @@ public String getSpaceSeparatedMkeys() {
for (int i = 0; i < numkeys; i++) {
sb.append(mkeyList.get(i));
if ((i + 1) < numkeys) {
sb.append(" ");
sb.append(keySeparator);
}
}
spaceSeparatedKeys = sb.toString();
Expand All @@ -64,6 +64,12 @@ public byte[] getAdditionalArgs() {
public String stringify() {
if (str != null) return str;

if (mkeyList.size() == 0) {
additionalArgs = null;
} else {
additionalArgs = getSpaceSeparatedMkeys().getBytes();
}

StringBuilder b = new StringBuilder();
if (additionalArgs == null) {
b.append("0");
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/net/spy/memcached/collection/MapGet.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ public class MapGet extends CollectionGet {

protected List<String> mkeyList;
protected byte[] data;
private String keySeparator;
private String spaceSeparatedKeys;
protected byte[] additionalArgs;

public MapGet(List<String> mkeyList, boolean delete) {
this.headerCount = 2;
this.mkeyList = mkeyList;
this.delete = delete;
if (mkeyList.size() == 0) {
this.additionalArgs = null;
} else {
this.additionalArgs = getSpaceSeparatedMkeys().getBytes();
}
}

public MapGet(List<String> mkeyList, boolean delete, boolean dropIfEmpty) {
this(mkeyList, delete);
this.dropIfEmpty = dropIfEmpty;
}

public void setKeySeparator(String keySeparator) {
this.keySeparator = keySeparator;
}

public String getSpaceSeparatedMkeys() {
if (spaceSeparatedKeys != null) {
return spaceSeparatedKeys;
Expand All @@ -53,7 +53,7 @@ public String getSpaceSeparatedMkeys() {
for (int i = 0; i < numkeys; i++) {
sb.append(mkeyList.get(i));
if ((i + 1) < numkeys) {
sb.append(" ");
sb.append(keySeparator);
}
}
spaceSeparatedKeys = sb.toString();
Expand All @@ -68,6 +68,12 @@ public byte[] getAddtionalArgs() {
public String stringify() {
if (str != null) return str;

if (mkeyList.size() == 0) {
additionalArgs = null;
} else {
additionalArgs = getSpaceSeparatedMkeys().getBytes();
}

StringBuilder b = new StringBuilder();
if (additionalArgs == null) {
b.append("0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public abstract class TCPMemcachedNodeImpl extends SpyObject
private String version=null;
private boolean isAsciiProtocol=true;
private boolean enabledMGetOp=false;
private boolean enabledSpaceSeparate = false;

// operation Future.get timeout counter
private final AtomicInteger continuousTimeout = new AtomicInteger(0);
Expand Down Expand Up @@ -555,6 +556,7 @@ public final SelectionKey getSk() {
public final void setVersion(String vr) {
version = vr;
setEnableMGetOp();
setEnableSpaceSeparate();
}

/* (non-javadoc)
Expand All @@ -578,11 +580,34 @@ private final void setEnableMGetOp() {
}
}


/* (non-javadoc)
* @see net.spy.memcached.MemcachedNode#setEnableSpaceSeparate(java.lang.Boolean)
*/
private final void setEnableSpaceSeparate() {
if (isAsciiProtocol) {
StringTokenizer tokens = new StringTokenizer(version, ".");
int majorVersion = Integer.parseInt(tokens.nextToken());
int minorVersion = Integer.parseInt(tokens.nextToken());
if (version.contains("E")) {
enabledSpaceSeparate = (majorVersion > 0 || (majorVersion == 0 && minorVersion > 6));
} else {
enabledSpaceSeparate = (majorVersion > 1 || (majorVersion == 1 && minorVersion > 10));
}
}
}

/* (non-javadoc)
* @see net.spy.memcached.MemcachedNode#enabledMGetOp()
*/
public final boolean enabledMGetOp() { return enabledMGetOp; }


/* (non-javadoc)
* @see net.spy.memcached.MemcachedNode#enabledSpaceSeparate()
*/
public final boolean enabledSpaceSeparate() { return enabledSpaceSeparate; }

/* (non-Javadoc)
* @see net.spy.memcached.MemcachedNode#getBytesRemainingInBuffer()
*/
Expand Down Expand Up @@ -757,13 +782,13 @@ private BlockingQueue<Operation> getAllOperations() {

public void addAllOpToInputQ(BlockingQueue<Operation> allOp) {
for (Operation op : allOp) {
op.setHandlingNode(this);
if (op.getState() == OperationState.WRITING && op.getBuffer() != null) {
op.getBuffer().reset(); // buffer offset reset
} else {
op.initialize(); // write completed or not yet initialized
op.resetState(); // reset operation state
}
op.setHandlingNode(this);
op.setMoved(true);
}
addOpCount += allOp.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ private final void readValue(ByteBuffer bb) {

public void initialize() {
String cmd = getBulk.getCommand();
if (getHandlingNode() == null || getHandlingNode().enabledSpaceSeparate()) {
getBulk.setKeySeparator(" ");
} else {
getBulk.setKeySeparator(",");
}
String args = getBulk.stringify();

ByteBuffer bb = ByteBuffer.allocate(cmd.length() + args.length()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,11 @@ else if (smGet instanceof BTreeSMGetWithByteTypeBkey)

public void initialize() {
String cmd = smGet.getCommand();
if (getHandlingNode() == null || getHandlingNode().enabledSpaceSeparate()) {
smGet.setKeySeparator(" ");
} else {
smGet.setKeySeparator(",");
}
String args = smGet.stringify();

ByteBuffer bb = ByteBuffer.allocate(cmd.length() + args.length()
Expand Down
Loading

0 comments on commit 45fd0bf

Please sign in to comment.