hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apurt...@apache.org
Subject svn commit: r784618 [2/11] - in /hadoop/hbase/trunk_on_hadoop-0.18.3/src: java/ java/org/apache/hadoop/hbase/ java/org/apache/hadoop/hbase/client/ java/org/apache/hadoop/hbase/client/tableindexed/ java/org/apache/hadoop/hbase/filter/ java/org/apache/ha...
Date Sun, 14 Jun 2009 21:34:19 GMT
Modified: hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/KeyValue.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/KeyValue.java?rev=784618&r1=784617&r2=784618&view=diff
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/KeyValue.java (original)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/KeyValue.java Sun Jun 14 21:34:13 2009
@@ -25,11 +25,11 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.hbase.io.HeapSize;
 import org.apache.hadoop.hbase.io.hfile.HFile;
 import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.io.RawComparator;
+import org.apache.hadoop.hbase.io.HeapSize;
 import org.apache.hadoop.io.Writable;
+import org.apache.hadoop.io.RawComparator;
 
 /**
  * An HBase Key/Value.  Instances of this class are immutable.  They are not
@@ -59,8 +59,6 @@
    * Colon character in UTF-8
    */
   public static final char COLUMN_FAMILY_DELIMITER = ':';
-
-  public static final byte[] COLUMN_FAMILY_DELIM_ARRAY = new byte[]{COLUMN_FAMILY_DELIMITER};
   
   /**
    * Comparator for plain key/values; i.e. non-catalog table key/values.
@@ -120,45 +118,26 @@
         return compare(a, 0, a.length, b, 0, b.length);
       }
     };
-  
-  /**
-   * Get the appropriate row comparator for the specified table.
-   * 
-   * Hopefully we can get rid of this, I added this here because it's replacing
-   * something in HSK.  We should move completely off of that.
-   * 
-   * @param tableName  The table name.
-   * @return The comparator.
-   */
-  public static RawComparator<byte []> getRowComparator(byte [] tableName) {
-    if(Bytes.equals(HTableDescriptor.ROOT_TABLEDESC.getName(),tableName)) {
-      return ROOT_COMPARATOR.getRawComparator();
-    }
-    if(Bytes.equals(HTableDescriptor.META_TABLEDESC.getName(), tableName)) {
-      return META_COMPARATOR.getRawComparator();
-    }
-    return COMPARATOR.getRawComparator();
-  }
 
   // Size of the timestamp and type byte on end of a key -- a long + a byte.
-  public static final int TIMESTAMP_TYPE_SIZE =
+  private static final int TIMESTAMP_TYPE_SIZE =
     Bytes.SIZEOF_LONG /* timestamp */ +
     Bytes.SIZEOF_BYTE /*keytype*/;
 
   // Size of the length shorts and bytes in key.
-  public static final int KEY_INFRASTRUCTURE_SIZE =
+  private static final int KEY_INFRASTRUCTURE_SIZE =
     Bytes.SIZEOF_SHORT /*rowlength*/ +
     Bytes.SIZEOF_BYTE /*columnfamilylength*/ +
     TIMESTAMP_TYPE_SIZE;
 
   // How far into the key the row starts at. First thing to read is the short
   // that says how long the row is.
-  public static final int ROW_OFFSET =
+  private static final int ROW_OFFSET =
     Bytes.SIZEOF_INT /*keylength*/ +
     Bytes.SIZEOF_INT /*valuelength*/;
 
   // Size of the length ints in a KeyValue datastructure.
-  public static final int KEYVALUE_INFRASTRUCTURE_SIZE = ROW_OFFSET;
+  private static final int KEYVALUE_INFRASTRUCTURE_SIZE = ROW_OFFSET;
 
   /**
    * Key type.
@@ -166,13 +145,10 @@
    * enum ordinals . They change if item is removed or moved.  Do our own codes.
    */
   public static enum Type {
-    Minimum((byte)0),
     Put((byte)4),
-
     Delete((byte)8),
     DeleteColumn((byte)12),
     DeleteFamily((byte)14),
-
     // Maximum is used when searching; you look from maximum on down.
     Maximum((byte)255);
     
@@ -257,200 +233,194 @@
     this.offset = offset;
     this.length = length;
   }
-
-  /** Temporary constructors until 880/1249 is committed to remove deps */
   
   /**
-   * Temporary.
+   * Constructs KeyValue structure filled with null value.
+   * @param row - row key (arbitrary byte array)
+   * @param timestamp
    */
