cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdusba...@apache.org
Subject svn commit: r934150 - in /cassandra/trunk/src/java/org/apache/cassandra: db/ dht/ service/ tools/ utils/
Date Wed, 14 Apr 2010 19:52:05 GMT
Author: gdusbabek
Date: Wed Apr 14 19:52:05 2010
New Revision: 934150

URL: http://svn.apache.org/viewvc?rev=934150&view=rev
Log:
store bytes in DecoratedKey. Patch by Stu Hood, reviewed by Gary Dusbabek. CASSANDRA-767

Modified:
    cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
    cassandra/trunk/src/java/org/apache/cassandra/db/DecoratedKey.java
    cassandra/trunk/src/java/org/apache/cassandra/db/RowIteratorFactory.java
    cassandra/trunk/src/java/org/apache/cassandra/dht/CollatingOrderPreservingPartitioner.java
    cassandra/trunk/src/java/org/apache/cassandra/dht/OrderPreservingPartitioner.java
    cassandra/trunk/src/java/org/apache/cassandra/dht/RandomPartitioner.java
    cassandra/trunk/src/java/org/apache/cassandra/service/AntiEntropyService.java
    cassandra/trunk/src/java/org/apache/cassandra/tools/SSTableExport.java
    cassandra/trunk/src/java/org/apache/cassandra/tools/SSTableImport.java
    cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java?rev=934150&r1=934149&r2=934150&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java Wed Apr 14 19:52:05
2010
@@ -839,8 +839,8 @@ public class ColumnFamilyStore implement
     private boolean getRangeRows(List<Row> rows, byte[] superColumn, final AbstractBounds
range, int maxResults, SliceRange sliceRange, List<byte[]> columnNames)
     throws ExecutionException, InterruptedException
     {
-        final DecoratedKey startWith = new DecoratedKey(range.left, null);
-        final DecoratedKey stopAt = new DecoratedKey(range.right, null);
+        final DecoratedKey startWith = new DecoratedKey(range.left, (byte[])null);
+        final DecoratedKey stopAt = new DecoratedKey(range.right, (byte[])null);
         
         final int gcBefore = CompactionManager.getDefaultGCBefore();
 

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/DecoratedKey.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/DecoratedKey.java?rev=934150&r1=934149&r2=934150&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/DecoratedKey.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/DecoratedKey.java Wed Apr 14 19:52:05
2010
@@ -41,14 +41,8 @@ import org.apache.cassandra.utils.FBUtil
  */
 public class DecoratedKey<T extends Token> implements Comparable<DecoratedKey>
 {
-    private static DecoratedKeySerializer serializer = new DecoratedKeySerializer();
     private static IPartitioner partitioner = StorageService.getPartitioner();
 
-    public static DecoratedKeySerializer serializer()
-    {
-        return serializer;
-    }
-
     public static final Comparator<DecoratedKey> comparator = new Comparator<DecoratedKey>()
     {
         public int compare(DecoratedKey o1, DecoratedKey o2)
@@ -58,13 +52,22 @@ public class DecoratedKey<T extends Toke
     };
 
     public final T token;
-    public final String key;
+    public final byte[] key;
 
+    @Deprecated
     public DecoratedKey(T token, String key)
     {
         super();
         assert token != null;
         this.token = token;
+        this.key = key == null ? null : key.getBytes(FBUtilities.UTF8);
+    }
+
+    public DecoratedKey(T token, byte[] key)
+    {
+        super();
+        assert token != null;
+        this.token = token;
         this.key = key;
     }
 
@@ -101,20 +104,7 @@ public class DecoratedKey<T extends Toke
     @Override
     public String toString()
     {
-        return "DecoratedKey(" + token + ", " + key + ")";
+        String keystring = key == null ? "null" : FBUtilities.bytesToHex(key);
+        return "DecoratedKey(" + token + ", " + keystring + ")";
     }
 }
-
-class DecoratedKeySerializer implements ICompactSerializer2<DecoratedKey>
-{
-    public void serialize(DecoratedKey dk, DataOutput dos) throws IOException
-    {
-        Token.serializer().serialize(dk.token, dos);
-        FBUtilities.writeNullableString(dk.key, dos);
-    }
-
-    public DecoratedKey deserialize(DataInput dis) throws IOException
-    {
-        return new DecoratedKey(Token.serializer().deserialize(dis), FBUtilities.readNullableString(dis));
-    }
-}
\ No newline at end of file

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/RowIteratorFactory.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/RowIteratorFactory.java?rev=934150&r1=934149&r2=934150&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/RowIteratorFactory.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/RowIteratorFactory.java Wed Apr 14 19:52:05
2010
@@ -133,7 +133,8 @@ public class RowIteratorFactory
                 Comparator<IColumn> colComparator = QueryFilter.getColumnComparator(comparator);
                 Iterator<IColumn> colCollated = IteratorUtils.collatedIterator(colComparator,
colIters);
 
-                ColumnFamily returnCF = current.getColumnFamily(key.key);
+                // FIXME: string keys
+                ColumnFamily returnCF = current.getColumnFamily(new String(key.key));
                 // TODO this is a little subtle: the Memtable ColumnIterator has to be a
shallow clone of the source CF,
                 // with deletion times set correctly, so we can use it as the "base" CF to
add query results to.
                 // (for sstable ColumnIterators we do not care if it is a shallow clone or
not.)
@@ -149,7 +150,8 @@ public class RowIteratorFactory
                     returnCF = null;
                 }
 
