Java Code Examples for org.apache.hadoop.hbase.client.Get#setReplicaId()

The following examples show how to use org.apache.hadoop.hbase.client.Get#setReplicaId() . 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 File: HBaseTestingUtility.java    From hbase with Apache License 2.0 6 votes vote down vote up
public void verifyNumericRows(Table table, final byte[] f, int startRow, int endRow,
    int replicaId)
    throws IOException {
  for (int i = startRow; i < endRow; i++) {
    String failMsg = "Failed verification of row :" + i;
    byte[] data = Bytes.toBytes(String.valueOf(i));
    Get get = new Get(data);
    get.setReplicaId(replicaId);
    get.setConsistency(Consistency.TIMELINE);
    Result result = table.get(get);
    assertTrue(failMsg, result.containsColumn(f, null));
    assertEquals(failMsg, 1, result.getColumnCells(f, null).size());
    Cell cell = result.getColumnLatestCell(f, null);
    assertTrue(failMsg,
      Bytes.equals(data, 0, data.length, cell.getValueArray(), cell.getValueOffset(),
        cell.getValueLength()));
  }
}
 
Example 2
Source File: MultiThreadedReader.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected Get createGet(long keyToRead) throws IOException {
  Get get = new Get(dataGenerator.getDeterministicUniqueKey(keyToRead));
  String cfsString = "";
  byte[][] columnFamilies = dataGenerator.getColumnFamilies();
  for (byte[] cf : columnFamilies) {
    get.addFamily(cf);
    if (verbose) {
      if (cfsString.length() > 0) {
        cfsString += ", ";
      }
      cfsString += "[" + Bytes.toStringBinary(cf) + "]";
    }
  }
  get = dataGenerator.beforeGet(keyToRead, get);
  if (regionReplicaId > 0) {
    get.setReplicaId(regionReplicaId);
    get.setConsistency(Consistency.TIMELINE);
  }
  if (verbose) {
    LOG.info("[" + readerId + "] " + "Querying key " + keyToRead + ", cfs " + cfsString);
  }
  return get;
}
 
Example 3
Source File: TestRegionReplicas.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetOnTargetRegionReplica() throws Exception {
  try {
    //load some data to primary
    HTU.loadNumericRows(table, f, 0, 1000);
    // assert that we can read back from primary
    Assert.assertEquals(1000, HBaseTestingUtility.countRows(table));
    // flush so that region replica can read
    HRegion region = getRS().getRegionByEncodedName(hriPrimary.getEncodedName());
    region.flush(true);

    openRegion(HTU, getRS(), hriSecondary);

    // try directly Get against region replica
    byte[] row = Bytes.toBytes(String.valueOf(42));
    Get get = new Get(row);
    get.setConsistency(Consistency.TIMELINE);
    get.setReplicaId(1);
    Result result = table.get(get);
    Assert.assertArrayEquals(row, result.getValue(f, null));
  } finally {
    HTU.deleteNumericRows(table, HConstants.CATALOG_FAMILY, 0, 1000);
    closeRegion(HTU, getRS(), hriSecondary);
  }
}
 
Example 4
Source File: TestRegionReplicaFailover.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the case where a newly created table with region replicas and no data, the secondary
 * region replicas are available to read immediately.
 */
@Test
public void testSecondaryRegionWithEmptyRegion() throws IOException {
  // Create a new table with region replication, don't put any data. Test that the secondary
  // region replica is available to read.
  try (Connection connection = ConnectionFactory.createConnection(HTU.getConfiguration());
      Table table = connection.getTable(htd.getTableName())) {

    Get get = new Get(row);
    get.setConsistency(Consistency.TIMELINE);
    get.setReplicaId(1);
    table.get(get); // this should not block
  }
}
 
Example 5
Source File: TestRegionReplicaFailover.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the case where we are creating a table with a lot of regions and replicas. Opening region
 * replicas should not block handlers on RS indefinitely.
 */
@Test
public void testLotsOfRegionReplicas() throws IOException {
  int numRegions = NB_SERVERS * 20;
  int regionReplication = 10;
  String tableName = htd.getTableName().getNameAsString() + "2";
  htd = HTU.createTableDescriptor(TableName.valueOf(tableName),
    HColumnDescriptor.DEFAULT_MIN_VERSIONS, 3, HConstants.FOREVER,
    HColumnDescriptor.DEFAULT_KEEP_DELETED);
  htd.setRegionReplication(regionReplication);

  // dont care about splits themselves too much
  byte[] startKey = Bytes.toBytes("aaa");
  byte[] endKey = Bytes.toBytes("zzz");
  byte[][] splits = HTU.getRegionSplitStartKeys(startKey, endKey, numRegions);
  HTU.getAdmin().createTable(htd, startKey, endKey, numRegions);

  try (Connection connection = ConnectionFactory.createConnection(HTU.getConfiguration());
      Table table = connection.getTable(htd.getTableName())) {

    for (int i = 1; i < splits.length; i++) {
      for (int j = 0; j < regionReplication; j++) {
        Get get = new Get(splits[i]);
        get.setConsistency(Consistency.TIMELINE);
        get.setReplicaId(j);
        table.get(get); // this should not block. Regions should be coming online
      }
    }
  }

  HTU.deleteTableIfAny(TableName.valueOf(tableName));
}
 
Example 6
Source File: ThriftUtilities.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a {@link Get} (HBase) from a {@link TGet} (Thrift).
 *
 * This ignores any timestamps set on {@link TColumn} objects.
 *
 * @param in the <code>TGet</code> to convert
 *
 * @return <code>Get</code> object
 *
 * @throws IOException if an invalid time range or max version parameter is given
 */
public static Get getFromThrift(TGet in) throws IOException {
  Get out = new Get(in.getRow());

  // Timestamp overwrites time range if both are set
  if (in.isSetTimestamp()) {
    out.setTimestamp(in.getTimestamp());
  } else if (in.isSetTimeRange()) {
    out.setTimeRange(in.getTimeRange().getMinStamp(), in.getTimeRange().getMaxStamp());
  }

  if (in.isSetMaxVersions()) {
    out.readVersions(in.getMaxVersions());
  }

  if (in.isSetFilterString()) {
    ParseFilter parseFilter = new ParseFilter();
    out.setFilter(parseFilter.parseFilterString(in.getFilterString()));
  }

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

  if (in.isSetAuthorizations()) {
    out.setAuthorizations(new Authorizations(in.getAuthorizations().getLabels()));
  }

  if (in.isSetConsistency()) {
    out.setConsistency(consistencyFromThrift(in.getConsistency()));
  }

  if (in.isSetTargetReplicaId()) {
    out.setReplicaId(in.getTargetReplicaId());
  }

  if (in.isSetCacheBlocks()) {
    out.setCacheBlocks(in.isCacheBlocks());
  }
  if (in.isSetStoreLimit()) {
    out.setMaxResultsPerColumnFamily(in.getStoreLimit());
  }
  if (in.isSetStoreOffset()) {
    out.setRowOffsetPerColumnFamily(in.getStoreOffset());
  }
  if (in.isSetExistence_only()) {
    out.setCheckExistenceOnly(in.isExistence_only());
  }

  if (in.isSetColumns()) {
    for (TColumn column : in.getColumns()) {
      if (column.isSetQualifier()) {
        out.addColumn(column.getFamily(), column.getQualifier());
      } else {
        out.addFamily(column.getFamily());
      }
    }
  }

  if (in.isSetFilterBytes()) {
    out.setFilter(filterFromThrift(in.getFilterBytes()));
  }
  return out;
}