-  public KeyValue(final byte [] row, final byte [] column) {
-    this(row, column, HConstants.LATEST_TIMESTAMP, null);
-  }
-  
-  public KeyValue(final byte [] row, final byte [] column, long ts) {
-    this(row, column, ts, null);
-  }
-  
-  public KeyValue(final byte [] row, final byte [] column, long ts,
-      byte [] value) {
-    this(row, column, ts, Type.Put, value);
+  public KeyValue(final String row, final long timestamp) {
+    this(Bytes.toBytes(row), timestamp);
   }
-  
-  public KeyValue(final byte [] row, final byte [] column, long ts, Type type,
-      byte [] value) {
-    int rlength = row == null ? 0 : row.length;
-    int vlength = value == null ? 0 : value.length;
-    int clength = column == null ? 0 : column.length;
-    this.bytes = createByteArray(row, 0, rlength, column, 0, clength,
-        ts, type, value, 0, vlength);
-    this.length = this.bytes.length;
-    this.offset = 0;
-  }
-  
-  /** Constructors that build a new backing byte array from fields */
-  
+
   /**
    * Constructs KeyValue structure filled with null value.
    * @param row - row key (arbitrary byte array)
    * @param timestamp
    */
   public KeyValue(final byte [] row, final long timestamp) {
-    this(row, timestamp, Type.Put);
+    this(row, null, timestamp, Type.Put, null);
   }
 
   /**
    * Constructs KeyValue structure filled with null value.
    * @param row - row key (arbitrary byte array)
-   * @param timestamp
+   * @param column Column with delimiter between family and qualifier
    */
-  public KeyValue(final byte [] row, final long timestamp, Type type) {
-    this(row, null, null, timestamp, type, null);
+  public KeyValue(final String row, final String column) {
+    this(row, column, null);
   }
 
   /**
    * Constructs KeyValue structure filled with null value.
    * @param row - row key (arbitrary byte array)
-   * @param family family name
-   * @param qualifier column qualifier
+   * @param column Column with delimiter between family and qualifier
+   */
+  public KeyValue(final byte [] row, final byte [] column) {
+    this(row, column, null);
+  }
+
+  /**
+   * Constructs KeyValue structure filled with specified value.
+   * @param row - row key (arbitrary byte array)
+   * @param column Column with delimiter between family and qualifier
+   * @param value
    */
-  public KeyValue(final byte [] row, final byte [] family, 
-      final byte [] qualifier) {
-    this(row, family, qualifier, HConstants.LATEST_TIMESTAMP, Type.Put);
+  public KeyValue(final String row, final String column, final byte [] value) {
+    this(Bytes.toBytes(row), Bytes.toBytes(column), value);
   }
 
   /**
+   * Constructs KeyValue structure filled with specified value.
+   * @param row - row key (arbitrary byte array)
+   * @param column Column with delimiter between family and qualifier
+   * @param value
+   */
+  public KeyValue(final byte [] row, final byte [] column, final byte [] value) {
+    this(row, column, HConstants.LATEST_TIMESTAMP, value);
+  }
+
+
+  /**
    * Constructs KeyValue structure filled with null value.
    * @param row - row key (arbitrary byte array)
-   * @param family family name
-   * @param qualifier column qualifier
+   * @param column Column with delimiter between family and qualifier
+   * @param ts
    */
-  public KeyValue(final byte [] row, final byte [] family, 
-      final byte [] qualifier, final byte [] value) {
-    this(row, family, qualifier, HConstants.LATEST_TIMESTAMP, Type.Put, value);
+  public KeyValue(final String row, final String column, final long ts) {
+    this(row, column, ts, null);
   }
 
   /**
-   * Constructs KeyValue structure filled with specified values.
-   * @param row row key
-   * @param family family name
-   * @param qualifier column qualifier
-   * @param timestamp version timestamp
-   * @param type key type
-   * @throws IllegalArgumentException
+   * Constructs KeyValue structure filled with null value.
+   * @param row - row key (arbitrary byte array)
+   * @param column Column with delimiter between family and qualifier
+   * @param ts
    */
-  public KeyValue(final byte[] row, final byte[] family,
-      final byte[] qualifier, final long timestamp, Type type) {
-    this(row, family, qualifier, timestamp, type, null);
+  public KeyValue(final byte [] row, final byte [] column, final long ts) {
+    this(row, column, ts, Type.Put);
   }
-  
+
   /**
-   * Constructs KeyValue structure filled with specified values.
-   * @param row row key
-   * @param family family name
-   * @param qualifier column qualifier
-   * @param timestamp version timestamp
-   * @param value column value
-   * @throws IllegalArgumentException
+   * Constructs KeyValue structure filled with specified value.
+   * @param row - row key (arbitrary byte array)
+   * @param column Column with delimiter between family and qualifier
+   * @param timestamp
+   * @param value
    */
-  public KeyValue(final byte[] row, final byte[] family,
-      final byte[] qualifier, final long timestamp, final byte[] value) {
-    this(row, family, qualifier, timestamp, Type.Put, value);
+  public KeyValue(final String row, final String column,
+    final long timestamp, final byte [] value) {
+    this(Bytes.toBytes(row),
+      column == null? HConstants.EMPTY_BYTE_ARRAY: Bytes.toBytes(column),
+      timestamp, value);
   }
-  
+
   /**
-   * Constructs KeyValue structure filled with specified values.
-   * @param row row key
-   * @param family family name
-   * @param qualifier column qualifier
-   * @param timestamp version timestamp
-   * @param type key type
-   * @param value column value
-   * @throws IllegalArgumentException
+   * Constructs KeyValue structure filled with specified value.
+   * @param row - row key (arbitrary byte array)
+   * @param column Column with delimiter between family and qualifier
+   * @param timestamp
+   * @param value
    */
-  public KeyValue(final byte[] row, final byte[] family,
-      final byte[] qualifier, final long timestamp, Type type,
-      final byte[] value) {
-    this(row, family, qualifier, 0, qualifier==null ? 0 : qualifier.length, 
-        timestamp, type, value, 0, value==null ? 0 : value.length);
-  } 
-
-  /**
-   * Constructs KeyValue structure filled with specified values.
-   * @param row row key
-   * @param family family name
-   * @param qualifier column qualifier
-   * @param qoffset qualifier offset
-   * @param qlength qualifier length
-   * @param timestamp version timestamp
-   * @param type key type
-   * @param value column value
-   * @param voffset value offset
-   * @param vlength value length
-   * @throws IllegalArgumentException
+  public KeyValue(final byte [] row, final byte [] column,
+     final long timestamp, final byte [] value) {
+    this(row, column, timestamp, Type.Put, value);
+  }
+
+  /**
+   * Constructs KeyValue structure filled with specified value.
+   * @param row - row key (arbitrary byte array)
+   * @param column Column with delimiter between family and qualifier
+   * @param timestamp
+   * @param type
+   * @param value
    */
-  public KeyValue(byte [] row, byte [] family, 
-      byte [] qualifier, int qoffset, int qlength, long timestamp, Type type, 
-      byte [] value, int voffset, int vlength) {
-    this(row, 0, row==null ? 0 : row.length, 
-        family, 0, family==null ? 0 : family.length,
-        qualifier, qoffset, qlength, timestamp, type, 
-        value, voffset, vlength);
+  public KeyValue(final String row, final String column,
+     final long timestamp, final Type type, final byte [] value) {
+    this(Bytes.toBytes(row), Bytes.toBytes(column), timestamp, type,
+      value);
   }
 
   /**
-   * Constructs KeyValue structure filled with specified values.
-   * <p>
-   * Column is split into two fields, family and qualifier.
-   * @param row row key
-   * @param roffset row offset
-   * @param rlength row length
-   * @param family family name
-   * @param foffset family offset
-   * @param flength family length
-   * @param qualifier column qualifier
-   * @param qoffset qualifier offset
-   * @param qlength qualifier length
-   * @param timestamp version timestamp
-   * @param type key type
-   * @param value column value
-   * @param voffset value offset
-   * @param vlength value length
+   * Constructs KeyValue structure filled with null value.
+   * @param row - row key (arbitrary byte array)
+   * @param column Column with delimiter between family and qualifier
+   * @param timestamp
+   * @param type
+   */
+  public KeyValue(final byte [] row, final byte [] column,
+      final long timestamp, final Type type) {
+    this(row, 0, row.length, column, 0, column == null? 0: column.length,
+      timestamp, type, null, 0, -1);
+  }
+
+  /**
+   * Constructs KeyValue structure filled with specified value.
+   * @param row - row key (arbitrary byte array)
+   * @param column Column with delimiter between family and qualifier
+   * @param timestamp
+   * @param type
+   * @param value
+   */
+  public KeyValue(final byte [] row, final byte [] column,
+      final long timestamp, final Type type, final byte [] value) {
+    this(row, 0, row.length, column, 0, column == null? 0: column.length,
+      timestamp, type, value, 0, value == null? 0: value.length);
+  }
+
+  /**
+   * Constructs KeyValue structure filled with specified value.
+   * @param row - row key (arbitrary byte array)
+   * @param roffset
+   * @param rlength
+   * @param column Column with delimiter between family and qualifier
+   * @param coffset Where to start reading the column.
+   * @param clength How long column is (including the family/qualifier delimiter.
+   * @param timestamp
+   * @param type
+   * @param value
+   * @param voffset
+   * @param vlength
    * @throws IllegalArgumentException
    */
   public KeyValue(final byte [] row, final int roffset, final int rlength,
-      final byte [] family, final int foffset, final int flength,
-      final byte [] qualifier, final int qoffset, final int qlength,
+      final byte [] column, final int coffset, int clength,
       final long timestamp, final Type type,
-      final byte [] value, final int voffset, final int vlength) {
-    this.bytes = createByteArray(row, roffset, rlength, 
-        family, foffset, flength, qualifier, qoffset, qlength,
-        timestamp, type, value, voffset, vlength);
+      final byte [] value, final int voffset, int vlength) {
+    this.bytes = createByteArray(row, roffset, rlength, column, coffset,
+      clength, timestamp, type, value, voffset, vlength);
     this.length = bytes.length;
     this.offset = 0;
   }
 
   /**
    * Write KeyValue format into a byte array.
-   * 
-   * @param row row key
-   * @param roffset row offset
-   * @param rlength row length
-   * @param family family name
-   * @param foffset family offset
-   * @param flength family length
-   * @param qualifier column qualifier
-   * @param qoffset qualifier offset
-   * @param qlength qualifier length
-   * @param timestamp version timestamp
-   * @param type key type
-   * @param value column value
-   * @param voffset value offset
-   * @param vlength value length
-   * @return The newly created byte array. 
+   * @param row - row key (arbitrary byte array)
+   * @param roffset
+   * @param rlength
+   * @param column
+   * @param coffset
+   * @param clength
+   * @param timestamp
+   * @param type
+   * @param value
+   * @param voffset
+   * @param vlength
+   * @return
    */
   static byte [] createByteArray(final byte [] row, final int roffset,
-      final int rlength, final byte [] family, final int foffset, int flength,
-      final byte [] qualifier, final int qoffset, int qlength,
+        final int rlength,
+      final byte [] column, final int coffset, int clength,
       final long timestamp, final Type type,
       final byte [] value, final int voffset, int vlength) {
     if (rlength > Short.MAX_VALUE) {
@@ -459,30 +429,24 @@
     if (row == null) {
       throw new IllegalArgumentException("Row is null");
     }
-    // Family length
-    flength = family == null ? 0 : flength;
-    if (flength > Byte.MAX_VALUE) {
-      throw new IllegalArgumentException("Family > " + Byte.MAX_VALUE);
-    }
-    // Qualifier length
-    qlength = qualifier == null ? 0 : qlength;
-    if (qlength > Integer.MAX_VALUE - rlength - flength) {
-      throw new IllegalArgumentException("Qualifier > " + Integer.MAX_VALUE);
+    // If column is non-null, figure where the delimiter is at.
+    int delimiteroffset = 0;
+    if (column != null && column.length > 0) {
+      delimiteroffset = getFamilyDelimiterIndex(column, coffset, clength);
+      if (delimiteroffset > Byte.MAX_VALUE) {
+        throw new IllegalArgumentException("Family > " + Byte.MAX_VALUE);
+      }
     }
-    // Key length
-    long longkeylength = KEY_INFRASTRUCTURE_SIZE + rlength + flength + qlength;
+    // Value length
+    vlength = value == null? 0: vlength;
+    // Column length - minus delimiter
+    clength = column == null || column.length == 0? 0: clength - 1;
+    long longkeylength = KEY_INFRASTRUCTURE_SIZE + rlength + clength;
     if (longkeylength > Integer.MAX_VALUE) {
       throw new IllegalArgumentException("keylength " + longkeylength + " > " +
         Integer.MAX_VALUE);
     }
     int keylength = (int)longkeylength;
-    // Value length
-    vlength = value == null? 0 : vlength;
-    if (vlength > HConstants.MAXIMUM_VALUE_LENGTH) {
-      throw new IllegalArgumentException("Valuer > " + 
-          HConstants.MAXIMUM_VALUE_LENGTH);
-    }
-    
     // Allocate right-sized byte array.
     byte [] bytes = new byte[KEYVALUE_INFRASTRUCTURE_SIZE + keylength + vlength];
     // Write key, value and key row length.
@@ -491,12 +455,15 @@
     pos = Bytes.putInt(bytes, pos, vlength);
     pos = Bytes.putShort(bytes, pos, (short)(rlength & 0x0000ffff));
     pos = Bytes.putBytes(bytes, pos, row, roffset, rlength);
-    pos = Bytes.putByte(bytes, pos, (byte)(flength & 0x0000ff));
-    if(flength != 0) {
-      pos = Bytes.putBytes(bytes, pos, family, foffset, flength);
-    }
-    if(qlength != 0) {
-      pos = Bytes.putBytes(bytes, pos, qualifier, qoffset, qlength);
+    // Write out column family length.
+    pos = Bytes.putByte(bytes, pos, (byte)(delimiteroffset & 0x0000ff));
+    if (column != null && column.length != 0) {
+      // Write family.
+      pos = Bytes.putBytes(bytes, pos, column, coffset, delimiteroffset);
+      // Write qualifier.
+      delimiteroffset++;
+      pos = Bytes.putBytes(bytes, pos, column, coffset + delimiteroffset,
+        column.length - delimiteroffset);
     }
     pos = Bytes.putLong(bytes, pos, timestamp);
     pos = Bytes.putByte(bytes, pos, type.getCode());
@@ -505,46 +472,6 @@
     }
     return bytes;
   }
-  
-  /**
-   * Write KeyValue format into a byte array.
-   * <p>
-   * Takes column in the form <code>family:qualifier</code>
-   * @param row - row key (arbitrary byte array)
-   * @param roffset
-   * @param rlength
-   * @param column
-   * @param coffset
-   * @param clength
-   * @param timestamp
-   * @param type
-   * @param value
-   * @param voffset
-   * @param vlength
-   * @return The newly created byte array. 
-   */
-  static byte [] createByteArray(final byte [] row, final int roffset,
-        final int rlength,
-      final byte [] column, final int coffset, int clength,
-      final long timestamp, final Type type,
-      final byte [] value, final int voffset, int vlength) {
-    // If column is non-null, figure where the delimiter is at.
-    int delimiteroffset = 0;
-    if (column != null && column.length > 0) {
-      delimiteroffset = getFamilyDelimiterIndex(column, coffset, clength);
-      if (delimiteroffset > Byte.MAX_VALUE) {
-        throw new IllegalArgumentException("Family > " + Byte.MAX_VALUE);
-      }
-    } else {
-      return createByteArray(row,roffset,rlength,null,0,0,null,0,0,timestamp,
-          type,value,voffset,vlength);
-    }
-    int flength = delimiteroffset-coffset;
-    int qlength = clength - flength - 1;
-    return createByteArray(row, roffset, rlength, column, coffset,
-        flength, column, delimiteroffset+1, qlength, timestamp, type,
-        value, voffset, vlength);
-  }
 
   // Needed doing 'contains' on List.  Only compares the key portion, not the
   // value.
@@ -558,36 +485,37 @@
     return result;
   }
 
-  //---------------------------------------------------------------------------
-  //
-  //  KeyValue cloning
-  //
-  //---------------------------------------------------------------------------
-  
   /**
-   * Clones a row.
-   * 
-   * @param timestamp  The new time stamp for the row.
+   * @param timestamp
    * @return Clone of bb's key portion with only the row and timestamp filled in.
+   * @throws IOException
    */
   public KeyValue cloneRow(final long timestamp) {
     return new KeyValue(getBuffer(), getRowOffset(), getRowLength(),
-        null, 0, 0, null, 0, 0, 
-        timestamp, Type.codeToType(getType()), null, 0, 0);
+      null, 0, 0, timestamp, Type.codeToType(getType()), null, 0, 0);
+  }
+
+  /**
+   * @return Clone of bb's key portion with type set to Type.Delete.
+   * @throws IOException
+   */
+  public KeyValue cloneDelete() {
+    return createKey(Type.Delete);
   }
 
   /**
    * @return Clone of bb's key portion with type set to Type.Maximum. Use this
    * doing lookups where you are doing getClosest.  Using Maximum, you'll be
    * sure to trip over all of the other key types since Maximum sorts first.
+   * @throws IOException
    */
   public KeyValue cloneMaximum() {
      return createKey(Type.Maximum);
   }
 
-  /**
-   * Make a clone with the new type. Does not copy value.
-   * 
+  /*
+   * Make a clone with the new type.
+   * Does not copy value.
    * @param newtype New type to set on clone of this key.
    * @return Clone of this key with type set to <code>newtype</code>
    */
@@ -603,12 +531,6 @@
     return new KeyValue(other, 0, other.length);
   }
 
-  //---------------------------------------------------------------------------
-  //
-  //  String representation
-  //
-  //---------------------------------------------------------------------------
-  
   public String toString() {
     return keyToString(this.bytes, this.offset + ROW_OFFSET, getKeyLength()) +
       "/vlen=" + getValueLength();
@@ -623,7 +545,6 @@
   }
 
   /**
-   * Use for logging.
    * @param b Key portion of a KeyValue.
    * @param o Offset to start of key
    * @param l Length of key.
@@ -631,7 +552,7 @@
    */
   public static String keyToString(final byte [] b, final int o, final int l) {
     int rowlength = Bytes.toShort(b, o);
-    String row = Bytes.toStringBinary(b, o + Bytes.SIZEOF_SHORT, rowlength);
+    String row = Bytes.toString(b, o + Bytes.SIZEOF_SHORT, rowlength);
     int columnoffset = o + Bytes.SIZEOF_SHORT + 1 + rowlength;
     int familylength = b[columnoffset - 1];
     int columnlength = l - ((columnoffset - o) + TIMESTAMP_TYPE_SIZE);
@@ -642,20 +563,11 @@
       columnlength - familylength);
     long timestamp = Bytes.toLong(b, o + (l - TIMESTAMP_TYPE_SIZE));
     byte type = b[o + l - 1];
-//    return row + "/" + family +
-//      (family != null && family.length() > 0? COLUMN_FAMILY_DELIMITER: "") +
-//      qualifier + "/" + timestamp + "/" + Type.codeToType(type);
     return row + "/" + family +
-      (family != null && family.length() > 0? ":" :"") +
+      (family != null && family.length() > 0? COLUMN_FAMILY_DELIMITER: "") +
       qualifier + "/" + timestamp + "/" + Type.codeToType(type);
   }
 
-  //---------------------------------------------------------------------------
-  //
-  //  Public Member Accessors
-  //
-  //---------------------------------------------------------------------------
-  
   /**
    * @return The byte array backing this KeyValue.
    */
@@ -677,13 +589,7 @@
     return length;
   }
 
-  //---------------------------------------------------------------------------
-  //
-  //  Length and Offset Calculators
-  //
-  //---------------------------------------------------------------------------
-  
-  /**
+  /*
    * Determines the total length of the KeyValue stored in the specified
    * byte array and offset.  Includes all headers.
    * @param bytes byte array
@@ -697,188 +603,40 @@
   }
 
   /**
-   * @return Key offset in backing buffer..
+   * @return Copy of the key portion only.  Used compacting and testing.
    */
-  public int getKeyOffset() {
-    return this.offset + ROW_OFFSET;
+  public byte [] getKey() {
+    int keylength = getKeyLength();
+    byte [] key = new byte[keylength];
+    System.arraycopy(getBuffer(), getKeyOffset(), key, 0, keylength);
+    return key;
   }
 
   public String getKeyString() {
-    return Bytes.toStringBinary(getBuffer(), getKeyOffset(), getKeyLength());
-  }
-
-  /**
-   * @return Length of key portion.
-   */
-  public int getKeyLength() {
-    return Bytes.toInt(this.bytes, this.offset);
+    return Bytes.toString(getBuffer(), getKeyOffset(), getKeyLength());
   }
 
   /**
-   * @return Value offset
-   */
-  public int getValueOffset() {
-    return getKeyOffset() + getKeyLength();
-  }
-  
-  /**
-   * @return Value length
+   * @return Key offset in backing buffer..
    */
-  public int getValueLength() {
-    return Bytes.toInt(this.bytes, this.offset + Bytes.SIZEOF_INT);
+  public int getKeyOffset() {
+    return this.offset + ROW_OFFSET;
   }
 
   /**
-   * @return Row offset
-   */
-  public int getRowOffset() {
-    return getKeyOffset() + Bytes.SIZEOF_SHORT;
-  }
-  
-  /**
-   * @return Row length
+   * @return Row length.
    */
   public short getRowLength() {
     return Bytes.toShort(this.bytes, getKeyOffset());
   }
 
   /**
-   * @return Family offset
-   */
-  public int getFamilyOffset() {
-    return getFamilyOffset(getRowLength());
-  }
-  
-  /**
-   * @return Family offset
-   */
-  public int getFamilyOffset(int rlength) {
-    return this.offset + ROW_OFFSET + Bytes.SIZEOF_SHORT + rlength + Bytes.SIZEOF_BYTE;
-  }
-  
-  /**
-   * @return Family length
-   */
-  public byte getFamilyLength() {
-    return getFamilyLength(getFamilyOffset());
-  }
-  
-  /**
-   * @return Family length
-   */
-  public byte getFamilyLength(int foffset) {
-    return this.bytes[foffset-1];
-  }
-
-  /**
-   * @return Qualifier offset
-   */
-  public int getQualifierOffset() {
-    return getQualifierOffset(getFamilyOffset());
-  }
-  
-  /**
-   * @return Qualifier offset
-   */
-  public int getQualifierOffset(int foffset) {
-    return foffset + getFamilyLength(foffset);
-  }
-  
-  /**
-   * @return Qualifier length
-   */
-  public int getQualifierLength() {
-    return getQualifierLength(getRowLength(),getFamilyLength());
-  }
-  
-  /**
-   * @return Qualifier length
-   */
-  public int getQualifierLength(int rlength, int flength) {
-    return getKeyLength() - 
-      (KEY_INFRASTRUCTURE_SIZE + rlength + flength);
-  }
-  
-  /**
-   * @return Column (family + qualifier) length
-   */
-  public int getTotalColumnLength() {
-    int rlength = getRowLength();
-    int foffset = getFamilyOffset(rlength);
-    return getTotalColumnLength(rlength,foffset);
-  }
-  
-  /**
-   * @return Column (family + qualifier) length
-   */
-  public int getTotalColumnLength(int rlength, int foffset) {
-    int flength = getFamilyLength(foffset);
-    int qlength = getQualifierLength(rlength,flength);
-    return flength + qlength;
-  }
-  
-  /**
-   * @return Timestamp offset
-   */
-  public int getTimestampOffset() {
-    return getTimestampOffset(getKeyLength());
-  }
-  
-  /**
-   * @param keylength Pass if you have it to save on a int creation.
-   * @return Timestamp offset
-   */
-  public int getTimestampOffset(final int keylength) {
-    return getKeyOffset() + keylength - TIMESTAMP_TYPE_SIZE;
-  }
-
-  /**
-   * @return True if this KeyValue has a LATEST_TIMESTAMP timestamp.
+   * @return Offset into backing buffer at which row starts.
    */
-  public boolean isLatestTimestamp() {
-    return  Bytes.compareTo(getBuffer(), getTimestampOffset(), Bytes.SIZEOF_LONG, 
-      HConstants.LATEST_TIMESTAMP_BYTES, 0, Bytes.SIZEOF_LONG) == 0;
+  public int getRowOffset() {
+    return getKeyOffset() + Bytes.SIZEOF_SHORT;
   }
 
-  public boolean updateLatestStamp(final byte [] now) {
-    int tsOffset = getTimestampOffset();
-    if(Bytes.compareTo(now, 0, Bytes.SIZEOF_LONG, 
-        this.bytes, tsOffset, Bytes.SIZEOF_LONG) < 0) {
-      System.arraycopy(now, 0, this.bytes, tsOffset, Bytes.SIZEOF_LONG);
-      return true;
-    }
-    return false;
-  }
-  
-  //---------------------------------------------------------------------------
-  //
-  //  Methods that return copies of fields
-  //
-  //---------------------------------------------------------------------------
-  
-  /**
-   * @return Copy of the key portion only.  Used compacting and testing.
-   */
-  public byte [] getKey() {
-    int keylength = getKeyLength();
-    byte [] key = new byte[keylength];
-    System.arraycopy(getBuffer(), getKeyOffset(), key, 0, keylength);
-    return key;
-  }
-  
-  /**
-   * Do not use unless you have to.  Use {@link #getBuffer()} with appropriate
-   * offset and lengths instead.
-   * @return Value in a new byte array.
-   */
-  public byte [] getValue() {
-    int o = getValueOffset();
-    int l = getValueLength();
-    byte [] result = new byte[l];
-    System.arraycopy(getBuffer(), o, result, 0, l);
-    return result;
-  }
-  
   /**
    * Do not use this unless you have to.
    * Use {@link #getBuffer()} with appropriate offsets and lengths instead.
@@ -909,9 +667,24 @@
   }
 
   /**
+   * @param keylength Pass if you have it to save on a int creation.
+   * @return Offset into backing buffer at which timestamp starts.
+   */
+  int getTimestampOffset(final int keylength) {
+    return getKeyOffset() + keylength - TIMESTAMP_TYPE_SIZE;
+  }
+
+  /**
+   * @return True if a {@link Type#Delete}.
+   */
+  public boolean isDeleteType() {
+    return getType() == Type.Delete.getCode();
+  }
+
+  /**
    * @return Type of this KeyValue.
    */
-  public byte getType() {
+  byte getType() {
     return getType(getKeyLength());
   }
 
@@ -924,170 +697,99 @@
   }
 
   /**
-   * @return True if Delete KeyValue type.
+   * @return Length of key portion.
    */
-  public boolean isDeleteType() {
-    return getType() == Type.Delete.code;
+  public int getKeyLength() {
+    return Bytes.toInt(this.bytes, this.offset);
   }
 
   /**
-   * @return True if DeleteColumn KeyValue type.
+   * @return Value length
    */
-  public boolean isDeleteColumnType() {
-    return getType() == Type.DeleteColumn.code;
+  public int getValueLength() {
+    return Bytes.toInt(this.bytes, this.offset + Bytes.SIZEOF_INT);
   }
 
   /**
-   * Do not use this unless you have to.
-   * Use {@link #getBuffer()} with appropriate offsets and lengths instead.
-   * @return Returns column. Makes a copy.  Inserts delimiter.
+   * @return Offset into backing buffer at which value starts.
    */
-  public byte [] getColumn() {
-    int fo = getFamilyOffset();
-    int fl = getFamilyLength(fo);
-    int ql = getQualifierLength();
-    byte [] result = new byte[fl + 1 + ql];
-    System.arraycopy(this.bytes, fo, result, 0, fl);
-    result[fl] = COLUMN_FAMILY_DELIMITER;
-    System.arraycopy(this.bytes, fo + fl, result,
-      fl + 1, ql);
-    return result;
+  public int getValueOffset() {
+    return getKeyOffset() + getKeyLength();
   }
 
   /**
-   * Do not use this unless you have to.
-   * Use {@link #getBuffer()} with appropriate offsets and lengths instead.
-   * @return Returns family. Makes a copy.
+   * Do not use unless you have to.  Use {@link #getBuffer()} with appropriate
+   * offset and lengths instead.
+   * @return Value in a new byte array.
    */
-  public byte [] getFamily() {
-    int o = getFamilyOffset();
-    int l = getFamilyLength(o);
+  public byte [] getValue() {
+    int o = getValueOffset();
+    int l = getValueLength();
     byte [] result = new byte[l];
-    System.arraycopy(this.bytes, o, result, 0, l);
+    System.arraycopy(getBuffer(), o, result, 0, l);
     return result;
   }
 
   /**
-   * Do not use this unless you have to.
-   * Use {@link #getBuffer()} with appropriate offsets and lengths instead.
-   * @return Returns qualifier. Makes a copy.
+   * @return Offset into backing buffer at which the column begins
    */
-  public byte [] getQualifier() {
-    int o = getQualifierOffset();
-    int l = getQualifierLength();
-    byte [] result = new byte[l];
-    System.arraycopy(this.bytes, o, result, 0, l);
-    return result;
+  public int getColumnOffset() {
+    return getColumnOffset(getRowLength());
   }
 
-  //---------------------------------------------------------------------------
-  //
-  //  KeyValue splitter
-  //
-  //---------------------------------------------------------------------------
-  
   /**
-   * Utility class that splits a KeyValue buffer into separate byte arrays.
-   * <p>
-   * Should get rid of this if we can, but is very useful for debugging.
-   */
-  public static class SplitKeyValue {
-    private byte [][] split;
-    SplitKeyValue() {
-      this.split = new byte[6][];
-    }
-    public void setRow(byte [] value) { this.split[0] = value; }
-    public void setFamily(byte [] value) { this.split[1] = value; }
-    public void setQualifier(byte [] value) { this.split[2] = value; }
-    public void setTimestamp(byte [] value) { this.split[3] = value; }
-    public void setType(byte [] value) { this.split[4] = value; }
-    public void setValue(byte [] value) { this.split[5] = value; }
-    public byte [] getRow() { return this.split[0]; }
-    public byte [] getFamily() { return this.split[1]; }
-    public byte [] getQualifier() { return this.split[2]; }
-    public byte [] getTimestamp() { return this.split[3]; }
-    public byte [] getType() { return this.split[4]; }
-    public byte [] getValue() { return this.split[5]; }
+   * @param rowlength - length of row.
+   * @return Offset into backing buffer at which the column begins
+   */
+  public int getColumnOffset(final int rowlength) {
+    return getRowOffset() + rowlength + 1;
   }
-  
-  public SplitKeyValue split() {
-    SplitKeyValue split = new SplitKeyValue();
-    int splitOffset = this.offset;
-    int keyLen = Bytes.toInt(bytes, splitOffset);
-    splitOffset += Bytes.SIZEOF_INT;
-    int valLen = Bytes.toInt(bytes, splitOffset);
-    splitOffset += Bytes.SIZEOF_INT;
-    short rowLen = Bytes.toShort(bytes, splitOffset);
-    splitOffset += Bytes.SIZEOF_SHORT;
-    byte [] row = new byte[rowLen];
-    System.arraycopy(bytes, splitOffset, row, 0, rowLen);
-    splitOffset += rowLen;
-    split.setRow(row);
-    byte famLen = bytes[splitOffset];
-    splitOffset += Bytes.SIZEOF_BYTE;
-    byte [] family = new byte[famLen];
-    System.arraycopy(bytes, splitOffset, family, 0, famLen);
-    splitOffset += famLen;
-    split.setFamily(family);
-    int colLen = keyLen -
-      (rowLen + famLen + Bytes.SIZEOF_SHORT + Bytes.SIZEOF_BYTE +
-      Bytes.SIZEOF_LONG + Bytes.SIZEOF_BYTE);
-    byte [] qualifier = new byte[colLen];
-    System.arraycopy(bytes, splitOffset, qualifier, 0, colLen);
-    splitOffset += colLen;
-    split.setQualifier(qualifier);
-    byte [] timestamp = new byte[Bytes.SIZEOF_LONG];
-    System.arraycopy(bytes, splitOffset, timestamp, 0, Bytes.SIZEOF_LONG);
-    splitOffset += Bytes.SIZEOF_LONG;
-    split.setTimestamp(timestamp);
-    byte [] type = new byte[1];
-    type[0] = bytes[splitOffset];
-    splitOffset += Bytes.SIZEOF_BYTE;
-    split.setType(type);
-    byte [] value = new byte[valLen];
-    System.arraycopy(bytes, splitOffset, value, 0, valLen);
-    split.setValue(value);
-    return split;
+
+  /**
+   * @param columnoffset Pass if you have it to save on an int creation.
+   * @return Length of family portion of column.
+   */
+  int getFamilyLength(final int columnoffset) {
+    return this.bytes[columnoffset - 1];
   }
-  
-  //---------------------------------------------------------------------------
-  //
-  //  Compare specified fields against those contained in this KeyValue 
-  //
-  //---------------------------------------------------------------------------
-  
+
   /**
-   * @param family
-   * @return True if matching families.
+   * @param columnoffset Pass if you have it to save on an int creation.
+   * @return Length of column.
    */
-  public boolean matchingFamily(final byte [] family) {
-    int o = getFamilyOffset();
-    int l = getFamilyLength(o);
-    return Bytes.compareTo(family, 0, family.length, this.bytes, o, l) == 0;
+  public int getColumnLength(final int columnoffset) {
+    return getColumnLength(columnoffset, getKeyLength());
+  }
+
+  int getColumnLength(final int columnoffset, final int keylength) {
+    return (keylength + ROW_OFFSET) - (columnoffset - this.offset) -
+      TIMESTAMP_TYPE_SIZE;
   }
 
   /**
-   * @param qualifier
-   * @return True if matching qualifiers.
+   * @param family
+   * @return True if matching families.
    */
-  public boolean matchingQualifier(final byte [] qualifier) {
-    int o = getQualifierOffset();
-    int l = getQualifierLength();
-    return Bytes.compareTo(qualifier, 0, qualifier.length, 
-        this.bytes, o, l) == 0;
+  public boolean matchingFamily(final byte [] family) {
+    int o = getColumnOffset();
+    // Family length byte is just before the column starts.
+    int l = this.bytes[o - 1];
+    return Bytes.compareTo(family, 0, family.length, this.bytes, o, l) == 0;
   }
 
   /**
    * @param column Column minus its delimiter
+   * @param familylength Length of family in passed <code>column</code>
    * @return True if column matches.
    * @see #matchingColumn(byte[])
    */
-  public boolean matchingColumnNoDelimiter(final byte [] column) {
-    int rl = getRowLength();
-    int o = getFamilyOffset(rl);
-    int fl = getFamilyLength(o);
-    int l = fl + getQualifierLength(rl,fl);
-    return Bytes.compareTo(column, 0, column.length, this.bytes, o, l) == 0;
+  public boolean matchingColumnNoDelimiter(final byte [] column,
+      final int familylength) {
+    int o = getColumnOffset();
+    int l = getColumnLength(o);
+    int f = getFamilyLength(o);
+    return compareColumns(getBuffer(), o, l, f,
+      column, 0, column.length, familylength) == 0;
   }
 
   /**
@@ -1096,40 +798,14 @@
    */
   public boolean matchingColumn(final byte [] column) {
     int index = getFamilyDelimiterIndex(column, 0, column.length);
-    int rl = getRowLength();
-    int o = getFamilyOffset(rl);
-    int fl = getFamilyLength(o);
-    int ql = getQualifierLength(rl,fl);
-    if(Bytes.compareTo(column, 0, index, this.bytes, o, fl) != 0) {
-      return false;
-    }
-    return Bytes.compareTo(column, index + 1, column.length - (index + 1),
-        this.bytes, o + fl, ql) == 0;
-  }
-
-  /**
-   *
-   * @param family column family
-   * @param qualifier column qualifier
-   * @return True if column matches
-   */
-  public boolean matchingColumn(final byte[] family, final byte[] qualifier) {
-    int rl = getRowLength();
-    int o = getFamilyOffset(rl);
-    int fl = getFamilyLength(o);
-    int ql = getQualifierLength(rl,fl);
-    if(Bytes.compareTo(family, 0, family.length, this.bytes, o, family.length)
-        != 0) {
+    int o = getColumnOffset();
+    int l = getColumnLength(o);
+    int result = Bytes.compareTo(getBuffer(), o, index, column, 0, index);
+    if (result != 0) {
       return false;
     }
-    if(qualifier == null || qualifier.length == 0) {
-      if(ql == 0) {
-        return true;
-      }
-      return false;
-    }
-    return Bytes.compareTo(qualifier, 0, qualifier.length,
-        this.bytes, o + fl, ql) == 0;
+    return Bytes.compareTo(getBuffer(), o + index, l - index,
+      column, index + 1, column.length - (index + 1)) == 0;
   }
 
   /**
@@ -1141,7 +817,7 @@
    * @param roffset
    * @param rlength
    * @param rfamilylength Offset of family delimiter in right column.
-   * @return The result of the comparison.
+   * @return
    */
   static int compareColumns(final byte [] left, final int loffset,
       final int llength, final int lfamilylength,
@@ -1167,33 +843,41 @@
   }
 
   /**
-   * @return True if column is empty.
+   * @return Returns column String with delimiter added back. Expensive!
    */
-  public boolean isEmptyColumn() {
-    return getQualifierLength() == 0;
+  public String getColumnString() {
+    int o = getColumnOffset();
+    int l = getColumnLength(o);
+    int familylength = getFamilyLength(o);
+    return Bytes.toString(this.bytes, o, familylength) +
+      COLUMN_FAMILY_DELIMITER + Bytes.toString(this.bytes,
+       o + familylength, l - familylength);
   }
 
   /**
-   * Splits a column in family:qualifier form into separate byte arrays.
-   * 
-   * @param c  The column.
-   * @return The parsed column.
-   */
-  public static byte [][] parseColumn(byte [] c) {
-    final byte [][] result = new byte [2][];
-    final int index = getFamilyDelimiterIndex(c, 0, c.length);
-    if (index == -1) {
-      throw new IllegalArgumentException("Impossible column name: " + c);
-    }
-    result[0] = new byte [index];
-    System.arraycopy(c, 0, result[0], 0, index);
-    final int len = c.length - (index + 1);
-    result[1] = new byte[len];
-    System.arraycopy(c, index + 1 /*Skip delimiter*/, result[1], 0,
-      len);
+   * Do not use this unless you have to.
+   * Use {@link #getBuffer()} with appropriate offsets and lengths instead.
+   * @return Returns column. Makes a copy.  Inserts delimiter.
+   */
+  public byte [] getColumn() {
+    int o = getColumnOffset();
+    int l = getColumnLength(o);
+    int familylength = getFamilyLength(o);
+    byte [] result = new byte[l + 1];
+    System.arraycopy(getBuffer(), o, result, 0, familylength);
+    result[familylength] = COLUMN_FAMILY_DELIMITER;
+    System.arraycopy(getBuffer(), o + familylength, result,
+      familylength + 1, l - familylength);
     return result;
   }
-  
+
+  /**
+   * @return True if column is empty.
+   */
+  public boolean isEmptyColumn() {
+    return getColumnLength(getColumnOffset()) == 0;
+  }
+
   /**
    * @param b
    * @return Index of the family-qualifier colon delimiter character in passed
@@ -1342,8 +1026,7 @@
      * @return Result comparing rows.
      */
     public int compareRows(final KeyValue left, final KeyValue right) {
-      return compareRows(left, left.getRowLength(), right, 
-          right.getRowLength());
+      return compareRows(left, left.getRowLength(), right, right.getRowLength());
     }
 
     /**
@@ -1375,27 +1058,28 @@
       return getRawComparator().compareRows(left, loffset, llength,
         right, roffset, rlength);
     }
-    
+
     public int compareColumns(final KeyValue left, final byte [] right,
         final int roffset, final int rlength, final int rfamilyoffset) {
-      int offset = left.getFamilyOffset();
-      int length = left.getFamilyLength() + left.getQualifierLength();
+      int offset = left.getColumnOffset();
+      int length = left.getColumnLength(offset);
       return getRawComparator().compareColumns(left.getBuffer(), offset, length,
         left.getFamilyLength(offset),
         right, roffset, rlength, rfamilyoffset);
     }
 
     int compareColumns(final KeyValue left, final short lrowlength,
-        final KeyValue right, final short rrowlength) {
-      int lfoffset = left.getFamilyOffset(lrowlength);
-      int rfoffset = right.getFamilyOffset(rrowlength);
-      int lclength = left.getTotalColumnLength(lrowlength,lfoffset);
-      int rclength = right.getTotalColumnLength(rrowlength, rfoffset);
-      int lfamilylength = left.getFamilyLength(lfoffset);
-      int rfamilylength = right.getFamilyLength(rfoffset);
-      return getRawComparator().compareColumns(left.getBuffer(), lfoffset,
-          lclength, lfamilylength,
-        right.getBuffer(), rfoffset, rclength, rfamilylength);
+        final int lkeylength, final KeyValue right, final short rrowlength,
+        final int rkeylength) {
+      int loffset = left.getColumnOffset(lrowlength);
+      int roffset = right.getColumnOffset(rrowlength);
+      int llength = left.getColumnLength(loffset, lkeylength);
+      int rlength = right.getColumnLength(roffset, rkeylength);
+      int lfamilylength = left.getFamilyLength(loffset);
+      int rfamilylength = right.getFamilyLength(roffset);
+      return getRawComparator().compareColumns(left.getBuffer(), loffset,
+          llength, lfamilylength,
+        right.getBuffer(), roffset, rlength, rfamilylength);
     }
 
     /**
@@ -1411,7 +1095,10 @@
       if (!matchingRows(left, lrowlength, right, rrowlength)) {
         return false;
       }
-      return compareColumns(left, lrowlength, right, rrowlength) == 0;
+      int lkeylength = left.getKeyLength();
+      int rkeylength = right.getKeyLength();
+      return compareColumns(left, lrowlength, lkeylength,
+        right, rrowlength, rkeylength) == 0;
     }
 
     /**
@@ -1453,8 +1140,7 @@
     public boolean matchingRows(final byte [] left, final int loffset,
         final int llength,
         final byte [] right, final int roffset, final int rlength) {
-      int compare = compareRows(left, loffset, llength, 
-          right, roffset, rlength);
+      int compare = compareRows(left, loffset, llength, right, roffset, rlength);
       if (compare != 0) {
         return false;
       }
@@ -1485,6 +1171,7 @@
  
     /**
      * @return Comparator that ignores timestamps; useful counting versions.
+     * @throws IOException
      */
     public KVComparator getComparatorIgnoringTimestamps() {
       KVComparator c = null;
@@ -1527,44 +1214,20 @@
    */
   public static KeyValue createFirstOnRow(final byte [] row,
       final long ts) {
-    return new KeyValue(row, null, null, ts, Type.Maximum);
+    return createFirstOnRow(row, null, ts);
   }
 
   /**
    * @param row - row key (arbitrary byte array)
    * @param ts - timestamp
-   * @return First possible key on passed <code>row</code>, column and timestamp
+   * @return First possible key on passed <code>row</code>, column and timestamp.
    */
   public static KeyValue createFirstOnRow(final byte [] row, final byte [] c,
       final long ts) {
-    byte [][] split = parseColumn(c);
-    return new KeyValue(row, split[0], split[1], ts, Type.Maximum);
-  }
-
-  /**
-   * @param row - row key (arbitrary byte array)
-   * @param f - family name
-   * @param q - column qualifier
-   * @return First possible key on passed <code>row</code>, and column.
-   */
-  public static KeyValue createFirstOnRow(final byte [] row, final byte [] f,
-      final byte [] q) {
-    return new KeyValue(row, f, q, HConstants.LATEST_TIMESTAMP, Type.Maximum);
+    return new KeyValue(row, c, ts, Type.Maximum);
   }
 
   /**
-   * @param row - row key (arbitrary byte array)
-   * @param f - family name
-   * @param q - column qualifier
-   * @param ts - timestamp
-   * @return First possible key on passed <code>row</code>, column and timestamp
-   */
-  public static KeyValue createFirstOnRow(final byte [] row, final byte [] f,
-      final byte [] q, final long ts) {
-    return new KeyValue(row, f, q, ts, Type.Maximum);
-  }
-  
-  /**
    * @param b
    * @param o
    * @param l
@@ -1592,8 +1255,7 @@
       //          "---" + Bytes.toString(right, roffset, rlength));
       final int metalength = 7; // '.META.' length
       int lmetaOffsetPlusDelimiter = loffset + metalength;
-      int leftFarDelimiter = getDelimiterInReverse(left, 
-          lmetaOffsetPlusDelimiter,
+      int leftFarDelimiter = getDelimiterInReverse(left, lmetaOffsetPlusDelimiter,
           llength - metalength, HRegionInfo.DELIMITER);
       int rmetaOffsetPlusDelimiter = roffset + metalength;
       int rightFarDelimiter = getDelimiterInReverse(right,
@@ -1701,9 +1363,6 @@
         return compare;
       }
 
-      // if row matches, and no column in the 'left' AND put type is 'minimum',
-      // then return that left is larger than right.
-
       // Compare column family.  Start compare past row and family length.
       int lcolumnoffset = Bytes.SIZEOF_SHORT + lrowlength + 1 + loffset;
       int rcolumnoffset = Bytes.SIZEOF_SHORT + rrowlength + 1 + roffset;
@@ -1711,24 +1370,12 @@
         (lcolumnoffset - loffset);
       int rcolumnlength = rlength - TIMESTAMP_TYPE_SIZE -
         (rcolumnoffset - roffset);
-
-      // This supports 'last key on a row' - the magic is if there is no column in the
-      // left operand, and the left operand has a type of '0' - magical value,
-      // then we say the left is bigger.  This will let us seek to the last key in
-      // a row.
-
-      byte ltype = left[loffset + (llength - 1)];
-
-      if (lcolumnlength == 0 && ltype == Type.Minimum.getCode()) {
-        return 1; // left is bigger.
-      }
-
       compare = Bytes.compareTo(left, lcolumnoffset, lcolumnlength, right,
           rcolumnoffset, rcolumnlength);
       if (compare != 0) {
         return compare;
       }
-      
+
       if (!this.ignoreTimestamp) {
         // Get timestamps.
         long ltimestamp = Bytes.toLong(left,
@@ -1744,8 +1391,7 @@
       if (!this.ignoreType) {
         // Compare types. Let the delete types sort ahead of puts; i.e. types
         // of higher numbers sort before those of lesser numbers
-
-        // ltype is defined above
+        byte ltype = left[loffset + (llength - 1)];
         byte rtype = right[roffset + (rlength - 1)];
         return (0xff & rtype) - (0xff & ltype);
       }
@@ -1756,7 +1402,7 @@
       return compare(left, 0, left.length, right, 0, right.length);
     }
 
-    public int compareRows(byte [] left, int loffset, int llength,
+    protected int compareRows(byte [] left, int loffset, int llength,
         byte [] right, int roffset, int rlength) {
       return Bytes.compareTo(left, loffset, llength, right, roffset, rlength);
     }
@@ -1784,9 +1430,7 @@
   
   // HeapSize
   public long heapSize() {
-    int dataLen = bytes.length + (bytes.length % 8);
-    return HeapSize.OBJECT + HeapSize.BYTE_ARRAY + dataLen +
-      (2 * HeapSize.INT);
+    return this.length;
   }
   
   // Writable

Modified: hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/RegionHistorian.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/RegionHistorian.java?rev=784618&r1=784617&r2=784618&view=diff
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/RegionHistorian.java (original)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/RegionHistorian.java Sun Jun 14 21:34:13 2009
@@ -29,10 +29,8 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.hbase.client.Get;
 import org.apache.hadoop.hbase.client.HTable;
-import org.apache.hadoop.hbase.client.Put;
-import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.io.BatchUpdate;
 import org.apache.hadoop.hbase.io.Cell;
 import org.apache.hadoop.hbase.util.Bytes;
 
@@ -59,17 +57,17 @@
   "EEE, d MMM yyyy HH:mm:ss");
 
   
-  private static enum HistorianQualifierKey  {
-    REGION_CREATION ( Bytes.toBytes("creation")),
-    REGION_OPEN ( Bytes.toBytes("open")),
-    REGION_SPLIT ( Bytes.toBytes("split")),
-    REGION_COMPACTION ( Bytes.toBytes("compaction")),
-    REGION_FLUSH ( Bytes.toBytes("flush")),
-    REGION_ASSIGNMENT ( Bytes.toBytes("assignment"));
+  private static enum HistorianColumnKey  {
+    REGION_CREATION ( Bytes.toBytes(COLUMN_FAMILY_HISTORIAN_STR+"creation")),
+    REGION_OPEN ( Bytes.toBytes(COLUMN_FAMILY_HISTORIAN_STR+"open")),
+    REGION_SPLIT ( Bytes.toBytes(COLUMN_FAMILY_HISTORIAN_STR+"split")),
+    REGION_COMPACTION ( Bytes.toBytes(COLUMN_FAMILY_HISTORIAN_STR+"compaction")),
+    REGION_FLUSH ( Bytes.toBytes(COLUMN_FAMILY_HISTORIAN_STR+"flush")),
+    REGION_ASSIGNMENT ( Bytes.toBytes(COLUMN_FAMILY_HISTORIAN_STR+"assignment"));
 
-    byte[] key;
+  byte[] key;
 
-    HistorianQualifierKey(byte[] key) {
+    HistorianColumnKey(byte[] key) {
       this.key = key;
     }
   } 
@@ -103,7 +101,7 @@
    *          Region name as a string
    * @return List of RegionHistoryInformation or null if we're offline.
    */
-  public List<RegionHistoryInformation> getRegionHistory(byte [] regionName) {
+  public List<RegionHistoryInformation> getRegionHistory(String regionName) {
     if (!isOnline()) {
       return null;
     }
@@ -115,17 +113,15 @@
        * moment to retrieve all version and to have the column key information.
        * To be changed when HTable.getRow handles versions.
        */
-      for (HistorianQualifierKey keyEnu : HistorianQualifierKey.values()) {
+      for (HistorianColumnKey keyEnu : HistorianColumnKey.values()) {
         byte[] columnKey = keyEnu.key;
-        Get get = new Get(regionName);
-        get.addColumn(CATALOG_HISTORIAN_FAMILY, columnKey);
-        get.setMaxVersions(ALL_VERSIONS);
-        Result result = this.metaTable.get(get);
-
-        if (result != null) {
-          for(KeyValue kv : result.raw()) {
-            informations.add(historian.new RegionHistoryInformation(
-                kv.getTimestamp(), columnKey, kv.getValue()));
+        Cell[] cells = this.metaTable.get(Bytes.toBytes(regionName),
+            columnKey, ALL_VERSIONS);
+        if (cells != null) {
+          for (Cell cell : cells) {
+            informations.add(historian.new RegionHistoryInformation(cell
+                .getTimestamp(), Bytes.toString(columnKey).split(":")[1], Bytes
+                .toString(cell.getValue())));
           }
         }
       }
@@ -142,7 +138,7 @@
    * @param serverName
    */
   public void addRegionAssignment(HRegionInfo info, String serverName) {
-    add(HistorianQualifierKey.REGION_ASSIGNMENT.key, "Region assigned to server "
+    add(HistorianColumnKey.REGION_ASSIGNMENT.key, "Region assigned to server "
         + serverName, info);
   }
 
@@ -151,7 +147,7 @@
    * @param info
    */
   public void addRegionCreation(HRegionInfo info) {
-    add(HistorianQualifierKey.REGION_CREATION.key, "Region creation", info);
+    add(HistorianColumnKey.REGION_CREATION.key, "Region creation", info);
   }
 
   /**
@@ -160,7 +156,7 @@
    * @param address
    */
   public void addRegionOpen(HRegionInfo info, HServerAddress address) {
-    add(HistorianQualifierKey.REGION_OPEN.key, "Region opened on server : "
+    add(HistorianColumnKey.REGION_OPEN.key, "Region opened on server : "
         + address.getHostname(), info);
   }
 
@@ -175,7 +171,7 @@
      HRegionInfo newInfo2) {
     HRegionInfo[] infos = new HRegionInfo[] { newInfo1, newInfo2 };
     for (HRegionInfo info : infos) {
-      add(HistorianQualifierKey.REGION_SPLIT.key, SPLIT_PREFIX +
+      add(HistorianColumnKey.REGION_SPLIT.key, SPLIT_PREFIX +
         oldInfo.getRegionNameAsString(), info);
     }
   }
@@ -192,7 +188,7 @@
     // such danger compacting; compactions are not allowed when
     // Flusher#flushSomeRegions is run.
     if (LOG.isDebugEnabled()) {
-      add(HistorianQualifierKey.REGION_COMPACTION.key,
+      add(HistorianColumnKey.REGION_COMPACTION.key,
         "Region compaction completed in " + timeTaken, info);
     }
   }
@@ -215,8 +211,9 @@
    * @param text
    * @param info
    */
-  private void add(byte [] qualifier, String text, HRegionInfo info) {
-    add(qualifier, text, info, LATEST_TIMESTAMP);
+  private void add(byte[] column,
+      String text, HRegionInfo info) {
+    add(column, text, info, LATEST_TIMESTAMP);
   }
 
   /**
@@ -226,19 +223,18 @@
    * @param info
    * @param timestamp
    */
-  private void add(byte [] qualifier, String text, HRegionInfo info,
-      long timestamp) {
+  private void add(byte[] column,
+      String text, HRegionInfo info, long timestamp) {
     if (!isOnline()) {
       // Its a noop
       return;
     }
     if (!info.isMetaRegion()) {
-      Put put = new Put(info.getRegionName());
-      put.setTimeStamp(timestamp);
-      put.add(HConstants.CATALOG_HISTORIAN_FAMILY, qualifier,
-          Bytes.toBytes(text));
+      BatchUpdate batch = new BatchUpdate(info.getRegionName());
+      batch.setTimestamp(timestamp);
+      batch.put(column, Bytes.toBytes(text));
       try {
-        this.metaTable.put(put);
+        this.metaTable.commit(batch);
       } catch (IOException ioe) {
         LOG.warn("Unable to '" + text + "'", ioe);
       }
@@ -256,35 +252,34 @@
 
     private long timestamp;
 
-    private byte [] event = null;
+    private String event;
 
-    private byte [] description = null;
+    private String description;
 
     /**
      * @param timestamp
      * @param event
      * @param description
      */
-    public RegionHistoryInformation(long timestamp, byte [] event,
-        byte [] description) {
+    public RegionHistoryInformation(long timestamp, String event,
+        String description) {
       this.timestamp = timestamp;
       this.event = event;
       this.description = description;
     }
-    
-    
+
     public int compareTo(RegionHistoryInformation otherInfo) {
       return -1 * Long.valueOf(timestamp).compareTo(otherInfo.getTimestamp());
     }
 
     /** @return the event */
     public String getEvent() {
-      return Bytes.toString(event);
+      return event;
     }
 
     /** @return the description */
     public String getDescription() {
-      return Bytes.toString(description);
+      return description;
     }
 
     /** @return the timestamp */

Modified: hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/WritableComparator.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/WritableComparator.java?rev=784618&r1=784617&r2=784618&view=diff
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/WritableComparator.java (original)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/WritableComparator.java Sun Jun 14 21:34:13 2009
@@ -23,7 +23,6 @@
 
 import org.apache.hadoop.io.Writable;
 
-/**
- * Interface that brings writable and comparable together
- */
-public interface WritableComparator<T> extends Writable, Comparator<T> {}
+public interface WritableComparator<T> extends Writable, Comparator<T> {
+// No methods, just bring the two interfaces together
+}

Modified: hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/client/HBaseAdmin.java?rev=784618&r1=784617&r2=784618&view=diff
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/client/HBaseAdmin.java (original)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/client/HBaseAdmin.java Sun Jun 14 21:34:13 2009
@@ -21,7 +21,6 @@
 
 import java.io.IOException;
 import java.util.Map;
-import java.util.NavigableMap;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -35,9 +34,8 @@
 import org.apache.hadoop.hbase.MasterNotRunningException;
 import org.apache.hadoop.hbase.RegionException;
 import org.apache.hadoop.hbase.RemoteExceptionHandler;
+import org.apache.hadoop.hbase.io.Cell;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-import org.apache.hadoop.hbase.client.Scan;
-import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.io.RowResult;
 import org.apache.hadoop.hbase.ipc.HMasterInterface;
 import org.apache.hadoop.hbase.ipc.HRegionInterface;
@@ -53,8 +51,7 @@
  */
 public class HBaseAdmin {
   private final Log LOG = LogFactory.getLog(this.getClass().getName());
-//  private final HConnection connection;
-  final HConnection connection;
+  private final HConnection connection;
   private volatile HBaseConfiguration conf;
   private final long pause;
   private final int numRetries;
@@ -124,13 +121,11 @@
     return this.connection.listTables();
   }
 
+  public HTableDescriptor getTableDescriptor(final String tableName)
+  throws IOException {
+    return getTableDescriptor(Bytes.toBytes(tableName));
+  }
   
-  /**
-   * Method for getting the tableDescriptor
-   * @param tableName as a byte []
-   * @return the tableDescriptor
-   * @throws IOException
-   */
   public HTableDescriptor getTableDescriptor(final byte [] tableName)
   throws IOException {
     return this.connection.getHTableDescriptor(tableName);
@@ -243,22 +238,19 @@
     for (int tries = 0; tries < numRetries; tries++) {
       long scannerId = -1L;
       try {
-        Scan scan = new Scan().addColumn(HConstants.CATALOG_FAMILY,
-            HConstants.REGIONINFO_QUALIFIER);
-        
-        scannerId = server.openScanner(
-            firstMetaServer.getRegionInfo().getRegionName(), 
-            scan);
-        Result values = server.next(scannerId);
+        scannerId =
+          server.openScanner(firstMetaServer.getRegionInfo().getRegionName(),
+            HConstants.COL_REGIONINFO_ARRAY, tableName,
+            HConstants.LATEST_TIMESTAMP, null);
+        RowResult values = server.next(scannerId);
         if (values == null || values.size() == 0) {
           break;
         }
         boolean found = false;
-        NavigableMap<byte[], byte[]> infoValues = values.getFamilyMap(HConstants.CATALOG_FAMILY);
-        for (Map.Entry<byte [], byte []> e: infoValues.entrySet()) {
-          if (Bytes.equals(e.getKey(), HConstants.REGIONINFO_QUALIFIER)) {
+        for (Map.Entry<byte [], Cell> e: values.entrySet()) {
+          if (Bytes.equals(e.getKey(), HConstants.COL_REGIONINFO)) {
             info = (HRegionInfo) Writables.getWritable(
-              e.getValue(), info);
+              e.getValue().getValue(), info);
             
             if (Bytes.equals(info.getTableDesc().getName(), tableName)) {
               found = true;
@@ -574,7 +566,7 @@
         newargs[i + xtraArgsCount] = args[i];
       }
     }
-    modifyTable(HConstants.META_TABLE_NAME, HConstants.Modify.CLOSE_REGION,
+    modifyTable(HConstants.META_TABLE_NAME, HConstants.MODIFY_CLOSE_REGION,
       newargs);
   }
   
@@ -597,7 +589,7 @@
    * @throws IOException
    */
   public void flush(final byte [] tableNameOrRegionName) throws IOException {
-    modifyTable(tableNameOrRegionName, HConstants.Modify.TABLE_FLUSH);
+    modifyTable(tableNameOrRegionName, HConstants.MODIFY_TABLE_FLUSH);
   }
 
   /**
@@ -619,7 +611,7 @@
    * @throws IOException
    */
   public void compact(final byte [] tableNameOrRegionName) throws IOException {
-    modifyTable(tableNameOrRegionName, HConstants.Modify.TABLE_COMPACT);
+    modifyTable(tableNameOrRegionName, HConstants.MODIFY_TABLE_COMPACT);
   }
   
   /**
@@ -643,7 +635,7 @@
    */
   public void majorCompact(final byte [] tableNameOrRegionName)
   throws IOException {
-    modifyTable(tableNameOrRegionName, HConstants.Modify.TABLE_MAJOR_COMPACT);
+    modifyTable(tableNameOrRegionName, HConstants.MODIFY_TABLE_MAJOR_COMPACT);
   }
 
   /**
@@ -665,7 +657,7 @@
    * @throws IOException
    */
   public void split(final byte [] tableNameOrRegionName) throws IOException {
-    modifyTable(tableNameOrRegionName, HConstants.Modify.TABLE_SPLIT);
+    modifyTable(tableNameOrRegionName, HConstants.MODIFY_TABLE_SPLIT);
   }
 
   /*
@@ -675,8 +667,7 @@
    * @param op
    * @throws IOException
    */
-  private void modifyTable(final byte [] tableNameOrRegionName, 
-      final HConstants.Modify op)
+  private void modifyTable(final byte [] tableNameOrRegionName, final int op)
   throws IOException {
     if (tableNameOrRegionName == null) {
       throw new IllegalArgumentException("Pass a table name or region name");
@@ -698,7 +689,7 @@
    */
   public void modifyTable(final byte [] tableName, HTableDescriptor htd) 
   throws IOException {
-    modifyTable(tableName, HConstants.Modify.TABLE_SET_HTD, htd);
+    modifyTable(tableName, HConstants.MODIFY_TABLE_SET_HTD, htd);
   }
 
   /**
@@ -711,8 +702,7 @@
    * @param args operation specific arguments
    * @throws IOException
    */
-  public void modifyTable(final byte [] tableName, HConstants.Modify op, 
-      Object... args)
+  public void modifyTable(final byte [] tableName, int op, Object... args)
       throws IOException {
     if (this.master == null) {
       throw new MasterNotRunningException("master has been shut down");
@@ -725,7 +715,7 @@
     Writable[] arr = null;
     try {
       switch (op) {
-      case TABLE_SET_HTD:
+      case HConstants.MODIFY_TABLE_SET_HTD:
         if (args == null || args.length < 1 || 
             !(args[0] instanceof HTableDescriptor)) {
           throw new IllegalArgumentException("SET_HTD requires a HTableDescriptor");
@@ -735,10 +725,10 @@
         this.master.modifyTable(tableName, op, arr);
         break;
 
-      case TABLE_COMPACT:
-      case TABLE_SPLIT:
-      case TABLE_MAJOR_COMPACT:
-      case TABLE_FLUSH:
+      case HConstants.MODIFY_TABLE_COMPACT:
+      case HConstants.MODIFY_TABLE_SPLIT:
+      case HConstants.MODIFY_TABLE_MAJOR_COMPACT:
+      case HConstants.MODIFY_TABLE_FLUSH:
         if (args != null && args.length > 0) {
           arr = new Writable[1];
           if (args[0] instanceof byte[]) {
@@ -755,7 +745,7 @@
         this.master.modifyTable(tableName, op, arr);
         break;
 
-      case CLOSE_REGION:
+      case HConstants.MODIFY_CLOSE_REGION:
         if (args == null || args.length < 1) {
           throw new IllegalArgumentException("Requires at least a region name");
         }

Modified: hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/client/HConnection.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/client/HConnection.java?rev=784618&r1=784617&r2=784618&view=diff
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/client/HConnection.java (original)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/client/HConnection.java Sun Jun 14 21:34:13 2009
@@ -26,6 +26,7 @@
 import org.apache.hadoop.hbase.HServerAddress;
 import org.apache.hadoop.hbase.HTableDescriptor;
 import org.apache.hadoop.hbase.MasterNotRunningException;
+import org.apache.hadoop.hbase.io.BatchUpdate;
 import org.apache.hadoop.hbase.ipc.HMasterInterface;
 import org.apache.hadoop.hbase.ipc.HRegionInterface;
 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWrapper;
@@ -189,6 +190,6 @@
    * @param tableName The name of the table
    * @throws IOException
    */
-  public void processBatchOfRows(ArrayList<Put> list, byte[] tableName)
+  public void processBatchOfRows(ArrayList<BatchUpdate> list, byte[] tableName)
       throws IOException;
 }
\ No newline at end of file

Modified: hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java?rev=784618&r1=784617&r2=784618&view=diff
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java (original)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java Sun Jun 14 21:34:13 2009
@@ -1,5 +1,5 @@
 /**
- * Copyright 2009 The Apache Software Foundation
+ * Copyright 2007 The Apache Software Foundation
  *
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -38,12 +38,15 @@
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.HRegionLocation;
 import org.apache.hadoop.hbase.HServerAddress;
+import org.apache.hadoop.hbase.HStoreKey;
 import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.MasterNotRunningException;
 import org.apache.hadoop.hbase.RemoteExceptionHandler;
 import org.apache.hadoop.hbase.TableNotFoundException;
 import org.apache.hadoop.hbase.client.MetaScanner.MetaScannerVisitor;
+import org.apache.hadoop.hbase.io.BatchUpdate;
+import org.apache.hadoop.hbase.io.Cell;
+import org.apache.hadoop.hbase.io.RowResult;
 import org.apache.hadoop.hbase.ipc.HBaseRPC;
 import org.apache.hadoop.hbase.ipc.HBaseRPCProtocolVersion;
 import org.apache.hadoop.hbase.ipc.HMasterInterface;
@@ -113,19 +116,6 @@
     }
   }
 
-  /**
-   * Delete information for all connections.
-   * @param stopProxy
-   */
-  public static void deleteAllConnections(boolean stopProxy) {
-    synchronized (HBASE_INSTANCES) {
-      for (TableServers t : HBASE_INSTANCES.values()) {
-        if (t != null) {
-          t.close(stopProxy);
-        }
-      }
-    }
-  }
 
   /* Encapsulates finding the servers for an HBase instance */
   private static class TableServers implements ServerConnection, HConstants, Watcher {
@@ -134,6 +124,7 @@
     private final long pause;
     private final int numRetries;
     private final int maxRPCAttempts;
+    private final long rpcTimeout;
 
     private final Object masterLock = new Object();
     private volatile boolean closed;
@@ -184,6 +175,7 @@
       this.pause = conf.getLong("hbase.client.pause", 2 * 1000);
       this.numRetries = conf.getInt("hbase.client.retries.number", 10);
       this.maxRPCAttempts = conf.getInt("hbase.client.rpc.maxattempts", 1);
+      this.rpcTimeout = conf.getLong("hbase.regionserver.lease.period", 60000);
       
       this.master = null;
       this.masterChecked = false;
@@ -216,10 +208,7 @@
     }
 
     private synchronized void resetZooKeeper() {
-      if (zooKeeperWrapper != null) {
-        zooKeeperWrapper.close();
-        zooKeeperWrapper = null;
-      }
+      zooKeeperWrapper = null;
     }
 
     // Used by master and region servers during safe mode only
@@ -349,9 +338,9 @@
 
       MetaScannerVisitor visitor = new MetaScannerVisitor() {
 
-        public boolean processRow(Result result) throws IOException {
+        public boolean processRow(RowResult rowResult) throws IOException {
           HRegionInfo info = Writables.getHRegionInfo(
-              result.getValue(CATALOG_FAMILY, REGIONINFO_QUALIFIER));
+              rowResult.get(COL_REGIONINFO));
 
           // Only examine the rows where the startKey is zero length
           if (info != null && info.getStartKey().length == 0) {
@@ -398,13 +387,12 @@
         HRegionInfo.createRegionName(tableName, null, HConstants.ZEROES);
       byte[] endKey = null;
       HRegionInfo currentRegion = null;
-      Scan scan = new Scan(startKey);
-      scan.addColumn(CATALOG_FAMILY, REGIONINFO_QUALIFIER);
       ScannerCallable s = new ScannerCallable(this, 
           (Bytes.equals(tableName, HConstants.META_TABLE_NAME) ?
               HConstants.ROOT_TABLE_NAME : HConstants.META_TABLE_NAME),
-          scan.getStartRow(),
-           scan);
+          HConstants.COL_REGIONINFO_ARRAY, startKey,
+          HConstants.LATEST_TIMESTAMP, null
+      );
       try {
         // Open scanner
         getRegionServerWithRetries(s);
@@ -414,25 +402,27 @@
             startKey = oldRegion.getEndKey();
           }
           currentRegion = s.getHRegionInfo();
-          Result r = null;
-          Result [] rrs = null;
+          RowResult r = null;
+          RowResult[] rrs = null;
           while ((rrs = getRegionServerWithRetries(s)) != null) {
             r = rrs[0];
-            byte [] value = r.getValue(HConstants.CATALOG_FAMILY, 
-                HConstants.REGIONINFO_QUALIFIER);
-            if (value != null) {
-              HRegionInfo info = Writables.getHRegionInfoOrNull(value);
-              if (info != null) {
-                if (Bytes.equals(info.getTableDesc().getName(), tableName)) {
-                  rowsScanned += 1;
-                  rowsOffline += info.isOffline() ? 1 : 0;
+            Cell c = r.get(HConstants.COL_REGIONINFO);
+            if (c != null) {
+              byte[] value = c.getValue();
+              if (value != null) {
+                HRegionInfo info = Writables.getHRegionInfoOrNull(value);
+                if (info != null) {
+                  if (Bytes.equals(info.getTableDesc().getName(), tableName)) {
+                    rowsScanned += 1;
+                    rowsOffline += info.isOffline() ? 1 : 0;
+                  }
                 }
               }
             }
           }
           endKey = currentRegion.getEndKey();
-        } while (!(endKey == null || 
-            Bytes.equals(endKey, HConstants.EMPTY_BYTE_ARRAY)));
+        } while (!(endKey == null || HStoreKey.equalsTwoRowKeys(endKey,
+            HConstants.EMPTY_BYTE_ARRAY)));
       }
       finally {
         s.setClose();
@@ -450,9 +440,9 @@
         protected HTableDescriptorFinder(byte[] tableName) {
           this.tableName = tableName;
         }
-        public boolean processRow(Result rowResult) throws IOException {
+        public boolean processRow(RowResult rowResult) throws IOException {
           HRegionInfo info = Writables.getHRegionInfo(
-              rowResult.getValue(CATALOG_FAMILY, REGIONINFO_QUALIFIER));
+            rowResult.get(HConstants.COL_REGIONINFO));
           HTableDescriptor desc = info.getTableDesc();
           if (Bytes.compareTo(desc.getName(), tableName) == 0) {
             result = desc;
@@ -554,7 +544,7 @@
       for (int tries = 0; true; tries++) {
         if (tries >= numRetries) {
           throw new NoServerForRegionException("Unable to find region for " 
-            + Bytes.toStringBinary(row) + " after " + numRetries + " tries.");
+            + Bytes.toString(row) + " after " + numRetries + " tries.");
         }
 
         try {
@@ -564,22 +554,21 @@
             getHRegionConnection(metaLocation.getServerAddress());
 
           // Query the root or meta region for the location of the meta region
-          Result regionInfoRow = server.getClosestRowBefore(
+          RowResult regionInfoRow = server.getClosestRowBefore(
             metaLocation.getRegionInfo().getRegionName(), metaKey,
-            HConstants.CATALOG_FAMILY);
+            HConstants.COLUMN_FAMILY);
           if (regionInfoRow == null) {
             throw new TableNotFoundException(Bytes.toString(tableName));
           }
 
-          byte [] value = regionInfoRow.getValue(CATALOG_FAMILY, 
-              REGIONINFO_QUALIFIER);
-          if (value == null || value.length == 0) {
+          Cell value = regionInfoRow.get(COL_REGIONINFO);
+          if (value == null || value.getValue().length == 0) {
             throw new IOException("HRegionInfo was null or empty in " + 
               Bytes.toString(parentTable));
           }
           // convert the row result into the HRegionLocation we need!
           HRegionInfo regionInfo = (HRegionInfo) Writables.getWritable(
-              value, new HRegionInfo());
+              value.getValue(), new HRegionInfo());
           // possible we got a region of a different table...
           if (!Bytes.equals(regionInfo.getTableDesc().getName(), tableName)) {
             throw new TableNotFoundException(
@@ -590,11 +579,8 @@
               regionInfo.getRegionNameAsString());
           }
           
-          value = regionInfoRow.getValue(CATALOG_FAMILY, SERVER_QUALIFIER);
-          String serverAddress = "";
-          if(value != null) {
-            serverAddress = Bytes.toString(value);
-          }
+          String serverAddress = 
+            Writables.cellToString(regionInfoRow.get(COL_SERVER));
           if (serverAddress.equals("")) { 
             throw new NoServerForRegionException("No server address listed " +
               "in " + Bytes.toString(parentTable) + " for region " +
@@ -694,8 +680,8 @@
           // this one. the exception case is when the endkey is EMPTY_START_ROW,
           // signifying that the region we're checking is actually the last
           // region in the table.
-          if (Bytes.equals(endKey, HConstants.EMPTY_END_ROW) ||
-              KeyValue.getRowComparator(tableName).compare(endKey, row) > 0) {
+          if (HStoreKey.equalsTwoRowKeys(endKey, HConstants.EMPTY_END_ROW) ||
+              HStoreKey.getComparator(tableName).compareRows(endKey, row) > 0) {
             return possibleRegion;
           }
         }
@@ -732,7 +718,7 @@
 
           // by nature of the map, we know that the start key has to be < 
           // otherwise it wouldn't be in the headMap. 
-          if (KeyValue.getRowComparator(tableName).compare(endKey, row) <= 0) {
+          if (HStoreKey.getComparator(tableName).compareRows(endKey, row) <= 0) {
             // delete any matching entry
             HRegionLocation rl =
               tableLocations.remove(matchingRegions.lastKey());
@@ -992,15 +978,15 @@
       return location;
     }
 
-    public void processBatchOfRows(ArrayList<Put> list, byte[] tableName)
+    public void processBatchOfRows(ArrayList<BatchUpdate> list, byte[] tableName)
         throws IOException {
       if (list.isEmpty()) {
         return;
       }
       boolean retryOnlyOne = false;
       int tries = 0;
-      Collections.sort(list); 
-      List<Put> currentPuts = new ArrayList<Put>();
+      Collections.sort(list);
+      List<BatchUpdate> tempUpdates = new ArrayList<BatchUpdate>();
       HRegionLocation location =
         getRegionLocationForRowWithRetries(tableName, list.get(0).getRow(),
             false);
@@ -1008,8 +994,8 @@
       byte [] region = currentRegion;
       boolean isLastRow = false;
       for (int i = 0; i < list.size() && tries < numRetries; i++) {
-        Put put = list.get(i);
-        currentPuts.add(put);
+        BatchUpdate batchUpdate = list.get(i);
+        tempUpdates.add(batchUpdate);
         isLastRow = (i + 1) == list.size();
         if (!isLastRow) {
           location = getRegionLocationForRowWithRetries(tableName,
@@ -1017,19 +1003,19 @@
           region = location.getRegionInfo().getRegionName();
         }
         if (!Bytes.equals(currentRegion, region) || isLastRow || retryOnlyOne) {
-          final Put [] puts = currentPuts.toArray(new Put[0]);
+          final BatchUpdate[] updates = tempUpdates.toArray(new BatchUpdate[0]);
           int index = getRegionServerWithRetries(new ServerCallable<Integer>(
-              this, tableName, put.getRow()) {
+              this, tableName, batchUpdate.getRow()) {
             public Integer call() throws IOException {
-              int i = server.put(location.getRegionInfo()
-                  .getRegionName(), puts);
+              int i = server.batchUpdates(location.getRegionInfo()
+                  .getRegionName(), updates);
               return i;
             }
           });
           if (index != -1) {
             if (tries == numRetries - 1) {
               throw new RetriesExhaustedException("Some server",
-                  currentRegion, put.getRow(), 
+                  currentRegion, batchUpdate.getRow(), 
                   tries, new ArrayList<Throwable>());
             }
             long sleepTime = getPauseTime(tries);
@@ -1045,7 +1031,7 @@
             } catch (InterruptedException e) {
               // continue
             }
-            i = i - puts.length + index;
+            i = i - updates.length + index;
             retryOnlyOne = true;
             location = getRegionLocationForRowWithRetries(tableName, 
               list.get(i + 1).getRow(), true);
@@ -1055,7 +1041,7 @@
             retryOnlyOne = false;
           }
           currentRegion = region;
-          currentPuts.clear();
+          tempUpdates.clear();
         }
       }
     }
@@ -1068,7 +1054,6 @@
         master = null;
         masterChecked = false;
       }
-      resetZooKeeper();
       if (stopProxy) {
         synchronized (servers) {
           for (HRegionInterface i: servers.values()) {



Mime
View raw message