Package org.apache.hadoop.hbase.client

Examples of org.apache.hadoop.hbase.client.Increment


      int row1Field2 = 1;
      Put put1 = new Put(row1);
      put1.add(fam1, qual1, Bytes.toBytes(row1Field1));
      put1.add(fam1, qual2, Bytes.toBytes(row1Field2));
      region.put(put1);
      Increment increment = new Increment(row1);
      increment.addColumn(fam1, qual1, 1);

      //here we should be successful as normal
      region.increment(increment, null, true);
      assertICV(row1, fam1, qual1, row1Field1 + 1);

      //failed to increment
      increment = new Increment(row1);
      increment.addColumn(fam1, qual2, 1);
      try {
        region.increment(increment, null, true);
        fail("Expected to fail here");
      } catch (Exception exception) {
        // Expected.
View Full Code Here


    @Override
    public void run() {
      int count = 0;
      while (count < incCounter) {
        Increment inc = new Increment(incRow);
        inc.addColumn(family, qualifier, ONE);
        count++;
        try {
          region.increment(inc, null, true);
        } catch (IOException e) {
          e.printStackTrace();
View Full Code Here

    assertEquals(11L, newVal);
    checkRowValue(ROW_A, Bytes.toBytes(11L));
  }

  private void checkIncrement() throws IOException {
    hTableInterface.increment(new Increment(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, -15L));
    checkRowValue(ROW_A, Bytes.toBytes(-4L));
  }
View Full Code Here

    checkRowValue(ROW_A, Bytes.toBytes(-4L));
  }

  private void checkBatch() throws IOException, InterruptedException {
    Object[] results1 = hTableInterface.batch(Arrays.asList(new Row[] {
        new Increment(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, 2L),
        new Increment(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, 2L) }));
    assertEquals(2, results1.length);
    for (Object r2 : results1) {
      assertTrue(r2 instanceof Result);
    }
    checkRowValue(ROW_A, Bytes.toBytes(0L));
    Object[] results2 = new Result[2];
    hTableInterface.batch(
        Arrays.asList(new Row[] { new Increment(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, 2L),
            new Increment(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, 2L) }), results2);
    for (Object r2 : results2) {
      assertTrue(r2 instanceof Result);
    }
    checkRowValue(ROW_A, Bytes.toBytes(4L));
  }
View Full Code Here

    }
    requestCount.incrementAndGet();
    try {
      HRegion region = getRegion(regionName);
      Integer lock = getLockFromId(increment.getLockId());
      Increment incVal = increment;
      Result resVal;
      if (region.getCoprocessorHost() != null) {
        resVal = region.getCoprocessorHost().preIncrement(incVal);
        if (resVal != null) {
          return resVal;
View Full Code Here

    }
    requestCount.incrementAndGet();
    try {
      HRegion region = getRegion(regionName);
      Integer lock = getLockFromId(increment.getLockId());
      Increment incVal = increment;
      Result resVal;
      if (region.getCoprocessorHost() != null) {
        resVal = region.getCoprocessorHost().preIncrement(incVal);
        if (resVal != null) {
          return resVal;
View Full Code Here

    user1.runAs(new PrivilegedExceptionAction<Void>() {
      @Override
      public Void run() throws Exception {
        HTable t = new HTable(conf, TEST_TABLE.getTableName());
        try {
          Increment inc = new Increment(TEST_ROW1);
          inc.setTimeRange(0, 123);
          inc.addColumn(TEST_FAMILY1, TEST_Q1, 2L);
          t.increment(inc);
          t.incrementColumnValue(TEST_ROW1, TEST_FAMILY1, TEST_Q2, 1L);
        } finally {
          t.close();
        }
        return null;
      }
    });

    user2.runAs(new PrivilegedExceptionAction<Void>() {
      @Override
      public Void run() throws Exception {
        HTable t = new HTable(conf, TEST_TABLE.getTableName());
        try {
          Increment inc = new Increment(TEST_ROW1);
          inc.setTimeRange(0, 127);
          inc.addColumn(TEST_FAMILY1, TEST_Q2, 2L);
          t.increment(inc);
          fail();
        } catch (Exception e) {

        } finally {
View Full Code Here

    @Override
    public void run() {
      int count = 0;
      while (count < incCounter) {
        Increment inc = new Increment(incRow);
        inc.addColumn(family, qualifier, ONE);
        count++;
        try {
          region.increment(inc);
        } catch (IOException e) {
          e.printStackTrace();
View Full Code Here

  public static Increment toIncrement(final MutationProto proto, final CellScanner cellScanner)
  throws IOException {
    MutationType type = proto.getMutateType();
    assert type == MutationType.INCREMENT : type.name();
    byte [] row = proto.hasRow()? proto.getRow().toByteArray(): null;
    Increment increment = null;
    int cellCount = proto.hasAssociatedCellCount()? proto.getAssociatedCellCount(): 0;
    if (cellCount > 0) {
      // The proto has metadata only and the data is separate to be found in the cellScanner.
      if (cellScanner == null) {
        throw new DoNotRetryIOException("Cell count of " + cellCount + " but no cellScanner: " +
          TextFormat.shortDebugString(proto));
      }
      for (int i = 0; i < cellCount; i++) {
        if (!cellScanner.advance()) {
          throw new DoNotRetryIOException("Cell count of " + cellCount + " but at index " + i +
            " no cell returned: " + TextFormat.shortDebugString(proto));
        }
        Cell cell = cellScanner.current();
        if (increment == null) {
          increment = new Increment(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength());
        }
        increment.add(KeyValueUtil.ensureKeyValue(cell));
      }
    } else {
      increment = new Increment(row);
      for (ColumnValue column: proto.getColumnValueList()) {
        byte[] family = column.getFamily().toByteArray();
        for (QualifierValue qv: column.getQualifierValueList()) {
          byte[] qualifier = qv.getQualifier().toByteArray();
          if (!qv.hasValue()) {
            throw new DoNotRetryIOException("Missing required field: qualifer value");
          }
          byte[] value = qv.getValue().toByteArray();
          byte[] tags = null;
          if (qv.hasTags()) {
            tags = qv.getTags().toByteArray();
          }
          increment.add(CellUtil.createCell(row, family, qualifier, qv.getTimestamp(),
              KeyValue.Type.Put, value, tags));
        }
      }
    }
    if (proto.hasTimeRange()) {
      HBaseProtos.TimeRange timeRange = proto.getTimeRange();
      long minStamp = 0;
      long maxStamp = Long.MAX_VALUE;
      if (timeRange.hasFrom()) {
        minStamp = timeRange.getFrom();
      }
      if (timeRange.hasTo()) {
        maxStamp = timeRange.getTo();
      }
      increment.setTimeRange(minStamp, maxStamp);
    }
    increment.setDurability(toDurability(proto.getDurability()));
    for (NameBytesPair attribute : proto.getAttributeList()) {
      increment.setAttribute(attribute.getName(), attribute.getValue().toByteArray());
    }
    return increment;
  }
View Full Code Here

   * @throws IOException
   */
  protected Result increment(final HRegion region, final MutationProto mutation,
      final CellScanner cells, long nonceGroup) throws IOException {
    long before = EnvironmentEdgeManager.currentTimeMillis();
    Increment increment = ProtobufUtil.toIncrement(mutation, cells);
    Result r = null;
    if (region.getCoprocessorHost() != null) {
      r = region.getCoprocessorHost().preIncrement(increment);
    }
    if (r == null) {
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.client.Increment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.