diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/client/Append.java hbase-client/src/main/java/org/apache/hadoop/hbase/client/Append.java index 45f1e46..9bb217d 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/client/Append.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/client/Append.java @@ -117,13 +117,12 @@ public class Append extends Mutation { * @param cell * @return This instance */ - @SuppressWarnings("unchecked") public Append add(final Cell cell) { // Presume it is KeyValue for now. byte [] family = CellUtil.cloneFamily(cell); List list = this.familyMap.get(family); if (list == null) { - list = new ArrayList(); + list = new ArrayList(maxCellsPerColumnFamily); } // find where the new entry should be placed in the List list.add(cell); diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/client/Delete.java hbase-client/src/main/java/org/apache/hadoop/hbase/client/Delete.java index 1e4f79f..47a7ff9 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/client/Delete.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/client/Delete.java @@ -171,7 +171,7 @@ public class Delete extends Mutation implements Comparable { byte [] family = CellUtil.cloneFamily(kv); List list = familyMap.get(family); if (list == null) { - list = new ArrayList(); + list = new ArrayList(maxCellsPerColumnFamily); } list.add(kv); familyMap.put(family, list); @@ -208,7 +208,7 @@ public class Delete extends Mutation implements Comparable { } List list = familyMap.get(family); if(list == null) { - list = new ArrayList(); + list = new ArrayList(maxCellsPerColumnFamily); } else if(!list.isEmpty()) { list.clear(); } @@ -228,7 +228,7 @@ public class Delete extends Mutation implements Comparable { public Delete addFamilyVersion(final byte [] family, final long timestamp) { List list = familyMap.get(family); if(list == null) { - list = new ArrayList(); + list = new ArrayList(maxCellsPerColumnFamily); } list.add(new KeyValue(row, family, null, timestamp, KeyValue.Type.DeleteFamilyVersion)); @@ -261,7 +261,7 @@ public class Delete extends Mutation implements Comparable { } List list = familyMap.get(family); if (list == null) { - list = new ArrayList(); + list = new ArrayList(maxCellsPerColumnFamily); } list.add(new KeyValue(this.row, family, qualifier, timestamp, KeyValue.Type.DeleteColumn)); @@ -296,7 +296,7 @@ public class Delete extends Mutation implements Comparable { } List list = familyMap.get(family); if(list == null) { - list = new ArrayList(); + list = new ArrayList(maxCellsPerColumnFamily); } KeyValue kv = new KeyValue(this.row, family, qualifier, timestamp, KeyValue.Type.Delete); list.add(kv); diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/client/Durability.java hbase-client/src/main/java/org/apache/hadoop/hbase/client/Durability.java index 9b35e04..44f0eba 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/client/Durability.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/client/Durability.java @@ -55,5 +55,16 @@ public enum Durability { * (Note: this is currently not supported and will behave identical to {@link #SYNC_WAL}) * See HADOOP-6313 */ - FSYNC_WAL + FSYNC_WAL; + + public static Durability valueOf(int ordinal) { + switch(ordinal){ + case 0: return USE_DEFAULT; + case 1: return SKIP_WAL; + case 2: return ASYNC_WAL; + case 3: return SYNC_WAL; + case 4: return FSYNC_WAL; + default: return null; + } + } } diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/client/Mutation.java hbase-client/src/main/java/org/apache/hadoop/hbase/client/Mutation.java index 06e0224..7932a38 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/client/Mutation.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/client/Mutation.java @@ -82,11 +82,30 @@ public abstract class Mutation extends OperationWithAttributes implements Row, C */ private static final String OP_ATTRIBUTE_TTL = "_ttl"; - private static final String RETURN_RESULTS = "_rr_"; - + private static final String RETURN_RESULTS = "_rr_"; protected byte [] row = null; protected long ts = HConstants.LATEST_TIMESTAMP; - protected Durability durability = Durability.USE_DEFAULT; + /** + * Removed reference to enum (8 bytes) and replaced it with + * enum ordinal (int) + */ + protected int durability = Durability.USE_DEFAULT.ordinal(); + /** + * Hint: maximum cells per column family allows to save + * some bytes, when it is less than 10 (default for ArrayList), + * or avoid ArrayList resize when it is larger than 10. + * One MUST set this value before adding cells to mutation. + */ + protected int maxCellsPerColumnFamily = 10; + + public int getMaxCellsPerColumnFamily() { + return maxCellsPerColumnFamily; + } + + public void setMaxCellsPerColumnFamily(int maxCellsPerColumnFamily) { + if(maxCellsPerColumnFamily <= 0) return; + this.maxCellsPerColumnFamily = maxCellsPerColumnFamily; + } // A Map sorted by column family. protected NavigableMap> familyMap = @@ -107,7 +126,7 @@ public abstract class Mutation extends OperationWithAttributes implements Row, C List getCellList(byte[] family) { List list = this.familyMap.get(family); if (list == null) { - list = new ArrayList(); + list = new ArrayList(maxCellsPerColumnFamily); } return list; } @@ -238,13 +257,13 @@ public abstract class Mutation extends OperationWithAttributes implements Row, C * @param d */ public Mutation setDurability(Durability d) { - this.durability = d; + this.durability = d.ordinal(); return this; } /** Get the current durability */ public Durability getDurability() { - return this.durability; + return Durability.valueOf(this.durability); } /**