Java Code Examples for org.apache.hadoop.hbase.client.Increment

The following examples show how to use org.apache.hadoop.hbase.client.Increment. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: cantor   Source File: HBaseStorage.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @return the value before increment
 */
@Override
public Optional<Long> incrementAndGet(long category, long ts, long range) {
    String tbl = String.format(TABLE_FMT, category % TABLE_COUNT);
    Table table = tableConnections.get(tbl);

    try {
        Increment increment = new Increment(Bytes.toBytes(String.format(ROW_KEY_FMT, ts)));
        increment.setTTL(ttl);
        byte[] col = Bytes.toBytes(String.valueOf(category));
        increment.addColumn(SERVICE_FAMILY, col, range);
        Result result = table.increment(increment);
        Long afterInc = Bytes.toLong(result.getValue(SERVICE_FAMILY, col));

        return Optional.of(afterInc);
    } catch (Exception e) {
        if (log.isErrorEnabled())
            log.error(
                    "increment range value failed for [ category: {} ] [ timestamp {} ] [ range {} ]",
                    category, ts, range, e);
        return Optional.empty();
    }
}
 
Example 2
Source Project: phoenix   Source File: Sequence.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public Increment newIncrement(long timestamp, Sequence.ValueOp action) {
    Increment inc = new Increment(key.getKey());
    // It doesn't matter what we set the amount too - we always use the values we get
    // from the Get we do to prevent any race conditions. All columns that get added
    // are returned with their current value
    try {
        inc.setTimeRange(MetaDataProtocol.MIN_TABLE_TIMESTAMP, timestamp);
    } catch (IOException e) {
        throw new RuntimeException(e); // Impossible
    }
    for (KeyValue kv : SEQUENCE_KV_COLUMNS) {
        // We don't care about the amount, as we'll add what gets looked up on the server-side
        inc.addColumn(kv.getFamily(), kv.getQualifier(), action.ordinal());
    }
    return inc;
}
 
Example 3
Source Project: hbase   Source File: ThriftUtilities.java    License: Apache License 2.0 6 votes vote down vote up
public static Increment incrementFromThrift(TIncrement in) throws IOException {
  Increment out = new Increment(in.getRow());
  for (TColumnIncrement column : in.getColumns()) {
    out.addColumn(column.getFamily(), column.getQualifier(), column.getAmount());
  }

  if (in.isSetAttributes()) {
    addAttributes(out,in.getAttributes());
  }

  if (in.isSetDurability()) {
    out.setDurability(durabilityFromThrift(in.getDurability()));
  }

  if(in.getCellVisibility() != null) {
    out.setCellVisibility(new CellVisibility(in.getCellVisibility().getExpression()));
  }

  if (in.isSetReturnResults()) {
    out.setReturnResults(in.isReturnResults());
  }

  return out;
}
 
Example 4
Source Project: hbase   Source File: ThriftHBaseServiceHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void increment(TIncrement tincrement) throws IOError, TException {

  if (tincrement.getRow().length == 0 || tincrement.getTable().length == 0) {
    throw new TException("Must supply a table and a row key; can't increment");
  }

  if (conf.getBoolean(COALESCE_INC_KEY, false)) {
    this.coalescer.queueIncrement(tincrement);
    return;
  }

  Table table = null;
  try {
    table = getTable(tincrement.getTable());
    Increment inc = ThriftUtilities.incrementFromThrift(tincrement);
    table.increment(inc);
  } catch (IOException e) {
    LOG.warn(e.getMessage(), e);
    throw getIOError(e);
  } finally{
    closeTable(table);
  }
}
 
Example 5
Source Project: kite   Source File: BaseEntityMapper.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Increment mapToIncrement(PartitionKey key, String fieldName,
    long amount) {
  FieldMapping fieldMapping = entitySchema.getColumnMappingDescriptor()
      .getFieldMapping(fieldName);
  if (fieldMapping == null) {
    throw new DatasetException("Unknown field in the schema: "
        + fieldName);
  }
  if (fieldMapping.getMappingType() != MappingType.COUNTER) {
    throw new DatasetException("Field is not a counter type: "
        + fieldName);
  }

  byte[] keyBytes;
  if (keySerDe == null) {
    keyBytes = new byte[] { (byte) 0 };
  } else {
    keyBytes = keySerDe.serialize(key);
  }
  Increment increment = new Increment(keyBytes);
  increment.addColumn(fieldMapping.getFamily(), fieldMapping.getQualifier(),
      amount);
  return increment;
}
 
