Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixes for Cassandra 0.7 client

  • Loading branch information...
commit 41491d3f5c36ee3bdc0d8aaf56b3e17cdb52f6e5 1 parent 8f9f463
Jake Luciani authored

Showing 1 changed file with 43 additions and 33 deletions. Show diff stats Hide diff stats

  1. +43 33 db/cassandra-0.7/src/com/yahoo/ycsb/db/CassandraClient7.java
76 db/cassandra-0.7/src/com/yahoo/ycsb/db/CassandraClient7.java
... ... @@ -1,18 +1,18 @@
1   -/**
2   - * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
3   - *
4   - * Licensed under the Apache License, Version 2.0 (the "License"); you
5   - * may not use this file except in compliance with the License. You
6   - * may obtain a copy of the License at
7   - *
8   - * http://www.apache.org/licenses/LICENSE-2.0
9   - *
10   - * Unless required by applicable law or agreed to in writing, software
11   - * distributed under the License is distributed on an "AS IS" BASIS,
12   - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13   - * implied. See the License for the specific language governing
14   - * permissions and limitations under the License. See accompanying
15   - * LICENSE file.
  1 +/**
  2 + * Copyright (c) 2010 Yahoo! Inc. All rights reserved.
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License"); you
  5 + * may not use this file except in compliance with the License. You
  6 + * may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  13 + * implied. See the License for the specific language governing
  14 + * permissions and limitations under the License. See accompanying
  15 + * LICENSE file.
16 16 */
17 17
18 18 package com.yahoo.ycsb.db;
@@ -28,6 +28,7 @@
28 28 import java.util.Vector;
29 29 import java.util.Random;
30 30 import java.util.Properties;
  31 +import java.nio.ByteBuffer;
31 32
32 33 import org.apache.thrift.transport.TTransport;
33 34 import org.apache.thrift.transport.TFramedTransport;
@@ -46,6 +47,7 @@
46 47 static Random random = new Random();
47 48 public static final int Ok = 0;
48 49 public static final int Error = -1;
  50 + public static final ByteBuffer emptyByteBuffer = ByteBuffer.wrap(new byte[0]);
