diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/client/RowMutations.java hbase-client/src/main/java/org/apache/hadoop/hbase/client/RowMutations.java index 888306d..8a8193e 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/client/RowMutations.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/client/RowMutations.java @@ -40,19 +40,25 @@ import org.apache.hadoop.hbase.util.Bytes; @InterfaceAudience.Public @InterfaceStability.Evolving public class RowMutations implements Row { - private final List mutations = new ArrayList(); - private byte [] row; - - /** Constructor for Writable. DO NOT USE */ - public RowMutations() {} + private final List mutations; + private final byte [] row; + public RowMutations(byte [] row) { + this(row, -1); + } /** * Create an atomic mutation for the specified row. * @param row row key + * @param initialCapacity the initial capacity of the RowMutations */ - public RowMutations(byte [] row) { + public RowMutations(byte [] row, int initialCapacity) { Mutation.checkRow(row); this.row = Bytes.copy(row); + if (initialCapacity <= 0) { + this.mutations = new ArrayList<>(); + } else { + this.mutations = new ArrayList<>(initialCapacity); + } } /** diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java index 5f49897..9f13939 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java @@ -521,7 +521,7 @@ public class RSRpcServices implements HBaseRPCErrorHandler, } MutationType type = action.getMutation().getMutateType(); if (rm == null) { - rm = new RowMutations(action.getMutation().getRow().toByteArray()); + rm = new RowMutations(action.getMutation().getRow().toByteArray(), actions.size()); } switch (type) { case PUT: @@ -573,7 +573,7 @@ public class RSRpcServices implements HBaseRPCErrorHandler, } MutationType type = action.getMutation().getMutateType(); if (rm == null) { - rm = new RowMutations(action.getMutation().getRow().toByteArray()); + rm = new RowMutations(action.getMutation().getRow().toByteArray(), actions.size()); } switch (type) { case PUT: diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCheckAndMutate.java hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCheckAndMutate.java index 1234194..b32de45 100644 --- hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCheckAndMutate.java +++ hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCheckAndMutate.java @@ -77,7 +77,7 @@ public class TestCheckAndMutate { Bytes.toString(result.getValue(family, Bytes.toBytes("C"))).equals("c")); // put the same row again with C column deleted - RowMutations rm = new RowMutations(rowKey); + RowMutations rm = new RowMutations(rowKey, 2); put = new Put(rowKey); put.addColumn(family, Bytes.toBytes("A"), Bytes.toBytes("a")); put.addColumn(family, Bytes.toBytes("B"), Bytes.toBytes("b")); diff --git hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftUtilities.java hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftUtilities.java index 94bdbb5..807af76 100644 --- hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftUtilities.java +++ hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftUtilities.java @@ -367,8 +367,8 @@ public class ThriftUtilities { * @return converted RowMutations */ public static RowMutations rowMutationsFromThrift(TRowMutations in) throws IOException { - RowMutations out = new RowMutations(in.getRow()); List mutations = in.getMutations(); + RowMutations out = new RowMutations(in.getRow(), mutations.size()); for (TMutation mutation : mutations) { if (mutation.isSetPut()) { out.add(putFromThrift(mutation.getPut()));