HBASE-17013 Add constructor to RowMutations for initializing the capacity of internal list. (ChiaPing Tsai)

This commit is contained in:
anoopsamjohn 2016-11-04 10:34:20 +05:30
parent bb0fc6b602
commit 05ee54f665
4 changed files with 16 additions and 10 deletions

View File

@ -40,19 +40,25 @@ import org.apache.hadoop.hbase.util.Bytes;
@InterfaceAudience.Public
@InterfaceStability.Evolving
public class RowMutations implements Row {
private final List<Mutation> mutations = new ArrayList<Mutation>();
private byte [] row;
/** Constructor for Writable. DO NOT USE */
public RowMutations() {}
private final List<Mutation> 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);
}
}
/**

View File

@ -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:

View File

@ -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"));

View File

@ -367,8 +367,8 @@ public class ThriftUtilities {
* @return converted <code>RowMutations</code>
*/
public static RowMutations rowMutationsFromThrift(TRowMutations in) throws IOException {
RowMutations out = new RowMutations(in.getRow());
List<TMutation> mutations = in.getMutations();
RowMutations out = new RowMutations(in.getRow(), mutations.size());
for (TMutation mutation : mutations) {
if (mutation.isSetPut()) {
out.add(putFromThrift(mutation.getPut()));