Return-Path: X-Original-To: apmail-cassandra-commits-archive@www.apache.org Delivered-To: apmail-cassandra-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D09D611CC0 for ; Fri, 1 Aug 2014 20:40:18 +0000 (UTC) Received: (qmail 11547 invoked by uid 500); 1 Aug 2014 20:40:18 -0000 Delivered-To: apmail-cassandra-commits-archive@cassandra.apache.org Received: (qmail 11462 invoked by uid 500); 1 Aug 2014 20:40:18 -0000 Mailing-List: contact commits-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cassandra.apache.org Delivered-To: mailing list commits@cassandra.apache.org Received: (qmail 11349 invoked by uid 99); 1 Aug 2014 20:40:18 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Aug 2014 20:40:18 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 141839BE712; Fri, 1 Aug 2014 20:40:17 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: benedict@apache.org To: commits@cassandra.apache.org Date: Fri, 01 Aug 2014 20:40:18 -0000 Message-Id: <57ba2a434cff4a98961972e68f956abf@git.apache.org> In-Reply-To: <1bf6a001a61c4ed7b7e1a567760b1bba@git.apache.org> References: <1bf6a001a61c4ed7b7e1a567760b1bba@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [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 Authored: Fri Aug 1 21:37:55 2014 +0100 Committer: Benedict Elliott Smith 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 names; + public transient List names; public final List 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 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 namesBuffer = new ArrayList<>(); + List namesBytes = (List) ois.readObject(); + for (byte[] bytes : namesBytes) + namesBuffer.add(ByteBuffer.wrap(bytes)); + this.names = new ArrayList<>(namesBuffer); + } + }