-                Row rv = new Row(key.key, returnCF);
+                // FIXME: string keys
+                Row rv = new Row(new String(key.key), returnCF);
                 colIters.clear();
                 key = null;
                 return rv;

Modified: cassandra/trunk/src/java/org/apache/cassandra/dht/CollatingOrderPreservingPartitioner.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/dht/CollatingOrderPreservingPartitioner.java?rev=934150&r1=934149&r2=934150&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/dht/CollatingOrderPreservingPartitioner.java
(original)
+++ cassandra/trunk/src/java/org/apache/cassandra/dht/CollatingOrderPreservingPartitioner.java
Wed Apr 14 19:52:05 2010
@@ -51,7 +51,8 @@ public class CollatingOrderPreservingPar
 
     public String convertToDiskFormat(DecoratedKey<BytesToken> key)
     {
-        return key.key;
+        // FIXME
+        return new String(key.key, FBUtilities.UTF8);
     }
 
     public BytesToken midpoint(BytesToken ltoken, BytesToken rtoken)

Modified: cassandra/trunk/src/java/org/apache/cassandra/dht/OrderPreservingPartitioner.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/dht/OrderPreservingPartitioner.java?rev=934150&r1=934149&r2=934150&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/dht/OrderPreservingPartitioner.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/dht/OrderPreservingPartitioner.java Wed
Apr 14 19:52:05 2010
@@ -47,7 +47,8 @@ public class OrderPreservingPartitioner 
 
     public String convertToDiskFormat(DecoratedKey<StringToken> key)
     {
-        return key.key;
+        // FIXME
+        return new String(key.key, FBUtilities.UTF8);
     }
 
     public StringToken midpoint(StringToken ltoken, StringToken rtoken)

Modified: cassandra/trunk/src/java/org/apache/cassandra/dht/RandomPartitioner.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/dht/RandomPartitioner.java?rev=934150&r1=934149&r2=934150&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/dht/RandomPartitioner.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/dht/RandomPartitioner.java Wed Apr 14 19:52:05
2010
@@ -55,7 +55,8 @@ public class RandomPartitioner implement
 
     public String convertToDiskFormat(DecoratedKey<BigIntegerToken> key)
     {
-        return key.token + DELIMITER + key.key;
+        // FIXME
+        return key.token + DELIMITER + new String(key.key, FBUtilities.UTF8);
     }
 
     public BigIntegerToken midpoint(BigIntegerToken ltoken, BigIntegerToken rtoken)

Modified: cassandra/trunk/src/java/org/apache/cassandra/service/AntiEntropyService.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/service/AntiEntropyService.java?rev=934150&r1=934149&r2=934150&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/service/AntiEntropyService.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/service/AntiEntropyService.java Wed Apr
14 19:52:05 2010
@@ -443,7 +443,7 @@ public class AntiEntropyService
         {
             validated++;
             // MerkleTree uses XOR internally, so we want lots of output bits here
-            byte[] rowhash = FBUtilities.hash("SHA-256", row.key.key.getBytes(), row.buffer.getData());
+            byte[] rowhash = FBUtilities.hash("SHA-256", row.key.key, row.buffer.getData());
             return new MerkleTree.RowHash(row.key.token, rowhash);
         }
 

Modified: cassandra/trunk/src/java/org/apache/cassandra/tools/SSTableExport.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/tools/SSTableExport.java?rev=934150&r1=934149&r2=934150&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/tools/SSTableExport.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/tools/SSTableExport.java Wed Apr 14 19:52:05
2010
@@ -35,6 +35,7 @@ import org.apache.cassandra.io.sstable.S
 import org.apache.cassandra.io.sstable.SSTableScanner;
 import org.apache.cassandra.io.util.BufferedRandomAccessFile;
 import org.apache.cassandra.service.StorageService;
