use of org.apache.hadoop.hbase.client.RowMutations in project hbase by apache.
the class TestMutateRowsRecovery method MutateRowsAndCheckPostKill.
@Test
public void MutateRowsAndCheckPostKill() throws IOException, InterruptedException {
final TableName tableName = TableName.valueOf("test");
Admin admin = null;
Table hTable = null;
try {
admin = connection.getAdmin();
hTable = connection.getTable(tableName);
HTableDescriptor desc = new HTableDescriptor(tableName);
desc.addFamily(new HColumnDescriptor(fam1));
admin.createTable(desc);
// Add a multi
RowMutations rm = new RowMutations(row1);
Put p1 = new Put(row1);
p1.addColumn(fam1, qual1, value1);
p1.setDurability(Durability.SYNC_WAL);
rm.add(p1);
hTable.mutateRow(rm);
// Add a put
Put p2 = new Put(row1);
p2.addColumn(fam1, qual2, value2);
p2.setDurability(Durability.SYNC_WAL);
hTable.put(p2);
HRegionServer rs1 = TESTING_UTIL.getRSForFirstRegionInTable(tableName);
long now = EnvironmentEdgeManager.currentTime();
// Send the RS Load to ensure correct lastflushedseqid for stores
rs1.tryRegionServerReport(now - 30000, now);
// Kill the RS to trigger wal replay
cluster.killRegionServer(rs1.serverName);
// Ensure correct data exists
Get g1 = new Get(row1);
Result result = hTable.get(g1);
assertTrue(result.getValue(fam1, qual1) != null);
assertEquals(0, Bytes.compareTo(result.getValue(fam1, qual1), value1));
assertTrue(result.getValue(fam1, qual2) != null);
assertEquals(0, Bytes.compareTo(result.getValue(fam1, qual2), value2));
} finally {
if (admin != null) {
admin.close();
}
if (hTable != null) {
hTable.close();
}
}
}
use of org.apache.hadoop.hbase.client.RowMutations in project hbase by apache.
the class TestRegionServerReadRequestMetrics method testReadRequestsCountNotFiltered.
@Test
public void testReadRequestsCountNotFiltered() throws Exception {
int resultCount;
Scan scan;
Append append;
Put put;
Increment increment;
Get get;
// test for scan
scan = new Scan();
try (ResultScanner scanner = table.getScanner(scan)) {
resultCount = 0;
for (Result ignore : scanner) {
resultCount++;
}
testReadRequests(resultCount, 3, 0);
}
// test for scan
scan = new Scan(ROW2, ROW3);
try (ResultScanner scanner = table.getScanner(scan)) {
resultCount = 0;
for (Result ignore : scanner) {
resultCount++;
}
testReadRequests(resultCount, 1, 0);
}
// test for get
get = new Get(ROW2);
Result result = table.get(get);
resultCount = result.isEmpty() ? 0 : 1;
testReadRequests(resultCount, 1, 0);
// test for increment
increment = new Increment(ROW1);
increment.addColumn(CF1, COL3, 1);
result = table.increment(increment);
resultCount = result.isEmpty() ? 0 : 1;
testReadRequests(resultCount, 1, 0);
// test for checkAndPut
put = new Put(ROW1);
put.addColumn(CF1, COL2, VAL2);
boolean checkAndPut = table.checkAndPut(ROW1, CF1, COL2, CompareFilter.CompareOp.EQUAL, VAL2, put);
resultCount = checkAndPut ? 1 : 0;
testReadRequests(resultCount, 1, 0);
// test for append
append = new Append(ROW1);
append.add(CF1, COL2, VAL2);
result = table.append(append);
resultCount = result.isEmpty() ? 0 : 1;
testReadRequests(resultCount, 1, 0);
// test for checkAndMutate
put = new Put(ROW1);
put.addColumn(CF1, COL1, VAL1);
RowMutations rm = new RowMutations(ROW1);
rm.add(put);
boolean checkAndMutate = table.checkAndMutate(ROW1, CF1, COL1, CompareFilter.CompareOp.EQUAL, VAL1, rm);
resultCount = checkAndMutate ? 1 : 0;
testReadRequests(resultCount, 1, 0);
}
use of org.apache.hadoop.hbase.client.RowMutations in project hbase by apache.
the class TestAtomicOperation method testRowMutationMultiThreads.
/**
* Test multi-threaded row mutations.
*/
@Test
public void testRowMutationMultiThreads() throws IOException {
LOG.info("Starting test testRowMutationMultiThreads");
initHRegion(tableName, name.getMethodName(), fam1);
// create 10 threads, each will alternate between adding and
// removing a column
int numThreads = 10;
int opsPerThread = 250;
AtomicOperation[] all = new AtomicOperation[numThreads];
AtomicLong timeStamps = new AtomicLong(0);
AtomicInteger failures = new AtomicInteger(0);
// create all threads
for (int i = 0; i < numThreads; i++) {
all[i] = new AtomicOperation(region, opsPerThread, timeStamps, failures) {
@Override
public void run() {
boolean op = true;
for (int i = 0; i < numOps; i++) {
try {
// throw in some flushes
if (i % 10 == 0) {
synchronized (region) {
LOG.debug("flushing");
region.flush(true);
if (i % 100 == 0) {
region.compact(false);
}
}
}
long ts = timeStamps.incrementAndGet();
RowMutations rm = new RowMutations(row);
if (op) {
Put p = new Put(row, ts);
p.addColumn(fam1, qual1, value1);
p.setDurability(Durability.ASYNC_WAL);
rm.add(p);
Delete d = new Delete(row);
d.addColumns(fam1, qual2, ts);
d.setDurability(Durability.ASYNC_WAL);
rm.add(d);
} else {
Delete d = new Delete(row);
d.addColumns(fam1, qual1, ts);
d.setDurability(Durability.ASYNC_WAL);
rm.add(d);
Put p = new Put(row, ts);
p.addColumn(fam1, qual2, value2);
p.setDurability(Durability.ASYNC_WAL);
rm.add(p);
}
region.mutateRow(rm);
op ^= true;
// check: should always see exactly one column
Get g = new Get(row);
Result r = region.get(g);
if (r.size() != 1) {
LOG.debug(r);
failures.incrementAndGet();
fail();
}
} catch (IOException e) {
e.printStackTrace();
failures.incrementAndGet();
fail();
}
}
}
};
}
// run all threads
for (int i = 0; i < numThreads; i++) {
all[i].start();
}
// wait for all threads to finish
for (int i = 0; i < numThreads; i++) {
try {
all[i].join();
} catch (InterruptedException e) {
}
}
assertEquals(0, failures.get());
}
use of org.apache.hadoop.hbase.client.RowMutations in project hbase by apache.
the class TestHRegion method testCheckAndRowMutateTimestampsAreMonotonic.
@Test
public void testCheckAndRowMutateTimestampsAreMonotonic() throws IOException {
HRegion region = initHRegion(tableName, method, CONF, fam1);
ManualEnvironmentEdge edge = new ManualEnvironmentEdge();
EnvironmentEdgeManager.injectEdge(edge);
edge.setValue(10);
Put p = new Put(row);
p.setDurability(Durability.SKIP_WAL);
p.addColumn(fam1, qual1, qual1);
region.put(p);
Result result = region.get(new Get(row));
Cell c = result.getColumnLatestCell(fam1, qual1);
assertNotNull(c);
assertEquals(c.getTimestamp(), 10L);
// clock goes back
edge.setValue(1);
p = new Put(row);
p.setDurability(Durability.SKIP_WAL);
p.addColumn(fam1, qual1, qual2);
RowMutations rm = new RowMutations(row);
rm.add(p);
assertTrue(region.checkAndRowMutate(row, fam1, qual1, CompareOp.EQUAL, new BinaryComparator(qual1), rm, false));
result = region.get(new Get(row));
c = result.getColumnLatestCell(fam1, qual1);
assertEquals(c.getTimestamp(), 10L);
LOG.info("c value " + Bytes.toStringBinary(c.getValueArray(), c.getValueOffset(), c.getValueLength()));
assertTrue(Bytes.equals(c.getValueArray(), c.getValueOffset(), c.getValueLength(), qual2, 0, qual2.length));
}
use of org.apache.hadoop.hbase.client.RowMutations in project hbase by apache.
the class TestVisibilityLabels method testMutateRow.
@Test
public void testMutateRow() throws Exception {
final byte[] qual2 = Bytes.toBytes("qual2");
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
HTableDescriptor desc = new HTableDescriptor(tableName);
HColumnDescriptor col = new HColumnDescriptor(fam);
desc.addFamily(col);
TEST_UTIL.getAdmin().createTable(desc);
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) {
Put p1 = new Put(row1);
p1.addColumn(fam, qual, value);
p1.setCellVisibility(new CellVisibility(CONFIDENTIAL));
Put p2 = new Put(row1);
p2.addColumn(fam, qual2, value);
p2.setCellVisibility(new CellVisibility(SECRET));
RowMutations rm = new RowMutations(row1);
rm.add(p1);
rm.add(p2);
table.mutateRow(rm);
Get get = new Get(row1);
get.setAuthorizations(new Authorizations(CONFIDENTIAL));
Result result = table.get(get);
assertTrue(result.containsColumn(fam, qual));
assertFalse(result.containsColumn(fam, qual2));
get.setAuthorizations(new Authorizations(SECRET));
result = table.get(get);
assertFalse(result.containsColumn(fam, qual));
assertTrue(result.containsColumn(fam, qual2));
}
}
Aggregations