org.apache.hadoop.hbase.client.Table.increment()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(216)

本文整理了Java中org.apache.hadoop.hbase.client.Table.increment()方法的一些代码示例,展示了Table.increment()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Table.increment()方法的具体详情如下:
包路径:org.apache.hadoop.hbase.client.Table
类名称:Table
方法名:increment

Table.increment介绍

[英]Increments one or more columns within a single row.

This operation does not appear atomic to readers. Increments are done under a single row lock, so write operations to a row are synchronized, but readers do not take row locks so get and scan operations can see this operation partially completed.
[中]在一行中增加一列或多列。
在读者看来,此操作不是原子操作。增量是在单行锁下完成的,因此对行的写入操作是同步的,但读卡器不接受行锁,因此get和scan操作可以看到此操作部分完成。

代码示例

代码示例来源:origin: apache/hbase

  1. private void testAppend(Increment inc) throws Exception {
  2. checkResult(table.increment(inc));
  3. List<Row> actions = Arrays.asList(inc, inc);
  4. Object[] results = new Object[actions.size()];
  5. table.batch(actions, results);
  6. checkResult(results);
  7. }

代码示例来源:origin: apache/hbase

  1. @Override
  2. public Void run() throws Exception {
  3. try (Connection connection = ConnectionFactory.createConnection(conf)) {
  4. try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
  5. Increment inc = new Increment(TEST_ROW1);
  6. inc.setTimeRange(0, 123);
  7. inc.addColumn(TEST_FAMILY1, TEST_Q1, 2L);
  8. t.increment(inc);
  9. t.incrementColumnValue(TEST_ROW1, TEST_FAMILY1, TEST_Q2, 1L);
  10. }
  11. }
  12. return null;
  13. }
  14. });

代码示例来源:origin: apache/hbase

  1. @Test(expected = InvalidMutationDurabilityException.class)
  2. public void testIncrementToTableNeedReplicate() throws Exception {
  3. tableNeedReplicate.increment(newIncrementWithSkipWAL());
  4. }

代码示例来源:origin: apache/hbase

  1. @Override
  2. protected void execute(Table table) throws IOException {
  3. table.increment(new Increment(FAM_NAM).addColumn(FAM_NAM, FAM_NAM, 1));
  4. }
  5. }

代码示例来源:origin: apache/hbase

  1. @Test
  2. public void testIncrementToTableNotReplicate() throws Exception {
  3. tableNotReplicate.increment(newIncrementWithSkipWAL());
  4. }

代码示例来源:origin: apache/hbase

  1. private static void increment(int sleepSteps) throws IOException {
  2. for (long i = 1; i <= UPPER; i++) {
  3. TABLE.increment(new Increment(ROW).addColumn(FAMILY, CQ1, i).addColumn(FAMILY, CQ2, 2 * i));
  4. if (sleepSteps > 0 && i % sleepSteps == 0) {
  5. try {
  6. Thread.sleep(10);
  7. } catch (InterruptedException e) {
  8. }
  9. }
  10. }
  11. }

代码示例来源:origin: apache/hbase

  1. @Override
  2. public TResult increment(ByteBuffer table, TIncrement increment) throws TIOError, TException {
  3. checkReadOnlyMode();
  4. Table htable = getTable(table);
  5. try {
  6. return resultFromHBase(htable.increment(incrementFromThrift(increment)));
  7. } catch (IOException e) {
  8. throw getTIOError(e);
  9. } finally {
  10. closeTable(htable);
  11. }
  12. }

代码示例来源:origin: apache/hbase

  1. @Test(expected = DoNotRetryIOException.class)
  2. public void testIncrementWithDoNotRetryIOException() throws Exception {
  3. tableDoNotRetry.increment(new Increment(Bytes.toBytes("row")).addColumn(CF, CQ, 1));
  4. }

代码示例来源:origin: apache/hbase

  1. @Test(expected = RetriesExhaustedException.class)
  2. public void testIncrementWithIOException() throws Exception {
  3. tableRetry.increment(new Increment(Bytes.toBytes("row")).addColumn(CF, CQ, 1));
  4. }

代码示例来源:origin: apache/hbase

  1. /**
  2. * See {@link #incrementColumnValue(byte[], byte[], byte[], long, Durability)}
  3. * <p>
  4. * The {@link Durability} is defaulted to {@link Durability#SYNC_WAL}.
  5. * @param row The row that contains the cell to increment.
  6. * @param family The column family of the cell to increment.
  7. * @param qualifier The column qualifier of the cell to increment.
  8. * @param amount The amount to increment the cell with (or decrement, if the
  9. * amount is negative).
  10. * @return The new value, post increment.
  11. * @throws IOException if a remote or network exception occurs.
  12. */
  13. default long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier, long amount)
  14. throws IOException {
  15. Increment increment = new Increment(row).addColumn(family, qualifier, amount);
  16. Cell cell = increment(increment).getColumnLatestCell(family, qualifier);
  17. return Bytes.toLong(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
  18. }

代码示例来源:origin: apache/hbase

  1. @Override
  2. boolean testRow(final int i) throws IOException {
  3. Increment increment = new Increment(format(i));
  4. // unlike checkAndXXX tests, which make most sense to do on a single value,
  5. // if multiple families are specified for an increment test we assume it is
  6. // meant to raise the work factor
  7. for (int family = 0; family < opts.families; family++) {
  8. byte[] familyName = Bytes.toBytes(FAMILY_NAME_BASE + family);
  9. increment.addColumn(familyName, getQualifier(), 1l);
  10. }
  11. updateValueSize(this.table.increment(increment));
  12. return true;
  13. }
  14. }

