You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ra...@apache.org on 2013/08/06 19:19:04 UTC

svn commit: r1511043 - in /hbase/trunk/hbase-common/src: main/java/org/apache/hadoop/hbase/CellUtil.java main/java/org/apache/hadoop/hbase/codec/CellCodec.java test/java/org/apache/hadoop/hbase/codec/TestCellCodec.java

Author: ramkrishna
Date: Tue Aug  6 17:19:04 2013
New Revision: 1511043

URL: http://svn.apache.org/r1511043
Log:
HBASE-8849 - CellCodec should write and read the memstoreTS/mvccVersion (Ram)


Modified:
    hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java
    hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/codec/CellCodec.java
    hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodec.java

Modified: hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java?rev=1511043&r1=1511042&r2=1511043&view=diff
==============================================================================
--- hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java (original)
+++ hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java Tue Aug  6 17:19:04 2013
@@ -128,6 +128,17 @@ public final class CellUtil {
     return new KeyValue(row, family, qualifier, timestamp,
       KeyValue.Type.codeToType(type), value);
   }
+  
+  public static Cell createCell(final byte[] row, final byte[] family, final byte[] qualifier,
+      final long timestamp, final byte type, final byte[] value, final long memstoreTS) {
+    // I need a Cell Factory here. Using KeyValue for now. TODO.
+    // TODO: Make a new Cell implementation that just carries these
+    // byte arrays.
+    KeyValue keyValue = new KeyValue(row, family, qualifier, timestamp,
+        KeyValue.Type.codeToType(type), value);
+    keyValue.setMvccVersion(memstoreTS);
+    return keyValue;
+  }
 
   /**
    * @param cellScannerables
@@ -283,4 +294,4 @@ public final class CellUtil {
       // Serialization is probably preceded by a length (it is in the KeyValueCodec at least).
       Bytes.SIZEOF_INT;
   }
-}
\ No newline at end of file
+}

Modified: hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/codec/CellCodec.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/codec/CellCodec.java?rev=1511043&r1=1511042&r2=1511043&view=diff
==============================================================================
--- hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/codec/CellCodec.java (original)
+++ hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/codec/CellCodec.java Tue Aug  6 17:19:04 2013
@@ -28,8 +28,7 @@ import org.apache.hadoop.hbase.util.Byte
 
 /**
  * Basic Cell codec that just writes out all the individual elements of a Cell.  Uses ints
- * delimiting all lengths. Profligate. Needs tune up.  Does not write the mvcc stamp.
- * Use a different codec if you want that in the stream.
+ * delimiting all lengths. Profligate. Needs tune up. 
  */
 public class CellCodec implements Codec {
   static class CellEncoder extends BaseEncoder {
@@ -52,6 +51,8 @@ public class CellCodec implements Codec 
       this.out.write(cell.getTypeByte());
       // Value
       write(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
+      // MvccVersion
+      this.out.write(Bytes.toBytes(cell.getMvccVersion()));
     }
 
     /**
@@ -82,7 +83,11 @@ public class CellCodec implements Codec 
       long timestamp = Bytes.toLong(longArray);
       byte type = (byte) this.in.read();
       byte [] value = readByteArray(in);
-      return CellUtil.createCell(row, family, qualifier, timestamp, type, value);
+      // Read memstore version
+      byte[] memstoreTSArray = new byte[Bytes.SIZEOF_LONG];
+      IOUtils.readFully(this.in, memstoreTSArray);
+      long memstoreTS = Bytes.toLong(memstoreTSArray);
+      return CellUtil.createCell(row, family, qualifier, timestamp, type, value, memstoreTS);
     }
 
     /**
@@ -108,4 +113,4 @@ public class CellCodec implements Codec 
   public Encoder getEncoder(OutputStream os) {
     return new CellEncoder(os);
   }
-}
\ No newline at end of file
+}

Modified: hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodec.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodec.java?rev=1511043&r1=1511042&r2=1511043&view=diff
==============================================================================
--- hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodec.java (original)
+++ hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/codec/TestCellCodec.java Tue Aug  6 17:19:04 2013
@@ -70,6 +70,7 @@ public class TestCellCodec {
     Codec.Encoder encoder = codec.getEncoder(dos);
     final KeyValue kv =
       new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("q"), Bytes.toBytes("v"));
+    kv.setMvccVersion(Long.MAX_VALUE);
     encoder.write(kv);
     encoder.flush();
     dos.close();
@@ -121,4 +122,4 @@ public class TestCellCodec {
     dis.close();
     assertEquals(offset, cis.getCount());
   }
-}
\ No newline at end of file
+}