Example 6
Source Project: hbase   Source File: RSRpcServices.java    License: Apache License 2.0 6 votes vote down vote up
private static Get toGet(final Mutation mutation) throws IOException {
  if(!(mutation instanceof Increment) && !(mutation instanceof Append)) {
    throw new AssertionError("mutation must be a instance of Increment or Append");
  }
  Get get = new Get(mutation.getRow());
  CellScanner cellScanner = mutation.cellScanner();
  while (!cellScanner.advance()) {
    Cell cell = cellScanner.current();
    get.addColumn(CellUtil.cloneFamily(cell), CellUtil.cloneQualifier(cell));
  }
  if (mutation instanceof Increment) {
    // Increment
    Increment increment = (Increment) mutation;
    get.setTimeRange(increment.getTimeRange().getMin(), increment.getTimeRange().getMax());
  } else {
    // Append
    Append append = (Append) mutation;
    get.setTimeRange(append.getTimeRange().getMin(), append.getTimeRange().getMax());
  }
  for (Entry<String, byte[]> entry : mutation.getAttributesMap().entrySet()) {
    get.setAttribute(entry.getKey(), entry.getValue());
  }
  return get;
}
 
Example 7
Source Project: hbase   Source File: RegionCoprocessorHost.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Supports Coprocessor 'bypass'.
 * @param increment increment object
 * @return result to return to client if default operation should be bypassed, null otherwise
 * @throws IOException if an error occurred on the coprocessor
 */
public Result preIncrement(final Increment increment) throws IOException {
  boolean bypassable = true;
  Result defaultResult = null;
  if (coprocEnvironments.isEmpty()) {
    return defaultResult;
  }
  return execOperationWithResult(
      new ObserverOperationWithResult<RegionObserver, Result>(regionObserverGetter, defaultResult,
          bypassable) {
        @Override
        public Result call(RegionObserver observer) throws IOException {
          return observer.preIncrement(this, increment);
        }
      });
}
 
Example 8
Source Project: hbase   Source File: RegionCoprocessorHost.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Supports Coprocessor 'bypass'.
 * @param increment increment object
 * @return result to return to client if default operation should be bypassed, null otherwise
 * @throws IOException if an error occurred on the coprocessor
 */
public Result preIncrementAfterRowLock(final Increment increment) throws IOException {
  boolean bypassable = true;
  Result defaultResult = null;
  if (coprocEnvironments.isEmpty()) {
    return defaultResult;
  }
  return execOperationWithResult(
      new ObserverOperationWithResult<RegionObserver, Result>(regionObserverGetter, defaultResult,
          bypassable) {
        @Override
        public Result call(RegionObserver observer) throws IOException {
          return observer.preIncrementAfterRowLock(this, increment);
        }
      });
}
 
Example 9
Source Project: hbase   Source File: TestVisibilityLabels.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testLabelsWithIncrement() throws Throwable {
  TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
  try (Table table = TEST_UTIL.createTable(tableName, fam)) {
    byte[] row1 = Bytes.toBytes("row1");
    byte[] val = Bytes.toBytes(1L);
    Put put = new Put(row1);
    put.addColumn(fam, qual, HConstants.LATEST_TIMESTAMP, val);
    put.setCellVisibility(new CellVisibility(SECRET + " & " + CONFIDENTIAL));
    table.put(put);
    Get get = new Get(row1);
    get.setAuthorizations(new Authorizations(SECRET));
    Result result = table.get(get);
    assertTrue(result.isEmpty());
    table.incrementColumnValue(row1, fam, qual, 2L);
    result = table.get(get);
    assertTrue(result.isEmpty());
    Increment increment = new Increment(row1);
    increment.addColumn(fam, qual, 2L);
    increment.setCellVisibility(new CellVisibility(SECRET));
    table.increment(increment);
    result = table.get(get);
    assertTrue(!result.isEmpty());
  }
}
 
