You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by be...@apache.org on 2014/08/01 22:40:18 UTC

[2/3] git commit: Fix column name serialization for cassandra-stress/stressd

Fix column name serialization for cassandra-stress/stressd

patch by rspitzer; reviewed by benedict for CASSANDRA-7608


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/a182ea00
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/a182ea00
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/a182ea00

Branch: refs/heads/trunk
Commit: a182ea00ba8650c5c94ff6d0b74cb864e434504d
Parents: 54c424d
Author: Benedict Elliott Smith <be...@apache.org>
Authored: Fri Aug 1 21:37:55 2014 +0100
Committer: Benedict Elliott Smith <be...@apache.org>
Committed: Fri Aug 1 21:37:55 2014 +0100

----------------------------------------------------------------------
 .../stress/settings/SettingsColumn.java         | 31 ++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/a182ea00/tools/stress/src/org/apache/cassandra/stress/settings/SettingsColumn.java
----------------------------------------------------------------------
diff --git a/tools/stress/src/org/apache/cassandra/stress/settings/SettingsColumn.java b/tools/stress/src/org/apache/cassandra/stress/settings/SettingsColumn.java
index 04c2a47..4b4e0b0 100644
--- a/tools/stress/src/org/apache/cassandra/stress/settings/SettingsColumn.java
+++ b/tools/stress/src/org/apache/cassandra/stress/settings/SettingsColumn.java
@@ -21,7 +21,10 @@ package org.apache.cassandra.stress.settings;
  */
 
 
+import java.io.IOException;
 import java.io.Serializable;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.nio.ByteBuffer;
 import java.nio.charset.CharacterCodingException;
 import java.util.ArrayList;
@@ -41,7 +44,7 @@ public class SettingsColumn implements Serializable
 {
 
     public final int maxColumnsPerKey;
-    public transient final List<ByteBuffer> names;
+    public transient List<ByteBuffer> names;
     public final List<String> namestrs;
     public final String comparator;
     public final boolean variableColumnCount;
@@ -130,7 +133,6 @@ public class SettingsColumn implements Serializable
             {
                 throw new RuntimeException(e);
             }
-
             this.names = Arrays.asList(names);
             this.namestrs = Arrays.asList(namestrs);
         }
@@ -205,4 +207,29 @@ public class SettingsColumn implements Serializable
             }
         };
     }
+
+    /* Custom serializaiton invoked here to make legacy thrift based table creation work with StressD. This code requires
+     * the names attribute to be populated. Since the names attribute is set as a List[ByteBuffer] we switch it
+     * to an array on the way out and back to a buffer when it's being read in.
+     */
+
+    private void writeObject(ObjectOutputStream oos) throws IOException
+    {
+        oos.defaultWriteObject();
+        ArrayList<byte[]> namesBytes = new ArrayList<>();
+        for (ByteBuffer buffer : this.names)
+            namesBytes.add(ByteBufferUtil.getArray(buffer));
+        oos.writeObject(namesBytes);
+    }
+
+    private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException
+    {
+        ois.defaultReadObject();
+        List<ByteBuffer> namesBuffer = new ArrayList<>();
+        List<byte[]> namesBytes = (List<byte[]>) ois.readObject();
+        for (byte[] bytes : namesBytes)
+            namesBuffer.add(ByteBuffer.wrap(bytes));
+        this.names = new ArrayList<>(namesBuffer);
+    }
+
 }