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

The following are top voted examples for showing how to use org.apache.hadoop.hbase.client.HTableInterface. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: SparkDemo   File: MyClass.java   Source Code and License 6 votes vote down vote up
public static void QueryAll(String tableName) {
    try {
        HTableInterface table = conn.getTable(tableName);

        ResultScanner rs = table.getScanner(new Scan());
        for (Result r : rs) {
            System.out.println("rowkey:" + new String(r.getRow()));
            for (KeyValue keyValue : r.raw()) {
                System.out.println("column:" + new String(keyValue.getFamily())
                        + "====value:" + new String(keyValue.getValue()));
            }
        }
        table.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 2
Project: SparkIsax   File: HBaseUtils.java   Source Code and License 6 votes vote down vote up
/**
 * 拷贝表
 * 
 * @throws IOException
 */
public static void copyTable(String oldTableName, String newTableName,String ColumnFamily, String ColumnName)throws IOException {
	if(CreateNewTable(newTableName))
		logger.info("创建表"+newTableName+"表成功");
	else{
		logger.info("创建表"+newTableName+"表失败");
	}
	Scan s = new Scan();
	s.addColumn(Bytes.toBytes(ColumnFamily), Bytes.toBytes(ColumnName));
	s.setMaxVersions(1);
	s.setCacheBlocks(false);
	ResultScanner rs = hbase_table.getScanner(s);
	
	HTableInterface hbase_table_new = conn.getTable(newTableName);
	for (Result r : rs) {
		byte[] key = r.getRow();
		byte[] value = r.getValue(Bytes.toBytes(ColumnFamily), Bytes.toBytes(ColumnName));
		Put put = new Put(key);
		put.add(Bytes.toBytes(ColumnFamily), Bytes.toBytes(ColumnName), value);
		hbase_table_new.put(put);
	}
	rs.close();
	hbase_table_new.close();
}
 
Example 3
Project: incubator-tephra   File: DataJanitorStateTest.java   Source Code and License 6 votes vote down vote up
@Before
public void beforeTest() throws Exception {
  pruneStateTable = TableName.valueOf(conf.get(TxConstants.TransactionPruning.PRUNE_STATE_TABLE,
                                               TxConstants.TransactionPruning.DEFAULT_PRUNE_STATE_TABLE));
  HTable table = createTable(pruneStateTable.getName(), new byte[][]{DataJanitorState.FAMILY}, false,
                             // Prune state table is a non-transactional table, hence no transaction co-processor
                             Collections.<String>emptyList());
  table.close();
  connection = HConnectionManager.createConnection(conf);

  dataJanitorState =
    new DataJanitorState(new DataJanitorState.TableSupplier() {
      @Override
      public HTableInterface get() throws IOException {
        return connection.getTable(pruneStateTable);
      }
    });

}
 
Example 4
Project: hadooparchitecturebook   File: BasicFraudHBaseService.java   Source Code and License 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 5
Project: hadooparchitecturebook   File: BasicFraudHBaseService.java   Source Code and License 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 6
Project: hadooparchitecturebook   File: BasicFraudHBaseService.java   Source Code and License 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 7
Project: incubator-tephra   File: SecondaryIndexTable.java   Source Code and License 6 votes vote down vote up
public SecondaryIndexTable(TransactionServiceClient transactionServiceClient, HTableInterface hTable,
                           byte[] secondaryIndex) {
  secondaryIndexTableName = TableName.valueOf(hTable.getName().getNameAsString() + ".idx");
  HTable secondaryIndexHTable = null;
  try (HBaseAdmin hBaseAdmin = new HBaseAdmin(hTable.getConfiguration())) {
    if (!hBaseAdmin.tableExists(secondaryIndexTableName)) {
      hBaseAdmin.createTable(new HTableDescriptor(secondaryIndexTableName));
    }
    secondaryIndexHTable = new HTable(hTable.getConfiguration(), secondaryIndexTableName);
  } catch (Exception e) {
    Throwables.propagate(e);
  }

  this.secondaryIndex = secondaryIndex;
  this.transactionAwareHTable = new TransactionAwareHTable(hTable);
  this.secondaryIndexTable = new TransactionAwareHTable(secondaryIndexHTable);
  this.transactionContext = new TransactionContext(transactionServiceClient, transactionAwareHTable,
                                                   secondaryIndexTable);
}
 
Example 8
Project: incubator-tephra   File: TransactionAwareHTableTest.java   Source Code and License 6 votes vote down vote up
private void verifyRows(HTableInterface table, Get get, List<byte[]> expectedValues) throws Exception {
  Result result = table.get(get);
  if (expectedValues == null) {
    assertTrue(result.isEmpty());
  } else {
    assertFalse(result.isEmpty());
    byte[] family = TestBytes.family;
    byte[] col = TestBytes.qualifier;
    if (get.hasFamilies()) {
      family = get.getFamilyMap().keySet().iterator().next();
      col = get.getFamilyMap().get(family).first();
    }
    Iterator<Cell> it = result.getColumnCells(family, col).iterator();
    for (byte[] expectedValue : expectedValues) {
      Assert.assertTrue(it.hasNext());
      assertArrayEquals(expectedValue, CellUtil.cloneValue(it.next()));
    }
  }
}
 
Example 9
Project: incubator-tephra   File: DataJanitorState.java   Source Code and License 6 votes vote down vote up
/**
 * Return the set of regions saved for the time at or before the given time. This method finds the greatest time
 * that is less than or equal to the given time, and then returns all regions with that exact time, but none that are
 * older than that.
 *
 * @param time timestamp in milliseconds
 * @return set of regions and time at which they were recorded, or null if no regions found
 * @throws IOException when not able to read the data from HBase
 */
@Nullable
public TimeRegions getRegionsOnOrBeforeTime(long time) throws IOException {
  try (HTableInterface stateTable = stateTableSupplier.get()) {
    TimeRegions timeRegions;
    while ((timeRegions = getNextSetOfTimeRegions(stateTable, time)) != null) {
      int count = getRegionCountForTime(stateTable, timeRegions.getTime());
      if (count != -1 && count == timeRegions.getRegions().size()) {
        return timeRegions;
      } else {
        LOG.warn(String.format("Got incorrect count for regions saved at time %s, expected = %s but actual = %s",
                               timeRegions.getTime(), count, timeRegions.getRegions().size()));
        time = timeRegions.getTime() - 1;
      }
    }
    return null;
  }
}
 
Example 10
Project: incubator-tephra   File: HBaseTransactionPruningPlugin.java   Source Code and License 6 votes vote down vote up
@Override
public void initialize(Configuration conf) throws IOException {
  this.conf = conf;
  this.hBaseAdmin = new HBaseAdmin(conf);
  this.connection = HConnectionManager.createConnection(conf);

  final TableName stateTable = TableName.valueOf(conf.get(TxConstants.TransactionPruning.PRUNE_STATE_TABLE,
                                                          TxConstants.TransactionPruning.DEFAULT_PRUNE_STATE_TABLE));
  LOG.info("Initializing plugin with state table {}:{}", stateTable.getNamespaceAsString(),
           stateTable.getNameAsString());
  createPruneTable(stateTable);
  this.dataJanitorState = new DataJanitorState(new DataJanitorState.TableSupplier() {
    @Override
    public HTableInterface get() throws IOException {
      return connection.getTable(stateTable);
    }
  });
}
 
Example 11
Project: incubator-tephra   File: DataJanitorState.java   Source Code and License 6 votes vote down vote up
/**
 * Gets a list of {@link RegionPruneInfo} for given regions. Returns all regions if the given regions set is null.
 *
 * @param regions a set of regions
 * @return list of {@link RegionPruneInfo}s.
 * @throws IOException when not able to read the data from HBase
 */
public List<RegionPruneInfo> getPruneInfoForRegions(@Nullable SortedSet<byte[]> regions) throws IOException {
  List<RegionPruneInfo> regionPruneInfos = new ArrayList<>();
  try (HTableInterface stateTable = stateTableSupplier.get()) {
    byte[] startRow = makeRegionKey(EMPTY_BYTE_ARRAY);
    Scan scan = new Scan(startRow, REGION_KEY_PREFIX_STOP);
    scan.addColumn(FAMILY, PRUNE_UPPER_BOUND_COL);

    try (ResultScanner scanner = stateTable.getScanner(scan)) {
      Result next;
      while ((next = scanner.next()) != null) {
        byte[] region = getRegionFromKey(next.getRow());
        if (regions == null || regions.contains(region)) {
          Cell cell = next.getColumnLatestCell(FAMILY, PRUNE_UPPER_BOUND_COL);
          if (cell != null) {
            byte[] pruneUpperBoundBytes = CellUtil.cloneValue(cell);
            long timestamp = cell.getTimestamp();
            regionPruneInfos.add(new RegionPruneInfo(region, Bytes.toStringBinary(region),
                                                     Bytes.toLong(pruneUpperBoundBytes), timestamp));
          }
        }
      }
    }
  }
  return Collections.unmodifiableList(regionPruneInfos);
}
 
Example 12
Project: incubator-tephra   File: DataJanitorState.java   Source Code and License 6 votes vote down vote up
/**
 * Delete prune upper bounds for the regions that are not in the given exclude set, and the
 * prune upper bound is less than the given value.
 * After the invalid list is pruned up to deletionPruneUpperBound, we do not need entries for regions that have
 * prune upper bound less than deletionPruneUpperBound. We however limit the deletion to only regions that are
 * no longer in existence (due to deletion, etc.), to avoid update/delete race conditions.
 *
 * @param deletionPruneUpperBound prune upper bound below which regions will be deleted
 * @param excludeRegions set of regions that should not be deleted
 * @throws IOException when not able to delete data in HBase
 */
public void deletePruneUpperBounds(long deletionPruneUpperBound, SortedSet<byte[]> excludeRegions)
  throws IOException {
  try (HTableInterface stateTable = stateTableSupplier.get()) {
    byte[] startRow = makeRegionKey(EMPTY_BYTE_ARRAY);
    Scan scan = new Scan(startRow, REGION_KEY_PREFIX_STOP);
    scan.addColumn(FAMILY, PRUNE_UPPER_BOUND_COL);

    try (ResultScanner scanner = stateTable.getScanner(scan)) {
      Result next;
      while ((next = scanner.next()) != null) {
        byte[] region = getRegionFromKey(next.getRow());
        if (!excludeRegions.contains(region)) {
          byte[] timeBytes = next.getValue(FAMILY, PRUNE_UPPER_BOUND_COL);
          if (timeBytes != null) {
            long pruneUpperBoundRegion = Bytes.toLong(timeBytes);
            if (pruneUpperBoundRegion < deletionPruneUpperBound) {
              stateTable.delete(new Delete(next.getRow()));
            }
          }
        }
      }
    }
  }
}
 
Example 13
Project: incubator-tephra   File: DataJanitorState.java   Source Code and License 6 votes vote down vote up
/**
 * Return the set of regions saved for the time at or before the given time. This method finds the greatest time
 * that is less than or equal to the given time, and then returns all regions with that exact time, but none that are
 * older than that.
 *
 * @param time timestamp in milliseconds
 * @return set of regions and time at which they were recorded, or null if no regions found
 * @throws IOException when not able to read the data from HBase
 */
@Nullable
public TimeRegions getRegionsOnOrBeforeTime(long time) throws IOException {
  try (HTableInterface stateTable = stateTableSupplier.get()) {
    TimeRegions timeRegions;
    while ((timeRegions = getNextSetOfTimeRegions(stateTable, time)) != null) {
      int count = getRegionCountForTime(stateTable, timeRegions.getTime());
      if (count != -1 && count == timeRegions.getRegions().size()) {
        return timeRegions;
      } else {
        LOG.warn(String.format("Got incorrect count for regions saved at time %s, expected = %s but actual = %s",
                               timeRegions.getTime(), count, timeRegions.getRegions().size()));
        time = timeRegions.getTime() - 1;
      }
    }
    return null;
  }
}
 
Example 14
Project: incubator-tephra   File: DataJanitorState.java   Source Code and License 6 votes vote down vote up
/**
 * Return regions that were recorded as empty after the given time.
 *
 * @param time time in milliseconds
 * @param includeRegions If not null, the returned set will be an intersection of the includeRegions set
 *                       and the empty regions after the given time
 */
public SortedSet<byte[]> getEmptyRegionsAfterTime(long time, @Nullable SortedSet<byte[]> includeRegions)
  throws IOException {
  SortedSet<byte[]> emptyRegions = new TreeSet<>(Bytes.BYTES_COMPARATOR);
  try (HTableInterface stateTable = stateTableSupplier.get()) {
    Scan scan = new Scan(makeEmptyRegionTimeKey(Bytes.toBytes(time + 1), EMPTY_BYTE_ARRAY),
                         EMPTY_REGION_TIME_KEY_PREFIX_STOP);
    scan.addColumn(FAMILY, EMPTY_REGION_TIME_COL);

    try (ResultScanner scanner = stateTable.getScanner(scan)) {
      Result next;
      while ((next = scanner.next()) != null) {
        byte[] emptyRegion = getEmptyRegionFromKey(next.getRow());
        if (includeRegions == null || includeRegions.contains(emptyRegion)) {
          emptyRegions.add(emptyRegion);
        }
      }
    }
  }
  return Collections.unmodifiableSortedSet(emptyRegions);
}
 
Example 15
Project: incubator-tephra   File: DataJanitorState.java   Source Code and License 6 votes vote down vote up
/**
 * Return regions that were recorded as empty after the given time.
 *
 * @param time time in milliseconds
 * @param includeRegions If not null, the returned set will be an intersection of the includeRegions set
 *                       and the empty regions after the given time
 */
public SortedSet<byte[]> getEmptyRegionsAfterTime(long time, @Nullable SortedSet<byte[]> includeRegions)
  throws IOException {
  SortedSet<byte[]> emptyRegions = new TreeSet<>(Bytes.BYTES_COMPARATOR);
  try (HTableInterface stateTable = stateTableSupplier.get()) {
    Scan scan = new Scan(makeEmptyRegionTimeKey(Bytes.toBytes(time + 1), EMPTY_BYTE_ARRAY),
                         EMPTY_REGION_TIME_KEY_PREFIX_STOP);
    scan.addColumn(FAMILY, EMPTY_REGION_TIME_COL);

    try (ResultScanner scanner = stateTable.getScanner(scan)) {
      Result next;
      while ((next = scanner.next()) != null) {
        byte[] emptyRegion = getEmptyRegionFromKey(next.getRow());
        if (includeRegions == null || includeRegions.contains(emptyRegion)) {
          emptyRegions.add(emptyRegion);
        }
      }
    }
  }
  return Collections.unmodifiableSortedSet(emptyRegions);
}
 
Example 16
Project: incubator-tephra   File: TransactionAwareHTableTest.java   Source Code and License 6 votes vote down vote up
private void verifyRows(HTableInterface table, Get get, List<byte[]> expectedValues) throws Exception {
  Result result = table.get(get);
  if (expectedValues == null) {
    assertTrue(result.isEmpty());
  } else {
    assertFalse(result.isEmpty());
    byte[] family = TestBytes.family;
    byte[] col = TestBytes.qualifier;
    if (get.hasFamilies()) {
      family = get.getFamilyMap().keySet().iterator().next();
      col = get.getFamilyMap().get(family).first();
    }
    Iterator<Cell> it = result.getColumnCells(family, col).iterator();
    for (byte[] expectedValue : expectedValues) {
      Assert.assertTrue(it.hasNext());
      assertArrayEquals(expectedValue, CellUtil.cloneValue(it.next()));
    }
  }
}
 
Example 17
Project: incubator-tephra   File: TransactionAwareHTableTest.java   Source Code and License 6 votes vote down vote up
private void verifyRows(HTableInterface table, Get get, List<byte[]> expectedValues) throws Exception {
  Result result = table.get(get);
  if (expectedValues == null) {
    assertTrue(result.isEmpty());
  } else {
    assertFalse(result.isEmpty());
    byte[] family = TestBytes.family;
    byte[] col = TestBytes.qualifier;
    if (get.hasFamilies()) {
      family = get.getFamilyMap().keySet().iterator().next();
      col = get.getFamilyMap().get(family).first();
    }
    Iterator<Cell> it = result.getColumnCells(family, col).iterator();
    for (byte[] expectedValue : expectedValues) {
      Assert.assertTrue(it.hasNext());
      assertArrayEquals(expectedValue, CellUtil.cloneValue(it.next()));
    }
  }
}
 
Example 18
Project: incubator-tephra   File: SecondaryIndexTable.java   Source Code and License 6 votes vote down vote up
public SecondaryIndexTable(TransactionServiceClient transactionServiceClient, HTableInterface hTable,
                           byte[] secondaryIndex) {
  secondaryIndexTableName = TableName.valueOf(hTable.getName().getNameAsString() + ".idx");
  HTable secondaryIndexHTable = null;
  try (HBaseAdmin hBaseAdmin = new HBaseAdmin(hTable.getConfiguration())) {
    if (!hBaseAdmin.tableExists(secondaryIndexTableName)) {
      hBaseAdmin.createTable(new HTableDescriptor(secondaryIndexTableName));
    }
    secondaryIndexHTable = new HTable(hTable.getConfiguration(), secondaryIndexTableName);
  } catch (Exception e) {
    Throwables.propagate(e);
  }

  this.secondaryIndex = secondaryIndex;
  this.transactionAwareHTable = new TransactionAwareHTable(hTable);
  this.secondaryIndexTable = new TransactionAwareHTable(secondaryIndexHTable);
  this.transactionContext = new TransactionContext(transactionServiceClient, transactionAwareHTable,
                                                   secondaryIndexTable);
}
 
Example 19
Project: incubator-tephra   File: TransactionAwareHTableTest.java   Source Code and License 6 votes vote down vote up
private void verifyRows(HTableInterface table, Get get, List<byte[]> expectedValues) throws Exception {
  Result result = table.get(get);
  if (expectedValues == null) {
    assertTrue(result.isEmpty());
  } else {
    assertFalse(result.isEmpty());
    byte[] family = TestBytes.family;
    byte[] col = TestBytes.qualifier;
    if (get.hasFamilies()) {
      family = get.getFamilyMap().keySet().iterator().next();
      col = get.getFamilyMap().get(family).first();
    }
    Iterator<Cell> it = result.getColumnCells(family, col).iterator();
    for (byte[] expectedValue : expectedValues) {
      Assert.assertTrue(it.hasNext());
      assertArrayEquals(expectedValue, CellUtil.cloneValue(it.next()));
    }
  }
}
 
Example 20
Project: incubator-tephra   File: TransactionAwareHTableTest.java   Source Code and License 6 votes vote down vote up
private void verifyRows(HTableInterface table, Get get, List<byte[]> expectedValues) throws Exception {
  Result result = table.get(get);
  if (expectedValues == null) {
    assertTrue(result.isEmpty());
  } else {
    assertFalse(result.isEmpty());
    byte[] family = TestBytes.family;
    byte[] col = TestBytes.qualifier;
    if (get.hasFamilies()) {
      family = get.getFamilyMap().keySet().iterator().next();
      col = get.getFamilyMap().get(family).first();
    }
    Iterator<Cell> it = result.getColumnCells(family, col).iterator();
    for (byte[] expectedValue : expectedValues) {
      Assert.assertTrue(it.hasNext());
      assertArrayEquals(expectedValue, CellUtil.cloneValue(it.next()));
    }
  }
}
 
Example 21
Project: incubator-tephra   File: HBaseTransactionPruningPlugin.java   Source Code and License 6 votes vote down vote up
@Override
public void initialize(Configuration conf) throws IOException {
  this.conf = conf;
  this.hBaseAdmin = new HBaseAdmin(conf);
  this.connection = HConnectionManager.createConnection(conf);

  final TableName stateTable = TableName.valueOf(conf.get(TxConstants.TransactionPruning.PRUNE_STATE_TABLE,
                                                          TxConstants.TransactionPruning.DEFAULT_PRUNE_STATE_TABLE));
  LOG.info("Initializing plugin with state table {}:{}", stateTable.getNamespaceAsString(),
           stateTable.getNameAsString());
  createPruneTable(stateTable);
  this.dataJanitorState = new DataJanitorState(new DataJanitorState.TableSupplier() {
    @Override
    public HTableInterface get() throws IOException {
      return connection.getTable(stateTable);
    }
  });
}
 
Example 22
Project: QDrill   File: HBasePStore.java   Source Code and License 5 votes vote down vote up
public HBasePStore(PStoreConfig<V> config, HTableInterface table) throws IOException {
  this.tableName = config.getName() + '\0';
  this.tableNameStartKey = Bytes.toBytes(tableName); // "tableName\x00"
  this.tableNameStopKey = this.tableNameStartKey.clone();
  this.tableNameStopKey[tableNameStartKey.length-1] = 1;
  this.config = config;
  this.table = table;
}
 
Example 23
Project: ditb   File: CoprocessorHost.java   Source Code and License 5 votes vote down vote up
/** Clean up the environment */
protected void shutdown() {
  if (state == Coprocessor.State.ACTIVE) {
    state = Coprocessor.State.STOPPING;
    Thread currentThread = Thread.currentThread();
    ClassLoader hostClassLoader = currentThread.getContextClassLoader();
    try {
      currentThread.setContextClassLoader(this.getClassLoader());
      impl.stop(this);
      state = Coprocessor.State.STOPPED;
    } catch (IOException ioe) {
      LOG.error("Error stopping coprocessor "+impl.getClass().getName(), ioe);
    } finally {
      currentThread.setContextClassLoader(hostClassLoader);
    }
  } else {
    LOG.warn("Not stopping coprocessor "+impl.getClass().getName()+
        " because not active (state="+state.toString()+")");
  }
  synchronized (openTables) {
    // clean up any table references
    for (HTableInterface table: openTables) {
      try {
        ((HTableWrapper)table).internalClose();
      } catch (IOException e) {
        // nothing can be done here
        LOG.warn("Failed to close " +
            Bytes.toStringBinary(table.getTableName()), e);
      }
    }
  }
}
 
Example 24
Project: incubator-omid   File: HBaseCellId.java   Source Code and License 5 votes vote down vote up
public HBaseCellId(HTableInterface table, byte[] row, byte[] family, byte[] qualifier, long timestamp) {
    this.timestamp = timestamp;
    this.table = table;
    this.row = row;
    this.family = family;
    this.qualifier = qualifier;
}
 
Example 25
Project: incubator-tephra   File: DataJanitorState.java   Source Code and License 5 votes vote down vote up
/**
 * Save the given region as empty as of the given time.
 *
 * @param time time in milliseconds
 * @param regionId region id
 */
public void saveEmptyRegionForTime(long time, byte[] regionId) throws IOException {
  byte[] timeBytes = Bytes.toBytes(time);
  try (HTableInterface stateTable = stateTableSupplier.get()) {
    Put put = new Put(makeEmptyRegionTimeKey(timeBytes, regionId));
    put.add(FAMILY, EMPTY_REGION_TIME_COL, COL_VAL);
    stateTable.put(put);
  }
}
 
Example 26
Project: incubator-omid   File: HBaseTransaction.java   Source Code and License 5 votes vote down vote up
/**
 * Flushes pending operations for tables touched by transaction
 * @throws IOException in case of any I/O related issues
 */
public void flushTables() throws IOException {

    for (HTableInterface writtenTable : getWrittenTables()) {
        writtenTable.flushCommits();
    }

}
 
Example 27
Project: incubator-omid   File: HBaseTransaction.java   Source Code and License 5 votes vote down vote up
private Set<HTableInterface> getWrittenTables() {
    HashSet<HBaseCellId> writeSet = (HashSet<HBaseCellId>) getWriteSet();
    Set<HTableInterface> tables = new HashSet<HTableInterface>();
    for (HBaseCellId cell : writeSet) {
        tables.add(cell.getTable());
    }
    return tables;
}
 
Example 28
Project: hadooparchitecturebook   File: BasicFraudHBaseService.java   Source Code and License 5 votes vote down vote up
@Override
public void createBulkProfile(ArrayList<ProfileCreatePojo> pojoList)
    throws Exception {
  
  HTableInterface profileTable = hTablePool.getTable(DataModelConsts.PROFILE_TABLE);
  ArrayList<Row> actions = new ArrayList<Row>();
  
  for (ProfileCreatePojo pojo: pojoList) {
    
    
    byte[] rowKey = generateProfileRowKey(pojo.getUserId());
    Put put = new Put(rowKey);
    put.add(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.FIXED_INFO_COL, Bytes.toBytes(pojo.getPojo().getUsername() + "|" + pojo.getPojo().getAge() + "|" + System.currentTimeMillis()));
    put.add(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LOG_IN_IP_ADDERSSES, Bytes.toBytes(pojo.getIpAddress()));
    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 29
Project: hadooparchitecturebook   File: HBaseUtils.java   Source Code and License 5 votes vote down vote up
public static void populateUserProfile(HConnection connection, UserProfile userProfile) throws Exception {
  HTableInterface table = connection.getTable(HBaseTableMetaModel.profileCacheTableName);

  try {
    Put put = new Put(convertKeyToRowKey(HBaseTableMetaModel.profileCacheTableName, userProfile.userId));
    put.add(HBaseTableMetaModel.profileCacheColumnFamily, HBaseTableMetaModel.profileCacheJsonColumn, Bytes.toBytes(userProfile.getJSONObject().toString()));
    put.add(HBaseTableMetaModel.profileCacheColumnFamily, HBaseTableMetaModel.profileCacheTsColumn, Bytes.toBytes(System.currentTimeMillis()));
    table.put(put);
  } finally {
    table.close();
  }
}
 
Example 30
Project: hadooparchitecturebook   File: HBaseUtils.java   Source Code and License 5 votes vote down vote up
public static void populateValidationRules(HConnection connection, ValidationRules rules) throws Exception {
  HTableInterface table = connection.getTable(HBaseTableMetaModel.profileCacheTableName);

  try {
    Put put = new Put(HBaseTableMetaModel.validationRulesRowKey);
    put.add(HBaseTableMetaModel.profileCacheColumnFamily, HBaseTableMetaModel.validationRulesRowKey, Bytes.toBytes(rules.getJSONObject().toString()));
    table.put(put);
  } finally {
    table.close();
  }
}
 
Example 31
Project: incubator-tephra   File: DataJanitorState.java   Source Code and License 5 votes vote down vote up
/**
 * Persist the regions for the given time. {@link HBaseTransactionPruningPlugin} saves the set of
 * transactional regions existing in the HBase instance periodically.
 *
 * @param time timestamp in milliseconds
 * @param regions set of regions at the time
 * @throws IOException when not able to persist the data to HBase
 */
public void saveRegionsForTime(long time, Set<byte[]> regions) throws IOException {
  byte[] timeBytes = Bytes.toBytes(getInvertedTime(time));
  try (HTableInterface stateTable = stateTableSupplier.get()) {
    for (byte[] region : regions) {
      Put put = new Put(makeTimeRegionKey(timeBytes, region));
      put.add(FAMILY, REGION_TIME_COL, COL_VAL);
      stateTable.put(put);
    }

    // Save the count of regions as a checksum
    saveRegionCountForTime(stateTable, timeBytes, regions.size());
  }
}
 
Example 32
Project: incubator-tephra   File: DataJanitorState.java   Source Code and License 5 votes vote down vote up
/**
 * Delete all the regions that were recorded for all times equal or less than the given time.
 *
 * @param time timestamp in milliseconds
 * @throws IOException when not able to delete data in HBase
 */
public void deleteAllRegionsOnOrBeforeTime(long time) throws IOException {
  byte[] timeBytes = Bytes.toBytes(getInvertedTime(time));
  try (HTableInterface stateTable = stateTableSupplier.get()) {
    // Delete the regions
    Scan scan = new Scan(makeTimeRegionKey(timeBytes, EMPTY_BYTE_ARRAY), REGION_TIME_KEY_PREFIX_STOP);
    scan.addColumn(FAMILY, REGION_TIME_COL);
    deleteFromScan(stateTable, scan);

    // Delete the count
    scan = new Scan(makeTimeRegionCountKey(timeBytes), REGION_TIME_COUNT_KEY_PREFIX_STOP);
    scan.addColumn(FAMILY, REGION_TIME_COL);
    deleteFromScan(stateTable, scan);
  }
}
 
Example 33
Project: incubator-tephra   File: DataJanitorState.java   Source Code and License 5 votes vote down vote up
/**
 * Delete all inactive transaction bounds recorded for a time less than the given time
 *
 * @param time time in milliseconds
 * @throws IOException when not able to delete data in HBase
 */
public void deleteInactiveTransactionBoundsOnOrBeforeTime(long time) throws IOException {
  try (HTableInterface stateTable = stateTableSupplier.get()) {
    Scan scan = new Scan(makeInactiveTransactionBoundTimeKey(Bytes.toBytes(getInvertedTime(time))),
                         INACTIVE_TRANSACTION_BOUND_TIME_KEY_PREFIX_STOP);
    scan.addColumn(FAMILY, INACTIVE_TRANSACTION_BOUND_TIME_COL);
    deleteFromScan(stateTable, scan);
  }
}
 
Example 34
Project: incubator-tephra   File: DataJanitorState.java   Source Code and License 5 votes vote down vote up
@VisibleForTesting
void deleteFromScan(HTableInterface stateTable, Scan scan) throws IOException {
  try (ResultScanner scanner = stateTable.getScanner(scan)) {
    Result next;
    while ((next = scanner.next()) != null) {
      stateTable.delete(new Delete(next.getRow()));
    }
  }
}
 
Example 35
Project: incubator-tephra   File: InvalidListPruneTest.java   Source Code and License 5 votes vote down vote up
@BeforeClass
public static void startMiniCluster() throws Exception {
  // Setup the configuration to start HBase cluster with the invalid list pruning enabled
  conf = HBaseConfiguration.create();
  conf.setBoolean(TxConstants.TransactionPruning.PRUNE_ENABLE, true);
  // Flush prune data to table quickly, so that tests don't need have to wait long to see updates
  conf.setLong(TxConstants.TransactionPruning.PRUNE_FLUSH_INTERVAL, 0L);
  AbstractHBaseTableTest.startMiniCluster();

  TransactionStateStorage txStateStorage = new InMemoryTransactionStateStorage();
  TransactionManager txManager = new TransactionManager(conf, txStateStorage, new TxMetricsCollector());
  txManager.startAndWait();

  // Do some transactional data operations
  txDataTable1 = TableName.valueOf("invalidListPruneTestTable1");
  HTable hTable = createTable(txDataTable1.getName(), new byte[][]{family}, false,
                              Collections.singletonList(TestTransactionProcessor.class.getName()));
  try (TransactionAwareHTable txTable = new TransactionAwareHTable(hTable, TxConstants.ConflictDetection.ROW)) {
    TransactionContext txContext = new TransactionContext(new InMemoryTxSystemClient(txManager), txTable);
    txContext.start();
    for (int i = 0; i < MAX_ROWS; ++i) {
      txTable.put(new Put(Bytes.toBytes(i)).add(family, qualifier, Bytes.toBytes(i)));
    }
    txContext.finish();
  }

  testUtil.flush(txDataTable1);
  txManager.stopAndWait();

  pruneStateTable = TableName.valueOf(conf.get(TxConstants.TransactionPruning.PRUNE_STATE_TABLE,
                                               TxConstants.TransactionPruning.DEFAULT_PRUNE_STATE_TABLE));
  connection = HConnectionManager.createConnection(conf);
  dataJanitorState =
    new DataJanitorState(new DataJanitorState.TableSupplier() {
      @Override
      public HTableInterface get() throws IOException {
        return connection.getTable(pruneStateTable);
      }
    });
}
 
Example 36
Project: incubator-tephra   File: DataJanitorState.java   Source Code and License 5 votes vote down vote up
@VisibleForTesting
int getRegionCountForTime(HTableInterface stateTable, long time) throws IOException {
  Get get = new Get(makeTimeRegionCountKey(Bytes.toBytes(getInvertedTime(time))));
  get.addColumn(FAMILY, REGION_TIME_COL);
  Result result = stateTable.get(get);
  byte[] value = result.getValue(FAMILY, REGION_TIME_COL);
  return value == null ? -1 : Bytes.toInt(value);
}
 
Example 37
Project: incubator-tephra   File: DataJanitorState.java   Source Code and License 5 votes vote down vote up
@VisibleForTesting
void deleteFromScan(HTableInterface stateTable, Scan scan) throws IOException {
  try (ResultScanner scanner = stateTable.getScanner(scan)) {
    Result next;
    while ((next = scanner.next()) != null) {
      stateTable.delete(new Delete(next.getRow()));
    }
  }
}
 
Example 38
Project: incubator-tephra   File: TransactionAwareHTableTest.java   Source Code and License 5 votes vote down vote up
private void verifyScan(HTableInterface table, Scan scan, List<KeyValue> expectedCells) throws Exception {
  List<Cell> actualCells = new ArrayList<>();
  try (ResultScanner scanner = table.getScanner(scan)) {
    Result[] results = scanner.next(expectedCells.size() + 1);
    for (Result result : results) {
      actualCells.addAll(Lists.newArrayList(result.rawCells()));
    }
    Assert.assertEquals(expectedCells, actualCells);
  }
}
 
Example 39
Project: incubator-tephra   File: DataJanitorState.java   Source Code and License 5 votes vote down vote up
/**
 * Delete all the regions that were recorded for all times equal or less than the given time.
 *
 * @param time timestamp in milliseconds
 * @throws IOException when not able to delete data in HBase
 */
public void deleteAllRegionsOnOrBeforeTime(long time) throws IOException {
  byte[] timeBytes = Bytes.toBytes(getInvertedTime(time));
  try (HTableInterface stateTable = stateTableSupplier.get()) {
    // Delete the regions
    Scan scan = new Scan(makeTimeRegionKey(timeBytes, EMPTY_BYTE_ARRAY), REGION_TIME_KEY_PREFIX_STOP);
    scan.addColumn(FAMILY, REGION_TIME_COL);
    deleteFromScan(stateTable, scan);

    // Delete the count
    scan = new Scan(makeTimeRegionCountKey(timeBytes), REGION_TIME_COUNT_KEY_PREFIX_STOP);
    scan.addColumn(FAMILY, REGION_TIME_COL);
    deleteFromScan(stateTable, scan);
  }
}
 
Example 40
Project: incubator-tephra   File: DataJanitorState.java   Source Code and License 5 votes vote down vote up
/**
 * Delete empty region records saved on or before the given time.
 *
 * @param time time in milliseconds
 */
public void deleteEmptyRegionsOnOrBeforeTime(long time) throws IOException {
  try (HTableInterface stateTable = stateTableSupplier.get()) {
    Scan scan = new Scan();
    scan.setStopRow(makeEmptyRegionTimeKey(Bytes.toBytes(time + 1), EMPTY_BYTE_ARRAY));
    scan.addColumn(FAMILY, EMPTY_REGION_TIME_COL);
    deleteFromScan(stateTable, scan);
  }
}
 
Example 41
Project: incubator-tephra   File: TransactionAwareHTableTest.java   Source Code and License 5 votes vote down vote up
private void verifyScan(HTableInterface table, Scan scan, List<KeyValue> expectedCells) throws Exception {
  List<Cell> actualCells = new ArrayList<>();
  try (ResultScanner scanner = table.getScanner(scan)) {
    Result[] results = scanner.next(expectedCells.size() + 1);
    for (Result result : results) {
      actualCells.addAll(Lists.newArrayList(result.rawCells()));
    }
    Assert.assertEquals(expectedCells, actualCells);
  }
}
 
Example 42
Project: incubator-tephra   File: TransactionAwareHTableTest.java   Source Code and License 5 votes vote down vote up
private void verifyScan(HTableInterface table, Scan scan, List<KeyValue> expectedCells) throws Exception {
  List<Cell> actualCells = new ArrayList<>();
  try (ResultScanner scanner = table.getScanner(scan)) {
    Result[] results = scanner.next(expectedCells.size() + 1);
    for (Result result : results) {
      actualCells.addAll(Lists.newArrayList(result.rawCells()));
    }
    Assert.assertEquals(expectedCells, actualCells);
  }
}
 
Example 43
Project: incubator-tephra   File: InvalidListPruneTest.java   Source Code and License 5 votes vote down vote up
@BeforeClass
public static void startMiniCluster() throws Exception {
  // Setup the configuration to start HBase cluster with the invalid list pruning enabled
  conf = HBaseConfiguration.create();
  conf.setBoolean(TxConstants.TransactionPruning.PRUNE_ENABLE, true);
  // Flush prune data to table quickly, so that tests don't need have to wait long to see updates
  conf.setLong(TxConstants.TransactionPruning.PRUNE_FLUSH_INTERVAL, 0L);
  AbstractHBaseTableTest.startMiniCluster();

  TransactionStateStorage txStateStorage = new InMemoryTransactionStateStorage();
  TransactionManager txManager = new TransactionManager(conf, txStateStorage, new TxMetricsCollector());
  txManager.startAndWait();

  // Do some transactional data operations
  txDataTable1 = TableName.valueOf("invalidListPruneTestTable1");
  HTable hTable = createTable(txDataTable1.getName(), new byte[][]{family}, false,
                              Collections.singletonList(TestTransactionProcessor.class.getName()));
  try (TransactionAwareHTable txTable = new TransactionAwareHTable(hTable, TxConstants.ConflictDetection.ROW)) {
    TransactionContext txContext = new TransactionContext(new InMemoryTxSystemClient(txManager), txTable);
    txContext.start();
    for (int i = 0; i < MAX_ROWS; ++i) {
      txTable.put(new Put(Bytes.toBytes(i)).add(family, qualifier, Bytes.toBytes(i)));
    }
    txContext.finish();
  }

  testUtil.flush(txDataTable1);
  txManager.stopAndWait();

  pruneStateTable = TableName.valueOf(conf.get(TxConstants.TransactionPruning.PRUNE_STATE_TABLE,
                                               TxConstants.TransactionPruning.DEFAULT_PRUNE_STATE_TABLE));
  connection = HConnectionManager.createConnection(conf);
  dataJanitorState =
    new DataJanitorState(new DataJanitorState.TableSupplier() {
      @Override
      public HTableInterface get() throws IOException {
        return connection.getTable(pruneStateTable);
      }
    });
}
 
Example 44
Project: incubator-tephra   File: InvalidListPruningDebugTool.java   Source Code and License 5 votes vote down vote up
/**
 * Initialize the Invalid List Debug Tool.
 * @param conf {@link Configuration}
 * @throws IOException when not able to create an HBase connection
 */
@Override
@SuppressWarnings("WeakerAccess")
public void initialize(final Configuration conf) throws IOException {
  LOG.debug("InvalidListPruningDebugMain : initialize method called");
  connection = HConnectionManager.createConnection(conf);
  tableName = TableName.valueOf(conf.get(TxConstants.TransactionPruning.PRUNE_STATE_TABLE,
                                         TxConstants.TransactionPruning.DEFAULT_PRUNE_STATE_TABLE));
  dataJanitorState = new DataJanitorState(new DataJanitorState.TableSupplier() {
    @Override
    public HTableInterface get() throws IOException {
      return connection.getTable(tableName);
    }
  });
}
 
Example 45
Project: incubator-tephra   File: DataJanitorState.java   Source Code and License 5 votes vote down vote up
@Nullable
private TimeRegions getNextSetOfTimeRegions(HTableInterface stateTable, long time) throws IOException {
  byte[] timeBytes = Bytes.toBytes(getInvertedTime(time));
  Scan scan = new Scan(makeTimeRegionKey(timeBytes, EMPTY_BYTE_ARRAY), REGION_TIME_KEY_PREFIX_STOP);
  scan.addColumn(FAMILY, REGION_TIME_COL);


  long currentRegionTime = -1;
  SortedSet<byte[]> regions = new TreeSet<>(Bytes.BYTES_COMPARATOR);
  Result next;
  try (ResultScanner scanner = stateTable.getScanner(scan)) {
    while ((next = scanner.next()) != null) {
      Map.Entry<Long, byte[]> timeRegion = getTimeRegion(next.getRow());
      // Stop if reached next time value
      if (currentRegionTime == -1) {
        currentRegionTime = timeRegion.getKey();
      } else if (timeRegion.getKey() < currentRegionTime) {
        break;
      } else if (timeRegion.getKey() > currentRegionTime) {
        throw new IllegalStateException(
          String.format("Got out of order time %d when expecting time less than or equal to %d",
                        timeRegion.getKey(), currentRegionTime));
      }
      regions.add(timeRegion.getValue());
    }
  }
  return regions.isEmpty() ? null : new TimeRegions(currentRegionTime, Collections.unmodifiableSortedSet(regions));
}
 
Example 46
Project: incubator-tephra   File: DataJanitorState.java   Source Code and License 5 votes vote down vote up
/**
 * Delete all inactive transaction bounds recorded for a time less than the given time
 *
 * @param time time in milliseconds
 * @throws IOException when not able to delete data in HBase
 */
public void deleteInactiveTransactionBoundsOnOrBeforeTime(long time) throws IOException {
  try (HTableInterface stateTable = stateTableSupplier.get()) {
    Scan scan = new Scan(makeInactiveTransactionBoundTimeKey(Bytes.toBytes(getInvertedTime(time))),
                         INACTIVE_TRANSACTION_BOUND_TIME_KEY_PREFIX_STOP);
    scan.addColumn(FAMILY, INACTIVE_TRANSACTION_BOUND_TIME_COL);
    deleteFromScan(stateTable, scan);
  }
}
 
Example 47
Project: ditb   File: MultiThreadedWriter.java   Source Code and License 4 votes vote down vote up
protected HTableInterface createTable() throws IOException {
  return connection.getTable(tableName);
}
 
Example 48
Project: ditb   File: MultiThreadedReaderWithACL.java   Source Code and License 4 votes vote down vote up
@Override
protected HTableInterface createTable() throws IOException {
  return null;
}
 
Example 49
Project: ditb   File: MultiThreadedUpdater.java   Source Code and License 4 votes vote down vote up
protected HTableInterface createTable() throws IOException {
  return connection.getTable(tableName);
}
 
Example 50
Project: ditb   File: MultiThreadedUpdaterWithACL.java   Source Code and License 4 votes vote down vote up
@Override
protected HTableInterface createTable() throws IOException {
  return null;
}
 
Example 51
Project: ditb   File: MultiThreadedReader.java   Source Code and License 4 votes vote down vote up
protected HTableInterface createTable() throws IOException {
  return connection.getTable(tableName);
}
 
Example 52
Project: ditb   File: MultiThreadedWriterWithACL.java   Source Code and License 4 votes vote down vote up
@Override
protected HTableInterface createTable() throws IOException {
  return null;
}
 
Example 53
Project: incubator-omid   File: HBaseCellId.java   Source Code and License 4 votes vote down vote up
public HTableInterface getTable() {
    return table;
}
 
Example 54
Project: incubator-omid   File: TTable.java   Source Code and License 4 votes vote down vote up
public TTable(HTableInterface hTable, CommitTable.Client commitTableClient) throws IOException {
    table = hTable;
    healerTable = new HTable(table.getConfiguration(), table.getTableName());
    boolean serverSideFilter = table.getConfiguration().getBoolean("omid.server.side.filter", false);
    snapshotFilter = (serverSideFilter) ?  new AttributeSetSnapshotFilter(hTable) : new SnapshotFilterImpl(new HTableAccessWrapper(hTable, healerTable), commitTableClient);
}
 
Example 55
Project: incubator-omid   File: TTable.java   Source Code and License 4 votes vote down vote up
public TTable(HTableInterface hTable, HTableInterface healerTable, CommitTable.Client commitTableClient) throws IOException {
    table = hTable;
    this.healerTable = healerTable;
    boolean serverSideFilter = table.getConfiguration().getBoolean("omid.server.side.filter", false);
    snapshotFilter = (serverSideFilter) ?  new AttributeSetSnapshotFilter(hTable) : new SnapshotFilterImpl(new HTableAccessWrapper(hTable, healerTable), commitTableClient);
}
 
Example 56
Project: incubator-omid   File: HTableAccessWrapper.java   Source Code and License 4 votes vote down vote up
public HTableAccessWrapper(HTableInterface table, HTableInterface healerTable) {
    this.readTable = table;
    this.writeTable = healerTable;
}
 
Example 57
Project: incubator-omid   File: AttributeSetSnapshotFilter.java   Source Code and License 4 votes vote down vote up
public AttributeSetSnapshotFilter(HTableInterface table) {
    this.table = table;
}
 
Example 58
Project: hadooparchitecturebook   File: BasicFraudHBaseService.java   Source Code and License 4 votes vote down vote up
public ProfilePojo[] getProfilesFromHBase(List<Long> userIds) throws IOException {
  
  ArrayList<Get> getList = new ArrayList<Get>();
  for (Long userId: userIds) {
    getList.add(new Get(generateProfileRowKey(userId)));
  }
  
  HTableInterface profileTable = hTablePool.getTable(DataModelConsts.PROFILE_TABLE);
  Result[] results = profileTable.get(getList);
  
  ProfilePojo[] profiles = new ProfilePojo[getList.size()];
  
  int counter = 0;
  for (Result result: results) {
    
    String[] fixedInfoValues = Bytes.toString(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.FIXED_INFO_COL).getValue()).split("|");
    String username = fixedInfoValues[0];
    int age = Integer.parseInt(fixedInfoValues[1]);
    long firstLogIn = Long.parseLong(fixedInfoValues[2]);
    
    long lastLogIn = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LAST_LOG_IN_COL).getValue());
    long logInCount = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LOG_IN_COUNT_COL).getValue());
    
    long logInCountHavingASell = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_SELLS_COL).getValue());
    long logInCountHavingAPurchase = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_PURCHASES_COL).getValue());
    
    long totalValueOfPastPurchases = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_VALUE_OF_PAST_PURCHASES_COL).getValue());
    long totalValueOfPastSells = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_VALUE_OF_PAST_SELLS_COL).getValue());
    
    long currentLogInSellsValue = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.CURRENT_LOG_IN_SELLS_VALUE_COL).getValue());
    long currentLogInPurchasesValue = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.CURRENT_LOG_IN_PURCHASES_VALUE_COL).getValue());
    
    HashSet<String> last20LogOnIpAddresses = new HashSet<String>();
    
    List<KeyValue> ipAddresses = result.getColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LOG_IN_IP_ADDERSSES);
    boolean isFirst = true;
    String lastLogInIpAddress = null;
    
    for (KeyValue kv: ipAddresses) {
      if (isFirst) {
        isFirst = false;
        lastLogInIpAddress = Bytes.toString(kv.getValue());
      } else {
        last20LogOnIpAddresses.add(Bytes.toString(kv.getValue()));
      }
    }
    
    ProfilePojo pojo = new ProfilePojo(username, age, firstLogIn, lastLogIn, lastLogInIpAddress,
    logInCount, logInCountHavingASell, totalValueOfPastSells,
    currentLogInSellsValue, logInCountHavingAPurchase,
    totalValueOfPastPurchases, currentLogInPurchasesValue,
    last20LogOnIpAddresses);
    
    profiles[counter++] = pojo;
  }
  
  return profiles;
}
 
Example 59
Project: incubator-tephra   File: TransactionAwareHTableTest.java   Source Code and License 4 votes vote down vote up
private void verifyRow(HTableInterface table, byte[] rowkey, byte[] expectedValue) throws Exception {
  verifyRow(table, new Get(rowkey), expectedValue);
}
 
Example 60
Project: incubator-tephra   File: TransactionAwareHTableTest.java   Source Code and License 4 votes vote down vote up
private void verifyRow(HTableInterface table, Get get, byte[] expectedValue) throws Exception {
  verifyRows(table, get, expectedValue == null ? null : ImmutableList.of(expectedValue));
}