Example 10
Source Project: hbase   Source File: TestCellACLWithMultipleVersions.java    License: Apache License 2.0 6 votes vote down vote up
private void verifyUserDeniedForIncrementMultipleVersions(final User user, final byte[] row,
    final byte[] q1) throws IOException, InterruptedException {
  user.runAs(new PrivilegedExceptionAction<Void>() {
    @Override
    public Void run() throws Exception {
      try (Connection connection = ConnectionFactory.createConnection(conf)) {
        try (Table t = connection.getTable(testTable.getTableName())) {
          Increment inc = new Increment(row);
          inc.setTimeRange(0, 127);
          inc.addColumn(TEST_FAMILY1, q1, 2L);
          t.increment(inc);
          fail(user.getShortName() + " cannot do the increment.");
        } catch (Exception e) {

        }
      }
      return null;
    }
  });
}
 
Example 11
Source Project: pinpoint   Source File: RowKeyMerge.java    License: Apache License 2.0 6 votes vote down vote up
public Map<TableName, List<Increment>> createBulkIncrement(Map<RowInfo, Long> data, RowKeyDistributorByHashPrefix rowKeyDistributorByHashPrefix) {
    if (data.isEmpty()) {
        return Collections.emptyMap();
    }

    final Map<TableName, List<Increment>> tableIncrementMap = new HashMap<>();
    final Map<TableName, Map<RowKey, List<ColumnName>>> tableRowKeyMap = mergeRowKeys(data);

    for (Map.Entry<TableName, Map<RowKey, List<ColumnName>>> tableRowKeys : tableRowKeyMap.entrySet()) {
        final TableName tableName = tableRowKeys.getKey();
        final List<Increment> incrementList = new ArrayList<>();
        for (Map.Entry<RowKey, List<ColumnName>> rowKeyEntry : tableRowKeys.getValue().entrySet()) {
            Increment increment = createIncrement(rowKeyEntry, rowKeyDistributorByHashPrefix);
            incrementList.add(increment);
        }
        tableIncrementMap.put(tableName, incrementList);
    }
    return tableIncrementMap;
}
 
Example 12
Source Project: hbase   Source File: TestPostIncrementAndAppendBeforeWAL.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testChangeCellWithDifferntColumnFamily() throws Exception {
  TableName tableName = TableName.valueOf(name.getMethodName());
  createTableWithCoprocessor(tableName,
    ChangeCellWithDifferntColumnFamilyObserver.class.getName());

  try (Table table = connection.getTable(tableName)) {
    Increment increment = new Increment(ROW).addColumn(CF1_BYTES, CQ1, 1);
    table.increment(increment);
    Get get = new Get(ROW).addColumn(CF2_BYTES, CQ1);
    Result result = table.get(get);
    assertEquals(1, result.size());
    assertEquals(1, Bytes.toLong(result.getValue(CF2_BYTES, CQ1)));

    Append append = new Append(ROW).addColumn(CF1_BYTES, CQ2, VALUE);
    table.append(append);
    get = new Get(ROW).addColumn(CF2_BYTES, CQ2);
    result = table.get(get);
    assertEquals(1, result.size());
    assertTrue(Bytes.equals(VALUE, result.getValue(CF2_BYTES, CQ2)));
  }
}
 
Example 13
Source Project: phoenix   Source File: Sequence.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Increment newIncrement(long timestamp) {
    Increment inc = new Increment(SchemaUtil.getSequenceKey(key.getTenantId(), key.getSchemaName(), key.getSequenceName()));
    // It doesn't matter what we set the amount too - we always use the values we get
    // from the Get we do to prevent any race conditions. All columns that get added
    // are returned with their current value
    try {
        inc.setTimeRange(MetaDataProtocol.MIN_TABLE_TIMESTAMP, timestamp);
    } catch (IOException e) {
        throw new RuntimeException(e); // Impossible
    }
    for (KeyValue kv : SEQUENCE_KV_COLUMNS) {
        // We don't care about the amount, as we'll add what gets looked up on the server-side
        inc.addColumn(kv.getFamily(), kv.getQualifier(), AMOUNT);
    }
    return inc;
}
 
