From b0ff7270fc29418cb8d47760466fb03ea28d3db1 Mon Sep 17 00:00:00 2001
From: sashas83 <solganik@gmail.com>
Date: Fri, 12 May 2017 17:06:44 +0300
Subject: [PATCH] [memcached] support binary protocol (#965)

Adding support for memcached binary protocol as described in
https://github.com/memcached/memcached/blob/master/doc/protocol.txt.

Protocol can be set via memcached.protocol property of YCSB memcached workload. if specified
protocol must be "binary" or "text". If unspecified text version is used.
---
 memcached/README.md                                      | 4 ++++
 .../src/main/java/com/yahoo/ycsb/db/MemcachedClient.java | 9 +++++++++
 2 files changed, 13 insertions(+)

diff --git a/memcached/README.md b/memcached/README.md
index 2126b2da..c46a24fd 100644
--- a/memcached/README.md
+++ b/memcached/README.md
@@ -91,6 +91,10 @@ A sample configuration is provided in
   What to do with failures; this is one of `net.spy.memcached.FailureMode` enum
   values, which are currently: `Redistribute`, `Retry`, or `Cancel`.
 
+- `memcached.protocol`
+  Set to 'binary' to use memcached binary protocol. Set to 'text' or omit this field
+  to use memcached text protocol
+
 You can set properties on the command line via `-p`, e.g.:
 
     ./bin/ycsb load memcached -s -P workloads/workloada \
diff --git a/memcached/src/main/java/com/yahoo/ycsb/db/MemcachedClient.java b/memcached/src/main/java/com/yahoo/ycsb/db/MemcachedClient.java
index 9ce0b93c..85f1f5dc 100644
--- a/memcached/src/main/java/com/yahoo/ycsb/db/MemcachedClient.java
+++ b/memcached/src/main/java/com/yahoo/ycsb/db/MemcachedClient.java
@@ -98,6 +98,10 @@ public class MemcachedClient extends DB {
   public static final FailureMode FAILURE_MODE_PROPERTY_DEFAULT =
       FailureMode.Redistribute;
 
+  public static final String PROTOCOL_PROPERTY = "memcached.protocol";
+  public static final ConnectionFactoryBuilder.Protocol DEFAULT_PROTOCOL =
+      ConnectionFactoryBuilder.Protocol.TEXT;
+
   /**
    * The MemcachedClient implementation that will be used to communicate
    * with the memcached server.
@@ -142,6 +146,11 @@ public class MemcachedClient extends DB {
     connectionFactoryBuilder.setOpTimeout(Integer.parseInt(
         getProperties().getProperty(OP_TIMEOUT_PROPERTY, DEFAULT_OP_TIMEOUT)));
 
+    String protocolString = getProperties().getProperty(PROTOCOL_PROPERTY);
+    connectionFactoryBuilder.setProtocol(
+        protocolString == null ? DEFAULT_PROTOCOL
+                         : ConnectionFactoryBuilder.Protocol.valueOf(protocolString.toUpperCase()));
+
     String failureString = getProperties().getProperty(FAILURE_MODE_PROPERTY);
     connectionFactoryBuilder.setFailureMode(
         failureString == null ? FAILURE_MODE_PROPERTY_DEFAULT
-- 
GitLab