HBASE-18344 Introduce Append.addColumn as a replacement for Append.add

Signed-off-by: Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
Jan Hentschel 2017-07-09 12:11:31 +02:00 committed by Chia-Ping Tsai
parent 9daac09f6e
commit 97b649eb93
26 changed files with 70 additions and 56 deletions

View File

@ -41,7 +41,7 @@ import org.apache.hadoop.hbase.util.Bytes;
* <p>
* To append to a set of columns of a row, instantiate an Append object with the
* row to append to. At least one column to append must be specified using the
* {@link #add(byte[], byte[], byte[])} method.
* {@link #addColumn(byte[], byte[], byte[])} method.
*/
@InterfaceAudience.Public
public class Append extends Mutation {
@ -104,8 +104,22 @@ public class Append extends Mutation {
* @param qualifier column qualifier
* @param value value to append to specified column
* @return this
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
* Use {@link #addColumn(byte[], byte[], byte[])} instead
*/
@Deprecated
public Append add(byte [] family, byte [] qualifier, byte [] value) {
return this.addColumn(family, qualifier, value);
}
/**
* Add the specified column and value to this Append operation.
* @param family family name
* @param qualifier column qualifier
* @param value value to append to specified column
* @return this
*/
public Append addColumn(byte[] family, byte[] qualifier, byte[] value) {
KeyValue kv = new KeyValue(this.row, family, qualifier, this.ts, KeyValue.Type.Put, value);
return add(kv);
}

View File

@ -163,7 +163,7 @@ public class TestRpcControllerFactory {
counter = verifyCount(counter);
Append append = new Append(row);
append.add(fam1, fam1, Bytes.toBytes("val2"));
append.addColumn(fam1, fam1, Bytes.toBytes("val2"));
table.append(append);
counter = verifyCount(counter);

View File

@ -1558,7 +1558,7 @@ public class PerformanceEvaluation extends Configured implements Tool {
void testRow(final int i) throws IOException {
byte [] bytes = format(i);
Append append = new Append(bytes);
append.add(FAMILY_NAME, getQualifier(), bytes);
append.addColumn(FAMILY_NAME, getQualifier(), bytes);
updateValueSize(this.table.append(append));
}
}

View File

@ -199,7 +199,7 @@ public class TestAsyncTable {
char suffix = ':';
AtomicLong suffixCount = new AtomicLong(0L);
IntStream.range(0, count).forEachOrdered(
i -> table.append(new Append(row).add(FAMILY, QUALIFIER, Bytes.toBytes("" + i + suffix)))
i -> table.append(new Append(row).addColumn(FAMILY, QUALIFIER, Bytes.toBytes("" + i + suffix)))
.thenAccept(r -> {
suffixCount.addAndGet(Bytes.toString(r.getValue(FAMILY, QUALIFIER)).chars()
.filter(x -> x == suffix).count());

View File

@ -186,7 +186,7 @@ public class TestAsyncTableBatch {
actions.add(new Put(Bytes.toBytes(1)).addColumn(FAMILY, CQ, Bytes.toBytes((long) 2)));
actions.add(new Delete(Bytes.toBytes(2)));
actions.add(new Increment(Bytes.toBytes(3)).addColumn(FAMILY, CQ, 1));
actions.add(new Append(Bytes.toBytes(4)).add(FAMILY, CQ, Bytes.toBytes(4)));
actions.add(new Append(Bytes.toBytes(4)).addColumn(FAMILY, CQ, Bytes.toBytes(4)));
List<Object> results = table.batchAll(actions).get();
assertEquals(5, results.size());
Result getResult = (Result) results.get(0);

View File

@ -103,9 +103,9 @@ public class TestAsyncTableNoncedRetry {
@Test
public void testAppend() throws InterruptedException, ExecutionException {
RawAsyncTable table = ASYNC_CONN.getRawTable(TABLE_NAME);
Result result = table.append(new Append(row).add(FAMILY, QUALIFIER, VALUE)).get();
Result result = table.append(new Append(row).addColumn(FAMILY, QUALIFIER, VALUE)).get();
assertArrayEquals(VALUE, result.getValue(FAMILY, QUALIFIER));
result = table.append(new Append(row).add(FAMILY, QUALIFIER, VALUE)).get();
result = table.append(new Append(row).addColumn(FAMILY, QUALIFIER, VALUE)).get();
// the second call should have no effect as we always generate the same nonce.
assertArrayEquals(VALUE, result.getValue(FAMILY, QUALIFIER));
result = table.get(new Get(row)).get();

View File

@ -209,7 +209,7 @@ public class TestFromClientSide {
try {
Append append = new Append(ROW);
append.add(TEST_UTIL.fam1, QUALIFIER, VALUE);
append.addColumn(TEST_UTIL.fam1, QUALIFIER, VALUE);
Result result = table.append(append);
// Verify expected result
@ -1463,7 +1463,7 @@ public class TestFromClientSide {
table.delete(delete);
Append append = new Append(ROW);
append.add(FAMILY, null, VALUE);
append.addColumn(FAMILY, null, VALUE);
table.append(append);
getTestNull(table, ROW, FAMILY, VALUE);
@ -4625,10 +4625,10 @@ public class TestFromClientSide {
Table table = TEST_UTIL.createTable(tableName, FAMILY);
Append append1 = new Append(Bytes.toBytes("row1"));
append1.setReturnResults(false);
append1.add(FAMILY, Bytes.toBytes("f1"), Bytes.toBytes("value1"));
append1.addColumn(FAMILY, Bytes.toBytes("f1"), Bytes.toBytes("value1"));
Append append2 = new Append(Bytes.toBytes("row1"));
append2.setReturnResults(false);
append2.add(FAMILY, Bytes.toBytes("f1"), Bytes.toBytes("value2"));
append2.addColumn(FAMILY, Bytes.toBytes("f1"), Bytes.toBytes("value2"));
List<Append> appends = new ArrayList<>();
appends.add(append1);
appends.add(append2);
@ -4653,15 +4653,15 @@ public class TestFromClientSide {
Bytes.toBytes("b"), Bytes.toBytes("a"), Bytes.toBytes("c")
};
Append a = new Append(ROW);
a.add(FAMILY, QUALIFIERS[0], v1);
a.add(FAMILY, QUALIFIERS[1], v2);
a.addColumn(FAMILY, QUALIFIERS[0], v1);
a.addColumn(FAMILY, QUALIFIERS[1], v2);
a.setReturnResults(false);
assertEmptyResult(t.append(a));
a = new Append(ROW);
a.add(FAMILY, QUALIFIERS[0], v2);
a.add(FAMILY, QUALIFIERS[1], v1);
a.add(FAMILY, QUALIFIERS[2], v2);
a.addColumn(FAMILY, QUALIFIERS[0], v2);
a.addColumn(FAMILY, QUALIFIERS[1], v1);
a.addColumn(FAMILY, QUALIFIERS[2], v2);
Result r = t.append(a);
assertEquals(0, Bytes.compareTo(Bytes.add(v1, v2), r.getValue(FAMILY, QUALIFIERS[0])));
assertEquals(0, Bytes.compareTo(Bytes.add(v2, v1), r.getValue(FAMILY, QUALIFIERS[1])));
@ -4683,16 +4683,16 @@ public class TestFromClientSide {
Put put_1 = new Put(row3);
put_1.addColumn(FAMILY, qual, Bytes.toBytes("put"));
Append append_0 = new Append(row1);
append_0.add(FAMILY, qual, Bytes.toBytes("i"));
append_0.addColumn(FAMILY, qual, Bytes.toBytes("i"));
Append append_1 = new Append(row1);
append_1.add(FAMILY, qual, Bytes.toBytes("k"));
append_1.addColumn(FAMILY, qual, Bytes.toBytes("k"));
Append append_2 = new Append(row1);
append_2.add(FAMILY, qual, Bytes.toBytes("e"));
append_2.addColumn(FAMILY, qual, Bytes.toBytes("e"));
if (!walUsed) {
append_2.setDurability(Durability.SKIP_WAL);
}
Append append_3 = new Append(row1);
append_3.add(FAMILY, qual, Bytes.toBytes("a"));
append_3.addColumn(FAMILY, qual, Bytes.toBytes("a"));
Scan s = new Scan();
s.setCaching(1);
t.append(append_0);
@ -6416,7 +6416,7 @@ public class TestFromClientSide {
// expected
}
try {
t.append(new Append(ROW).add(FAMILY, QUALIFIER, new byte[10 * 1024]));
t.append(new Append(ROW).addColumn(FAMILY, QUALIFIER, new byte[10 * 1024]));
fail("Oversize cell failed to trigger exception");
} catch (IOException e) {
// expected

View File

@ -597,7 +597,7 @@ public class TestFromClientSide3 {
ExecutorService appendService = Executors.newSingleThreadExecutor();
appendService.execute(() -> {
Append append = new Append(ROW);
append.add(FAMILY, QUALIFIER, VALUE);
append.addColumn(FAMILY, QUALIFIER, VALUE);
try (Table table = con.getTable(tableName)) {
table.append(append);
fail("The APPEND should fail because the target lock is blocked by previous put");

View File

@ -103,7 +103,7 @@ public class TestMetaCache {
put.addColumn(FAMILY, QUALIFIER, Bytes.toBytes(10));
Get get = new Get(row);
Append append = new Append(row);
append.add(FAMILY, QUALIFIER, Bytes.toBytes(11));
append.addColumn(FAMILY, QUALIFIER, Bytes.toBytes(11));
Increment increment = new Increment(row);
increment.addColumn(FAMILY, QUALIFIER, 10);
Delete delete = new Delete(row);

View File

@ -476,8 +476,8 @@ public class TestMultiParallel {
inc.addColumn(BYTES_FAMILY, QUAL3, 1);
Append a = new Append(ONE_ROW);
a.add(BYTES_FAMILY, QUAL1, Bytes.toBytes("def"));
a.add(BYTES_FAMILY, QUAL4, Bytes.toBytes("xyz"));
a.addColumn(BYTES_FAMILY, QUAL1, Bytes.toBytes("def"));
a.addColumn(BYTES_FAMILY, QUAL4, Bytes.toBytes("xyz"));
List<Row> actions = new ArrayList<>();
actions.add(inc);
actions.add(a);

View File

@ -100,7 +100,7 @@ public class TestPutDeleteEtcCellIteration {
Append a = new Append(ROW);
for (int i = 0; i < COUNT; i++) {
byte [] bytes = Bytes.toBytes(i);
a.add(bytes, bytes, bytes);
a.addColumn(bytes, bytes, bytes);
}
int index = 0;
for (CellScanner cellScanner = a.cellScanner(); cellScanner.advance();) {

View File

@ -74,7 +74,7 @@ public class TestResultFromCoprocessor {
t.put(put);
assertRowAndValue(t.get(new Get(ROW)), ROW, VALUE);
Append append = new Append(ROW);
append.add(FAMILY, QUAL, FIXED_VALUE);
append.addColumn(FAMILY, QUAL, FIXED_VALUE);
assertRowAndValue(t.append(append), ROW, FIXED_VALUE);
assertRowAndValue(t.get(new Get(ROW)), ROW, Bytes.add(VALUE, FIXED_VALUE));
}

View File

@ -196,7 +196,7 @@ public class TestHTableWrapper {
private void checkAppend() throws IOException {
final byte[] appendValue = Bytes.toBytes("append");
Append append = new Append(qualifierCol1).add(TEST_FAMILY, qualifierCol1, appendValue);
Append append = new Append(qualifierCol1).addColumn(TEST_FAMILY, qualifierCol1, appendValue);
Result appendResult = hTableInterface.append(append);
byte[] appendedRow = appendResult.getRow();
checkRowValue(appendedRow, appendValue);

View File

@ -286,7 +286,7 @@ public class TestRegionObserverInterface {
Table table = util.createTable(tableName, new byte[][] { A, B, C });
try {
Append app = new Append(Bytes.toBytes(0));
app.add(A, A, A);
app.addColumn(A, A, A);
verifyMethodResult(SimpleRegionObserver.class,
new String[] { "hadPreAppend", "hadPostAppend", "hadPreAppendAfterRowLock" }, tableName,

View File

@ -132,7 +132,7 @@ public class TestSpaceQuotas {
@Test
public void testNoInsertsWithAppend() throws Exception {
Append a = new Append(Bytes.toBytes("to_reject"));
a.add(
a.addColumn(
Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("to"), Bytes.toBytes("reject"));
writeUntilViolationAndVerifyViolation(SpaceViolationPolicy.NO_INSERTS, a);
}
@ -168,7 +168,7 @@ public class TestSpaceQuotas {
@Test
public void testNoWritesWithAppend() throws Exception {
Append a = new Append(Bytes.toBytes("to_reject"));
a.add(
a.addColumn(
Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("to"), Bytes.toBytes("reject"));
writeUntilViolationAndVerifyViolation(SpaceViolationPolicy.NO_WRITES, a);
}

View File

@ -131,12 +131,12 @@ public class TestAtomicOperation {
String v2 = " is... 42.";
Append a = new Append(row);
a.setReturnResults(false);
a.add(fam1, qual1, Bytes.toBytes(v1));
a.add(fam1, qual2, Bytes.toBytes(v2));
a.addColumn(fam1, qual1, Bytes.toBytes(v1));
a.addColumn(fam1, qual2, Bytes.toBytes(v2));
assertTrue(region.append(a, HConstants.NO_NONCE, HConstants.NO_NONCE).isEmpty());
a = new Append(row);
a.add(fam1, qual1, Bytes.toBytes(v2));
a.add(fam1, qual2, Bytes.toBytes(v1));
a.addColumn(fam1, qual1, Bytes.toBytes(v2));
a.addColumn(fam1, qual2, Bytes.toBytes(v1));
Result result = region.append(a, HConstants.NO_NONCE, HConstants.NO_NONCE);
assertEquals(0, Bytes.compareTo(Bytes.toBytes(v1+v2), result.getValue(fam1, qual1)));
assertEquals(0, Bytes.compareTo(Bytes.toBytes(v2+v1), result.getValue(fam1, qual2)));
@ -147,8 +147,8 @@ public class TestAtomicOperation {
initHRegion(tableName, name.getMethodName(), fam1);
final String v1 = "Value";
final Append a = new Append(row);
a.add(fam1, qual1, Bytes.toBytes(v1));
a.add(fam2, qual2, Bytes.toBytes(v1));
a.addColumn(fam1, qual1, Bytes.toBytes(v1));
a.addColumn(fam2, qual2, Bytes.toBytes(v1));
Result result = null;
try {
result = region.append(a, HConstants.NO_NONCE, HConstants.NO_NONCE);
@ -327,9 +327,9 @@ public class TestAtomicOperation {
for (int i=0; i<numOps; i++) {
try {
Append a = new Append(row);
a.add(fam1, qual1, val);
a.add(fam1, qual2, val);
a.add(fam2, qual3, val);
a.addColumn(fam1, qual1, val);
a.addColumn(fam1, qual2, val);
a.addColumn(fam2, qual3, val);
a.setDurability(Durability.ASYNC_WAL);
region.append(a, HConstants.NO_NONCE, HConstants.NO_NONCE);

View File

@ -1387,7 +1387,7 @@ public class TestHRegion {
boolean exceptionCaught = false;
Append append = new Append(Bytes.toBytes("somerow"));
append.setDurability(Durability.SKIP_WAL);
append.add(Bytes.toBytes("somefamily"), Bytes.toBytes("somequalifier"),
append.addColumn(Bytes.toBytes("somefamily"), Bytes.toBytes("somequalifier"),
Bytes.toBytes("somevalue"));
try {
region.append(append);
@ -4364,7 +4364,7 @@ public class TestHRegion {
int count = 0;
while (count < appendCounter) {
Append app = new Append(appendRow);
app.add(family, qualifier, CHAR);
app.addColumn(family, qualifier, CHAR);
count++;
try {
region.append(app);
@ -6167,7 +6167,7 @@ public class TestHRegion {
edge.setValue(10);
Append a = new Append(row);
a.setDurability(Durability.SKIP_WAL);
a.add(fam1, qual1, qual1);
a.addColumn(fam1, qual1, qual1);
region.append(a);
Result result = region.get(new Get(row));

View File

@ -365,7 +365,7 @@ public class TestRegionServerMetrics {
for(int count = 0; count< 73; count++) {
Append append = new Append(row);
append.add(cf, qualifier, Bytes.toBytes(",Test"));
append.addColumn(cf, qualifier, Bytes.toBytes(",Test"));
table.append(append);
}

View File

@ -284,7 +284,7 @@ public class TestRegionServerReadRequestMetrics {
// test for append
append = new Append(ROW1);
append.add(CF1, COL2, VAL2);
append.addColumn(CF1, COL2, VAL2);
result = table.append(append);
resultCount = result.isEmpty() ? 0 : 1;
testReadRequests(resultCount, 1, 0);

View File

@ -456,7 +456,7 @@ public class TestTags {
put.setAttribute("visibility", Bytes.toBytes("tag1"));
table.put(put);
Append append = new Append(row3);
append.add(f, q, Bytes.toBytes("b"));
append.addColumn(f, q, Bytes.toBytes("b"));
table.append(append);
TestCoprocessorForTags.checkTagPresence = true;
scanner = table.getScanner(new Scan().setStartRow(row3));

View File

@ -1163,7 +1163,7 @@ public class TestAccessController extends SecureTestUtil {
Put put = new Put(row);
put.addColumn(TEST_FAMILY, qualifier, Bytes.toBytes(1));
Append append = new Append(row);
append.add(TEST_FAMILY, qualifier, Bytes.toBytes(2));
append.addColumn(TEST_FAMILY, qualifier, Bytes.toBytes(2));
try(Connection conn = ConnectionFactory.createConnection(conf);
Table t = conn.getTable(TEST_TABLE)) {
t.put(put);

View File

@ -636,12 +636,12 @@ public abstract class TestVisibilityLabels {
Result result = table.get(get);
assertTrue(result.isEmpty());
Append append = new Append(row1);
append.add(fam, qual, Bytes.toBytes("b"));
append.addColumn(fam, qual, Bytes.toBytes("b"));
table.append(append);
result = table.get(get);
assertTrue(result.isEmpty());
append = new Append(row1);
append.add(fam, qual, Bytes.toBytes("c"));
append.addColumn(fam, qual, Bytes.toBytes("c"));
append.setCellVisibility(new CellVisibility(SECRET));
table.append(append);
result = table.get(get);

View File

@ -191,7 +191,7 @@ public class TestVisibilityWithCheckAuths {
try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Append append = new Append(row1);
append.add(fam, qual, Bytes.toBytes("b"));
append.addColumn(fam, qual, Bytes.toBytes("b"));
table.append(append);
}
return null;
@ -204,7 +204,7 @@ public class TestVisibilityWithCheckAuths {
try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Append append = new Append(row1);
append.add(fam, qual, Bytes.toBytes("c"));
append.addColumn(fam, qual, Bytes.toBytes("c"));
append.setCellVisibility(new CellVisibility(PUBLIC));
table.append(append);
Assert.fail("Testcase should fail with AccesDeniedException");

View File

@ -151,7 +151,7 @@ public class MultiThreadedUpdater extends MultiThreadedWriterBase {
buf.setLength(0); // Clear the buffer
buf.append("#").append(Bytes.toString(INCREMENT));
buf.append(":").append(MutationType.INCREMENT.getNumber());
app.add(cf, MUTATE_INFO, Bytes.toBytes(buf.toString()));
app.addColumn(cf, MUTATE_INFO, Bytes.toBytes(buf.toString()));
++columnCount;
if (!isBatchUpdate) {
mutate(table, inc, rowKeyBase);
@ -220,9 +220,9 @@ public class MultiThreadedUpdater extends MultiThreadedWriterBase {
break;
default:
buf.append(MutationType.APPEND.getNumber());
app.add(cf, column, hashCodeBytes);
app.addColumn(cf, column, hashCodeBytes);
}
app.add(cf, MUTATE_INFO, Bytes.toBytes(buf.toString()));
app.addColumn(cf, MUTATE_INFO, Bytes.toBytes(buf.toString()));
if (!isBatchUpdate) {
mutate(table, app, rowKeyBase);
numCols.addAndGet(1);

View File

@ -228,7 +228,7 @@ public class ThriftUtilities {
for (int i = 0; i < length; i++) {
byte[][] famAndQf = KeyValue.parseColumn(getBytes(columns.get(i)));
append.add(famAndQf[0], famAndQf[1], getBytes(values.get(i)));
append.addColumn(famAndQf[0], famAndQf[1], getBytes(values.get(i)));
}
return append;
}

View File

@ -482,7 +482,7 @@ public class ThriftUtilities {
public static Append appendFromThrift(TAppend append) throws IOException {
Append out = new Append(append.getRow());
for (TColumnValue column : append.getColumns()) {
out.add(column.getFamily(), column.getQualifier(), column.getValue());
out.addColumn(column.getFamily(), column.getQualifier(), column.getValue());
}
if (append.isSetAttributes()) {