Example 14
Source Project: hbase   Source File: MultiThreadedUpdaterWithACL.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object run() throws Exception {
  try {
    if (table == null) {
      table = connection.getTable(tableName);
    }
    if (m instanceof Increment) {
      table.increment((Increment) m);
    } else if (m instanceof Append) {
      table.append((Append) m);
    } else if (m instanceof Put) {
      table.checkAndMutate(row, cf).qualifier(q).ifEquals(v).thenPut((Put) m);
    } else if (m instanceof Delete) {
      table.checkAndMutate(row, cf).qualifier(q).ifEquals(v).thenDelete((Delete) m);
    } else {
      throw new IllegalArgumentException("unsupported mutation "
          + m.getClass().getSimpleName());
    }
    totalOpTimeMs.addAndGet(System.currentTimeMillis() - start);
  } catch (IOException e) {
    recordFailure(m, keyBase, start, e);
  }
  return null;
}
 
Example 15
Source Project: hbase   Source File: TestWALMonotonicallyIncreasingSeqId.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
  try {
    for (int i = 0; i < 100; i++) {
      byte[] row = Bytes.toBytes("incrementRow" + i);
      Increment inc = new Increment(row);
      inc.addColumn(Bytes.toBytes("cf"), Bytes.toBytes(0), 1);
      // inc.setDurability(Durability.ASYNC_WAL);
      region.increment(inc);
      latch.countDown();
      Thread.sleep(10);
    }

  } catch (Throwable t) {
    LOG.warn("Error happend when Put: ", t);
  }
}
 
Example 16
Source Project: pinpoint   Source File: BulkIncrementerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Map<TableName, List<Increment>> call() {
    Map<TableName, List<Increment>> resultMap = new HashMap<>();
    try {
        do {
            flushToMap(resultMap);
        } while (!awaitLatch.await(10L, TimeUnit.MILLISECONDS));
        flushToMap(resultMap);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return Collections.emptyMap();
    } finally {
        completeLatch.countDown();
    }
    return resultMap;
}
 
Example 17
Source Project: hbase   Source File: WriteHeavyIncrementObserver.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Result preIncrement(ObserverContext<RegionCoprocessorEnvironment> c, Increment increment)
    throws IOException {
  byte[] row = increment.getRow();
  Put put = new Put(row);
  long ts = getUniqueTimestamp(row);
  for (Map.Entry<byte[], List<Cell>> entry : increment.getFamilyCellMap().entrySet()) {
    for (Cell cell : entry.getValue()) {
      put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY).setRow(row)
          .setFamily(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength())
          .setQualifier(cell.getQualifierArray(), cell.getQualifierOffset(),
            cell.getQualifierLength())
          .setValue(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength())
          .setType(Cell.Type.Put).setTimestamp(ts).build());
    }
  }
  c.getEnvironment().getRegion().put(put);
  c.bypass();
  return Result.EMPTY_RESULT;
}
 
Example 18
Source Project: hadoop-arch-book   Source File: BasicFraudHBaseService.java    License: Apache License 2.0 6 votes vote down vote up
public void updateProfileCountsForSaleInHBase(Long buyerId, Long sellerId, ItemSaleEvent event) throws IOException, InterruptedException {
  HTableInterface profileTable = hTablePool.getTable(DataModelConsts.PROFILE_TABLE);
  ArrayList<Row> actions = new ArrayList<Row>();
  
  Increment buyerValueIncrement = new Increment(generateProfileRowKey(buyerId));
  buyerValueIncrement.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.CURRENT_LOG_IN_PURCHASES_VALUE_COL, event.getItemValue());
  buyerValueIncrement.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_VALUE_OF_PAST_SELLS_COL, event.getItemValue());
  actions.add(buyerValueIncrement);
  
  Increment sellerValueIncrement = new Increment(generateProfileRowKey(sellerId));
  sellerValueIncrement.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.CURRENT_LOG_IN_SELLS_VALUE_COL, event.getItemValue());
  sellerValueIncrement.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_VALUE_OF_PAST_SELLS_COL, event.getItemValue());
  actions.add(sellerValueIncrement);
  
  profileTable.batch(actions);
  
}
 