代码示例来源:origin: apache/hbase

  1. @Override
  2. public Object run() throws Exception {
  3. Increment inc = new Increment(TEST_ROW);
  4. inc.addColumn(TEST_FAMILY, TEST_QUALIFIER, 1);
  5. try(Connection conn = ConnectionFactory.createConnection(conf);
  6. Table t = conn.getTable(TEST_TABLE)) {
  7. t.increment(inc);
  8. }
  9. return null;
  10. }
  11. };

代码示例来源:origin: apache/hbase

  1. @Test
  2. public void testIncrement() throws Exception {
  3. Put p = new Put(row).addColumn(cf, qualifier, Bytes.toBytes(0L));
  4. table.put(p);
  5. for(int count = 0; count < 13; count++) {
  6. Increment inc = new Increment(row);
  7. inc.addColumn(cf, qualifier, 100);
  8. table.increment(inc);
  9. }
  10. metricsRegionServer.getRegionServerWrapper().forceRecompute();
  11. assertCounter("incrementNumOps", 13);
  12. }

代码示例来源:origin: apache/hbase

  1. @Test
  2. public void testIncrement() throws IOException {
  3. try (Table t = TEST_UTIL.getConnection().getTable(TABLE_NAME)) {
  4. Put put = new Put(ROW);
  5. put.addColumn(FAMILY, QUAL, VALUE);
  6. t.put(put);
  7. assertRowAndValue(t.get(new Get(ROW)), ROW, VALUE);
  8. Increment inc = new Increment(ROW);
  9. inc.addColumn(FAMILY, QUAL, 99);
  10. assertRowAndValue(t.increment(inc), ROW, FIXED_VALUE);
  11. assertRowAndValue(t.get(new Get(ROW)), ROW, Bytes.toBytes(199L));
  12. }
  13. }

代码示例来源:origin: apache/hbase

  1. @Override
  2. public Object run() throws Exception {
  3. Increment i = new Increment(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1, 1L);
  4. try(Connection connection = ConnectionFactory.createConnection(conf);
  5. Table t = connection.getTable(TEST_TABLE.getTableName())) {
  6. t.increment(i);
  7. }
  8. return null;
  9. }
  10. };

代码示例来源:origin: apache/hbase

  1. @Override
  2. public Object run() throws Exception {
  3. Increment i = new Increment(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q2, 1L);
  4. try(Connection connection = ConnectionFactory.createConnection(conf);
  5. Table t = connection.getTable(TEST_TABLE.getTableName())) {
  6. t.increment(i);
  7. }
  8. return null;
  9. }
  10. };

代码示例来源:origin: apache/hbase

  1. @Override
  2. public Object run() throws Exception {
  3. Increment i = new Increment(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q3, 1L);
  4. try(Connection connection = ConnectionFactory.createConnection(conf);
  5. Table t = connection.getTable(TEST_TABLE.getTableName())) {
  6. t.increment(i);
  7. }
  8. return null;
  9. }
  10. };

代码示例来源:origin: apache/hbase

  1. @Override
  2. public Object run() throws Exception {
  3. Increment i = new Increment(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q2, 1L);
  4. // Tag this increment with an ACL that denies write permissions to USER_OTHER and GROUP
  5. i.setACL(prepareCellPermissions(usersAndGroups, Action.READ));
  6. try(Connection connection = ConnectionFactory.createConnection(conf);
  7. Table t = connection.getTable(TEST_TABLE.getTableName())) {
  8. t.increment(i);
  9. }
  10. return null;
  11. }
  12. };

代码示例来源:origin: apache/hbase

  1. @Override
  2. public Void run() throws Exception {
  3. try (Connection connection = ConnectionFactory.createConnection(conf)) {
  4. try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
  5. Increment inc = new Increment(row);
  6. inc.setTimeRange(0, 127);
  7. inc.addColumn(TEST_FAMILY1, q1, 2L);
  8. t.increment(inc);
  9. fail(user.getShortName() + " cannot do the increment.");
  10. } catch (Exception e) {
  11. }
  12. }
  13. return null;
  14. }
  15. });

代码示例来源:origin: apache/hbase

  1. @Test
  2. public void testIncrementWithCustomTimestamp() throws IOException {
  3. TableName TABLENAME = TableName.valueOf(name.getMethodName());
  4. Table table = TEST_UTIL.createTable(TABLENAME, FAMILY);
  5. long timestamp = 999;
  6. Increment increment = new Increment(ROW);
  7. increment.add(CellUtil.createCell(ROW, FAMILY, QUALIFIER, timestamp, KeyValue.Type.Put.getCode(), Bytes.toBytes(100L)));
  8. Result r = table.increment(increment);
  9. assertEquals(1, r.size());
  10. assertEquals(timestamp, r.rawCells()[0].getTimestamp());
  11. r = table.get(new Get(ROW));
  12. assertEquals(1, r.size());
  13. assertEquals(timestamp, r.rawCells()[0].getTimestamp());
  14. r = table.increment(increment);
  15. assertEquals(1, r.size());
  16. assertNotEquals(timestamp, r.rawCells()[0].getTimestamp());
  17. r = table.get(new Get(ROW));
  18. assertEquals(1, r.size());
  19. assertNotEquals(timestamp, r.rawCells()[0].getTimestamp());
  20. }

相关文章