+import org.apache.cassandra.utils.FBUtilities;
 
 import static org.apache.cassandra.utils.FBUtilities.bytesToHex;
 import org.apache.commons.cli.*;
@@ -80,6 +81,13 @@ public class SSTableExport
         return String.format("%s: ", quote(val));
     }
     
+    @Deprecated
+    private static String asStr(byte[] val)
+    {
+        // FIXME: should not interpret as a string
+        return new String(val, FBUtilities.UTF8);
+    }
+    
     private static String serializeColumns(Collection<IColumn> cols, AbstractType comp)
     {
         StringBuilder json = new StringBuilder("[");
@@ -110,7 +118,7 @@ public class SSTableExport
     {
         ColumnFamily cf = row.getColumnFamily();
         AbstractType comparator = cf.getComparator();
-        StringBuilder json = new StringBuilder(asKey(row.getKey().key));
+        StringBuilder json = new StringBuilder(asKey(asStr(row.getKey().key)));
         
         if (cf.isSuper())
         {
@@ -158,7 +166,7 @@ public class SSTableExport
         {
             DecoratedKey decoratedKey = partitioner.convertFromDiskFormat(input.readUTF());
             long dataPosition = input.readLong();
-            outs.println(decoratedKey.key);
+            outs.println(asStr(decoratedKey.key));
         }
 
         outs.flush();
@@ -265,7 +273,7 @@ public class SSTableExport
         while(scanner.hasNext())
         {
             SSTableIdentityIterator row = (SSTableIdentityIterator) scanner.next();
-            if (excludeSet.contains(row.getKey().key))
+            if (excludeSet.contains(asStr(row.getKey().key)))
                 continue;
             try
             {
@@ -278,12 +286,12 @@ public class SSTableExport
             }
             catch (IOException ioexcep)
             {
-                System.err.println("WARNING: Corrupt row " + row.getKey().key + " (skipping).");
+                System.err.println("WARNING: Corrupt row " + asStr(row.getKey().key) + "
(skipping).");
                 continue;
             }
             catch (OutOfMemoryError oom)
             {
-                System.err.println("ERROR: Out of memory deserializing row " + row.getKey().key);
+                System.err.println("ERROR: Out of memory deserializing row " + asStr(row.getKey().key));
                 continue;
             }
         }

Modified: cassandra/trunk/src/java/org/apache/cassandra/tools/SSTableImport.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/tools/SSTableImport.java?rev=934150&r1=934149&r2=934150&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/tools/SSTableImport.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/tools/SSTableImport.java Wed Apr 14 19:52:05
2010
@@ -29,6 +29,7 @@ import org.apache.cassandra.db.filter.Qu
 import org.apache.cassandra.dht.IPartitioner;
 import org.apache.cassandra.io.util.DataOutputBuffer;
 import org.apache.cassandra.io.sstable.SSTableWriter;
+import org.apache.cassandra.utils.FBUtilities;
 import static org.apache.cassandra.utils.FBUtilities.hexToBytes;
 import org.apache.commons.cli.*;
 import org.json.simple.JSONArray;
@@ -75,6 +76,13 @@ public class SSTableImport
         }
     }
 
+    @Deprecated
+    private static String asStr(byte[] val)
+    {
+        // FIXME: should not interpret as a string
+        return new String(val, FBUtilities.UTF8);
+    }
+    
     /**
      * Add columns to a column family.
      * 
@@ -151,9 +159,9 @@ public class SSTableImport
             for (DecoratedKey<?> rowKey : decoratedKeys)
             {
                 if (cfType.equals("Super"))
-                    addToSuperCF((JSONObject)json.get(rowKey.key), cfamily);
+                    addToSuperCF((JSONObject)json.get(asStr(rowKey.key)), cfamily);
                 else
-                    addToStandardCF((JSONArray)json.get(rowKey.key), cfamily);
+                    addToStandardCF((JSONArray)json.get(asStr(rowKey.key)), cfamily);
                            
                 ColumnFamily.serializer().serializeWithIndexes(cfamily, dob);
                 writer.append(rowKey, dob);

Modified: cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java?rev=934150&r1=934149&r2=934150&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java Wed Apr 14 19:52:05
2010
@@ -22,6 +22,7 @@ import java.io.*;
 import java.math.BigInteger;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
+import java.nio.charset.Charset;
 import java.security.MessageDigest;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -53,6 +54,19 @@ public class FBUtilities
 
     private static volatile InetAddress localInetAddress_;
 
+    public static Charset UTF8;
+    static
+    {
+        try
+        {
+            UTF8 = Charset.forName("UTF-8");
+        }
+        catch (Exception e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
+
     public static String[] strip(String string, String token)
     {
         StringTokenizer st = new StringTokenizer(string, token);



Mime
View raw message