Example 19
Source Project: hadoop-arch-book   Source File: BasicFraudHBaseService.java    License: Apache License 2.0 6 votes vote down vote up
public void logInProfileInHBase(long userId, String ipAddress) throws IOException, Exception {
  HTableInterface profileTable = hTablePool.getTable(DataModelConsts.PROFILE_TABLE);
  
  ArrayList<Row> actions = new ArrayList<Row>();
  
  byte[] profileRowKey = generateProfileRowKey(userId);

  Delete delete = new Delete(profileRowKey);
  delete.deleteColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.CURRENT_LOG_IN_PURCHASES_VALUE_COL);
  delete.deleteColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.CURRENT_LOG_IN_SELLS_VALUE_COL);
  actions.add(delete);
  
  Increment increment = new Increment(profileRowKey);
  increment.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LOG_IN_COUNT_COL, 1);
  actions.add(increment);
  
  Put put = new Put(profileRowKey);
  put.add(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LAST_LOG_IN_COL, Bytes.toBytes(System.currentTimeMillis()));
  put.add(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LOG_IN_IP_ADDERSSES, Bytes.toBytes(ipAddress));
  actions.add(put);
  
  profileTable.batch(actions);
}
 
Example 20
Source Project: hadoop-arch-book   Source File: BasicFraudHBaseService.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void createProfile(long userId, ProfilePojo pojo, String ipAddress) throws Exception {
  HTableInterface profileTable = hTablePool.getTable(DataModelConsts.PROFILE_TABLE);
  
  ArrayList<Row> actions = new ArrayList<Row>();
  
  byte[] rowKey = generateProfileRowKey(userId);
  Put put = new Put(rowKey);
  put.add(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.FIXED_INFO_COL, Bytes.toBytes(pojo.getUsername() + "|" + pojo.getAge() + "|" + System.currentTimeMillis()));
  put.add(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LOG_IN_IP_ADDERSSES, Bytes.toBytes(ipAddress));
  put.add(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LAST_LOG_IN_COL, Bytes.toBytes(System.currentTimeMillis()));
  actions.add(put);
  
  Increment increment = new Increment(rowKey);
  
  increment.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LOG_IN_COUNT_COL, 1);
  increment.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_SELLS_COL, 0);
  increment.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_PURCHASES_COL, 0);
  increment.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_VALUE_OF_PAST_PURCHASES_COL, 0);
  increment.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_VALUE_OF_PAST_SELLS_COL, 0);
  increment.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.CURRENT_LOG_IN_SELLS_VALUE_COL, 0);
  increment.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.CURRENT_LOG_IN_PURCHASES_VALUE_COL, 0);
  actions.add(increment);
  
  profileTable.batch(actions);
}
 
Example 21
Source Project: DDMQ   Source File: HBaseAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Status act(UpstreamJob job, byte[] bytes) {
    HBaseConnection connection = connectionMap.get(job.getTopic());
    if (connection == null) {
        LogUtils.logErrorInfo("HBASE_error", "no hbase connection for topic=" + job.getTopic());
        return FAIL;
    }

    if (CollectionUtils.isNotEmpty(job.getHbaseCommands())) {
        try {
            for (HbaseCommand hbaseCommand : job.getHbaseCommands()) {
                HTableInterface table = connection.getTable(hbaseCommand.getTableName());
                Mutation mutation = hbaseCommand.getMutation();

                if (mutation instanceof Put) {
                    table.put((Put) mutation);
                } else if (mutation instanceof Delete) {
                    table.delete((Delete) mutation);
                } else if (mutation instanceof Append) {
                    table.append((Append) mutation);
                } else if (mutation instanceof Increment) {
                    table.increment((Increment) mutation);
                }
            }
            MetricUtils.qpsAndFilterMetric(job, MetricUtils.ConsumeResult.SUCCESS);
            return FINISH;
        } catch (IOException e) {
            LogUtils.logErrorInfo("HBASE_error", "job=" + job, e);
            return FAIL;
        }
    } else {
        LogUtils.logErrorInfo("HBASE_error", "no hbase command found, group:{}, topic:{}", group, job.getTopic());
        return FAIL;
    }
}
 
