You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by jy...@apache.org on 2013/11/17 05:49:30 UTC
svn commit: r1542645 - in
/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client:
Append.java Delete.java Put.java
Author: jyates
Date: Sun Nov 17 04:49:30 2013
New Revision: 1542645
URL: http://svn.apache.org/r1542645
Log:
HBASE-9834: Minimize byte[] copies for 'smart' clients (again)
Modified:
hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Append.java
hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Delete.java
hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Put.java
Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Append.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Append.java?rev=1542645&r1=1542644&r2=1542645&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Append.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Append.java Sun Nov 17 04:49:30 2013
@@ -27,7 +27,6 @@ import java.util.Map;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.io.Writable;
/**
* Performs Append operations on a single row.
@@ -144,10 +143,38 @@ public class Append extends Mutation {
}
out.writeInt(totalLen);
for(KeyValue kv : keys) {
- out.writeInt(kv.getLength());
- out.write(kv.getBuffer(), kv.getOffset(), kv.getLength());
+ kv.write(out);
}
}
writeAttributes(out);
}
-}
+
+ /**
+ * Add the specified {@link KeyValue} to this operation.
+ * @param kv whose value should be to appended to the specified column
+ * @return <tt?this</tt>
+ * @throws IllegalArgumentException if the row or type does not match <tt>this</tt>
+ */
+ public Append add(KeyValue kv) {
+ if(!(kv.getType() == KeyValue.Type.Put.getCode())){
+ throw new IllegalArgumentException("Added type " + KeyValue.Type.codeToType(kv.getType())
+ + ", but appends can only be of type " + KeyValue.Type.Put + ". Rowkey:"
+ + Bytes.toStringBinary(kv.getRow()));
+ }
+
+ if (!kv.matchingRow(row)) {
+ throw new IllegalArgumentException("The row in the recently added KeyValue "
+ + Bytes.toStringBinary(kv.getRow()) + " doesn't match the original one "
+ + Bytes.toStringBinary(this.row));
+ }
+
+ byte[] family = kv.getFamily();
+ List<KeyValue> list = familyMap.get(family);
+ if (list == null) {
+ list = new ArrayList<KeyValue>();
+ familyMap.put(family, list);
+ }
+ list.add(kv);
+ return this;
+ }
+}
\ No newline at end of file
Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Delete.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Delete.java?rev=1542645&r1=1542644&r2=1542645&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Delete.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Delete.java Sun Nov 17 04:49:30 2013
@@ -137,22 +137,19 @@ public class Delete extends Mutation
}
/**
- * Advanced use only.
- * Add an existing delete marker to this Delete object.
- * @param kv An existing KeyValue of type "delete".
+ * Advanced use only. Add an existing delete marker to this Delete object.
+ * @param kv An existing 'delete' tpye KeyValue - can be family, column, or point delete
* @return this for invocation chaining
* @throws IOException
*/
public Delete addDeleteMarker(KeyValue kv) throws IOException {
- if (!kv.isDelete()) {
+ if (!(kv.isDelete() || kv.isDeleteColumnOrFamily())) {
throw new IOException("The recently added KeyValue is not of type "
+ "delete. Rowkey: " + Bytes.toStringBinary(this.row));
}
- if (Bytes.compareTo(this.row, 0, row.length, kv.getBuffer(),
- kv.getRowOffset(), kv.getRowLength()) != 0) {
+ if (!kv.matchingRow(row)) {
throw new IOException("The row in the recently added KeyValue "
- + Bytes.toStringBinary(kv.getBuffer(), kv.getRowOffset(),
- kv.getRowLength()) + " doesn't match the original one "
+ + Bytes.toStringBinary(kv.getRow()) + " doesn't match the original one "
+ Bytes.toStringBinary(this.row));
}
byte [] family = kv.getFamily();
@@ -299,9 +296,9 @@ public class Delete extends Mutation
int numColumns = in.readInt();
List<KeyValue> list = new ArrayList<KeyValue>(numColumns);
for(int j=0;j<numColumns;j++) {
- KeyValue kv = new KeyValue();
- kv.readFields(in);
- list.add(kv);
+ KeyValue kv = new KeyValue();
+ kv.readFields(in);
+ list.add(kv);
}
this.familyMap.put(family, list);
}
Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Put.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Put.java?rev=1542645&r1=1542644&r2=1542645&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Put.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Put.java Sun Nov 17 04:49:30 2013
@@ -157,13 +157,10 @@ public class Put extends Mutation
byte [] family = kv.getFamily();
List<KeyValue> list = getKeyValueList(family);
//Checking that the row of the kv is the same as the put
- int res = Bytes.compareTo(this.row, 0, row.length,
- kv.getBuffer(), kv.getRowOffset(), kv.getRowLength());
- if(res != 0) {
- throw new IOException("The row in the recently added KeyValue " +
- Bytes.toStringBinary(kv.getBuffer(), kv.getRowOffset(),
- kv.getRowLength()) + " doesn't match the original one " +
- Bytes.toStringBinary(this.row));
+ if (!kv.matchingRow(row)) {
+ throw new IOException("The row in the recently added KeyValue "
+ + Bytes.toStringBinary(kv.getRow()) + " doesn't match the original one "
+ + Bytes.toStringBinary(this.row));
}
list.add(kv);
familyMap.put(family, list);
@@ -415,8 +412,7 @@ public class Put extends Mutation
}
out.writeInt(totalLen);
for(KeyValue kv : keys) {
- out.writeInt(kv.getLength());
- out.write(kv.getBuffer(), kv.getOffset(), kv.getLength());
+ kv.write(out);
}
}
writeAttributes(out);