49 51
50 52 public int ConnectionRetries;
51 53 public int OperationRetries;
@@ -191,18 +193,18 @@ public int read(String table, String key, Set<String> fields, HashMap<String, St
191 193 {
192 194
193 195 SliceRange sliceRange = new SliceRange();
194   - sliceRange.setStart(new byte[0]);
195   - sliceRange.setFinish(new byte[0]);
  196 + sliceRange.setStart(emptyByteBuffer);
  197 + sliceRange.setFinish(emptyByteBuffer);;
196 198 sliceRange.setCount(1000000);
197 199
198 200 predicate = new SlicePredicate();
199 201 predicate.setSlice_range(sliceRange);
200 202 } else
201 203 {
202   - ArrayList<byte[]> fieldlist = new ArrayList<byte[]>(fields.size());
  204 + ArrayList<ByteBuffer> fieldlist = new ArrayList<ByteBuffer>(fields.size());
203 205 for (String s : fields)
204 206 {
205   - fieldlist.add(s.getBytes("UTF-8"));
  207 + fieldlist.add(ByteBuffer.wrap(s.getBytes("UTF-8")));
206 208 }
207 209
208 210 predicate = new SlicePredicate();
@@ -210,7 +212,7 @@ public int read(String table, String key, Set<String> fields, HashMap<String, St
210 212 }
211 213
212 214 ColumnParent parent = new ColumnParent(column_family);
213   - List<ColumnOrSuperColumn> results = client.get_slice(key.getBytes("UTF-8"), parent, predicate,
  215 + List<ColumnOrSuperColumn> results = client.get_slice(ByteBuffer.wrap(key.getBytes("UTF-8")), parent, predicate,
214 216 ConsistencyLevel.ONE);
215 217
216 218 if (_debug)
@@ -220,12 +222,17 @@ public int read(String table, String key, Set<String> fields, HashMap<String, St
220 222
221 223 for (ColumnOrSuperColumn oneresult : results)
222 224 {
  225 +
223 226 Column column = oneresult.column;
224   - result.put(new String(column.name), new String(column.value));
  227 +
  228 + String name = new String(column.name.array(), column.name.position()+column.name.arrayOffset(), column.name.remaining());
  229 + String value = new String(column.value.array(), column.value.position()+column.value.arrayOffset(), column.value.remaining());
  230 +
  231 + result.put(name,value);
225 232
226 233 if (_debug)
227 234 {
228   - System.out.print("(" + new String(column.name) + "=" + new String(column.value) + ")");
  235 + System.out.print("(" + name + "=" + value + ")");
229 236 }
230 237 }
231 238
@@ -294,17 +301,17 @@ public int scan(String table, String startkey, int recordcount, Set<String> fiel
294 301 if (fields == null)
295 302 {
296 303 SliceRange sliceRange = new SliceRange();
297   - sliceRange.setStart(new byte[0]);
298   - sliceRange.setFinish(new byte[0]);
  304 + sliceRange.setStart(emptyByteBuffer);
  305 + sliceRange.setFinish(emptyByteBuffer);
299 306 sliceRange.setCount(1000000);
300 307 predicate = new SlicePredicate();
301 308 predicate.setSlice_range(sliceRange);
302 309 } else
303 310 {
304   - ArrayList<byte[]> fieldlist = new ArrayList<byte[]>(fields.size());
  311 + ArrayList<ByteBuffer> fieldlist = new ArrayList<ByteBuffer>(fields.size());
305 312 for (String s : fields)
306 313 {
307   - fieldlist.add(s.getBytes("UTF-8"));
  314 + fieldlist.add(ByteBuffer.wrap(s.getBytes("UTF-8")));
308 315 }
309 316 predicate = new SlicePredicate();
310 317 predicate.setColumn_names(fieldlist);
@@ -325,13 +332,16 @@ public int scan(String table, String startkey, int recordcount, Set<String> fiel
325 332
326 333 for (ColumnOrSuperColumn onecol : oneresult.columns)
327 334 {
328   - Column column = onecol.column;
329   - tuple.put(new String(column.name), new String(column.value));
  335 + Column column = onecol.column;
  336 + String name = new String(column.name.array(), column.name.position()+column.name.arrayOffset(), column.name.remaining());
  337 + String value = new String(column.value.array(), column.value.position()+column.value.arrayOffset(), column.value.remaining());
  338 +
  339 + tuple.put(name, value);
330 340
331 341 if (_debug)
332 342 {
333 343 System.out
334   - .print("(" + new String(column.name) + "=" + new String(column.value) + ")");
  344 + .print("(" + name + "=" + value + ")");
335 345 }
336 346 }
337 347
@@ -411,16 +421,16 @@ public int insert(String table, String key, HashMap<String, String> values)
411 421
412 422 try
413 423 {
414   - Map<byte[], Map<String, List<Mutation>>> batch_mutation = new HashMap<byte[], Map<String, List<Mutation>>>();
  424 + Map<ByteBuffer, Map<String, List<Mutation>>> batch_mutation = new HashMap<ByteBuffer, Map<String, List<Mutation>>>();
415 425 ArrayList<Mutation> v = new ArrayList<Mutation>(values.size());
416 426 Map<String, List<Mutation>> cfMutationMap = new HashMap<String, List<Mutation>>();
417 427 cfMutationMap.put(column_family, v);
418   - batch_mutation.put(key.getBytes("UTF-8"), cfMutationMap);
  428 + batch_mutation.put(ByteBuffer.wrap(key.getBytes("UTF-8")), cfMutationMap);
419 429
420 430 for (String field : values.keySet())
421 431 {
422 432 String val = values.get(field);
423   - Column col = new Column(field.getBytes("UTF-8"), val.getBytes("UTF-8"), timestamp);
  433 + Column col = new Column(ByteBuffer.wrap(field.getBytes("UTF-8")), ByteBuffer.wrap(val.getBytes("UTF-8")), timestamp);
424 434
425 435 ColumnOrSuperColumn c = new ColumnOrSuperColumn();
426 436 c.setColumn(col);
@@ -482,7 +492,7 @@ public int delete(String table, String key)
482 492 {
483 493 try
484 494 {
485   - client.remove(key.getBytes("UTF-8"), new ColumnPath(column_family), System.currentTimeMillis(),
  495 + client.remove(ByteBuffer.wrap(key.getBytes("UTF-8")), new ColumnPath(column_family), System.currentTimeMillis(),
486 496 ConsistencyLevel.ONE);
487 497
488 498 if (_debug)

0 comments on commit 41491d3

Please sign in to comment.
Something went wrong with that request. Please try again.