Example 22
Source Project: DDMQ   Source File: HBaseAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Status act(UpstreamJob job, byte[] bytes) {
    HBaseConnection connection = connectionMap.get(job.getTopic());
    if (connection == null) {
        LogUtils.logErrorInfo("HBASE_error", "no hbase connection for topic=" + job.getTopic());
        return FAIL;
    }

    if (CollectionUtils.isNotEmpty(job.getHbaseCommands())) {
        try {
            for (HbaseCommand hbaseCommand : job.getHbaseCommands()) {
                HTableInterface table = connection.getTable(hbaseCommand.getTableName());
                Mutation mutation = hbaseCommand.getMutation();

                if (mutation instanceof Put) {
                    table.put((Put) mutation);
                } else if (mutation instanceof Delete) {
                    table.delete((Delete) mutation);
                } else if (mutation instanceof Append) {
                    table.append((Append) mutation);
                } else if (mutation instanceof Increment) {
                    table.increment((Increment) mutation);
                }
            }
            MetricUtils.qpsAndFilterMetric(job, MetricUtils.ConsumeResult.SUCCESS);
            return FINISH;
        } catch (IOException e) {
            LogUtils.logErrorInfo("HBASE_error", "job=" + job, e);
            return FAIL;
        }
    } else {
        LogUtils.logErrorInfo("HBASE_error", "no hbase command found, group:{}, topic:{}", group, job.getTopic());
        return FAIL;
    }
}
 
Example 23
Source Project: hgraphdb   Source File: PropertyIncrementer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<Mutation> constructMutations() {
    Increment incr = new Increment(ValueUtils.serializeWithSalt(element.id()));
    incr.addColumn(Constants.DEFAULT_FAMILY_BYTES, Bytes.toBytes(key), value);
    Put put = new Put(ValueUtils.serializeWithSalt(element.id()));
    put.addColumn(Constants.DEFAULT_FAMILY_BYTES, Constants.UPDATED_AT_BYTES,
            ValueUtils.serialize(((HBaseElement) element).updatedAt()));
    return IteratorUtils.of(incr, put);
}
 
Example 24
Source Project: mt-flume   Source File: SimpleHbaseEventSerializer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public List<Increment> getIncrements(){
  List<Increment> incs = new LinkedList<Increment>();
  if(incCol != null) {
    Increment inc = new Increment(incrementRow);
    inc.addColumn(cf, incCol, 1);
    incs.add(inc);
  }
  return incs;
}
 
Example 25
public Increment call(String v) throws Exception {
  String[] cells = v.split(",");
  Increment increment = new Increment(Bytes.toBytes(cells[0]));

  increment.addColumn(Bytes.toBytes(cells[1]), Bytes.toBytes(cells[2]),
      Integer.parseInt(cells[3]));
  return increment;
}
 
Example 26
Source Project: hbase   Source File: ThriftUtilities.java    License: Apache License 2.0 5 votes vote down vote up
public static TIncrement incrementFromHBase(Increment in) throws IOException {
  TIncrement out = new TIncrement();
  out.setRow(in.getRow());

  if (in.getDurability() != Durability.USE_DEFAULT) {
    out.setDurability(durabilityFromHBase(in.getDurability()));
  }
  for (Map.Entry<byte [], List<Cell>> entry : in.getFamilyCellMap().entrySet()) {
    byte[] family = entry.getKey();
    for (Cell cell : entry.getValue()) {
      TColumnIncrement columnValue = new TColumnIncrement();
      columnValue.setFamily(family).setQualifier(CellUtil.cloneQualifier(cell));
      columnValue.setAmount(
          Bytes.toLong(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()));
      out.addToColumns(columnValue);
    }
  }
  for (Map.Entry<String, byte[]> attribute : in.getAttributesMap().entrySet()) {
    out.putToAttributes(ByteBuffer.wrap(Bytes.toBytes(attribute.getKey())),
        ByteBuffer.wrap(attribute.getValue()));
  }
  try {
    CellVisibility cellVisibility = in.getCellVisibility();
    if (cellVisibility != null) {
      TCellVisibility tCellVisibility = new TCellVisibility();
      tCellVisibility.setExpression(cellVisibility.getExpression());
      out.setCellVisibility(tCellVisibility);
    }
  } catch (DeserializationException e) {
    throw new RuntimeException(e);
  }
  out.setReturnResults(in.isReturnResults());
  return out;
}
 
Example 27
Source Project: hbase   Source File: ThriftUtilities.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * From a {@link TIncrement} create an {@link Increment}.
 * @param tincrement the Thrift version of an increment
 * @return an increment that the {@link TIncrement} represented.
 */
public static Increment incrementFromThrift(TIncrement tincrement) {
  Increment inc = new Increment(tincrement.getRow());
  byte[][] famAndQf = CellUtil.parseColumn(tincrement.getColumn());

  if (famAndQf.length != 2) {
    return null;
  }

  inc.addColumn(famAndQf[0], famAndQf[1], tincrement.getAmmount());
  return inc;
}
 
Example 28
Source Project: hbase   Source File: VisibilityController.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Result preIncrement(ObserverContext<RegionCoprocessorEnvironment> e, Increment increment)
    throws IOException {
  // If authorization is not enabled, we don't care about reserved tags
  if (!authorizationEnabled) {
    return null;
  }
  for (CellScanner cellScanner = increment.cellScanner(); cellScanner.advance();) {
    if (!checkForReservedVisibilityTagPresence(cellScanner.current())) {
      throw new FailedSanityCheckException("Increment contains cell with reserved type tag");
    }
  }
  return null;
}
 
Example 29
Source Project: hbase   Source File: AccessController.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Result preIncrement(final ObserverContext<RegionCoprocessorEnvironment> c,
    final Increment increment)
    throws IOException {
  User user = getActiveUser(c);
  checkForReservedTagPresence(user, increment);

  // Require WRITE permission to the table, CF, and the KV to be replaced by
  // the incremented value
  RegionCoprocessorEnvironment env = c.getEnvironment();
  Map<byte[],? extends Collection<Cell>> families = increment.getFamilyCellMap();
  AuthResult authResult = permissionGranted(OpType.INCREMENT,
      user, env, families, Action.WRITE);
  AccessChecker.logResult(authResult);
  if (!authResult.isAllowed()) {
    if (cellFeaturesEnabled && !compatibleEarlyTermination) {
      increment.setAttribute(CHECK_COVERING_PERM, TRUE);
    } else if (authorizationEnabled) {
      throw new AccessDeniedException("Insufficient permissions " +
        authResult.toContextString());
    }
  }

  byte[] bytes = increment.getAttribute(AccessControlConstants.OP_ATTRIBUTE_ACL);
  if (bytes != null) {
    if (cellFeaturesEnabled) {
      addCellPermissions(bytes, increment.getFamilyCellMap());
    } else {
      throw new DoNotRetryIOException("Cell ACLs cannot be persisted");
    }
  }

  return null;
}
 
Example 30
Source Project: hbase   Source File: NoInsertsViolationPolicyEnforcement.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void check(Mutation m) throws SpaceLimitingException {
  // Disallow all "new" data flowing into HBase, but allow Deletes (even though we know they will
  // temporarily increase utilization).
  if (m instanceof Append  || m instanceof Increment || m instanceof Put) {
    throw new SpaceLimitingException(getPolicyName(),
        m.getClass().getSimpleName() + "s are disallowed due to a space quota.");
  }
}