Java 类org.apache.hadoop.hbase.client.HTableInterface 实例源码
项目:SparkDemo
文件:MyClass.java
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();
}
}
项目:SparkIsax
文件:HBaseUtils.java
/**
* 拷贝表
*
* @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();
}
项目:incubator-tephra
文件:DataJanitorStateTest.java
@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);
}
});
}
项目:hadooparchitecturebook
文件:BasicFraudHBaseService.java
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);
}
项目:hadooparchitecturebook
文件:BasicFraudHBaseService.java
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);
}
项目:hadooparchitecturebook
文件:BasicFraudHBaseService.java
@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);
}
项目:incubator-tephra
文件:SecondaryIndexTable.java
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);
}
项目:incubator-tephra
文件:TransactionAwareHTableTest.java
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()));
}
}
}
项目:incubator-tephra
文件:DataJanitorState.java
/**
* 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;
}
}
项目:incubator-tephra
文件:HBaseTransactionPruningPlugin.java
@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);
}
});
}
项目:incubator-tephra
文件:DataJanitorState.java
/**
* 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);
}
项目:incubator-tephra
文件:DataJanitorState.java
/**
* 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()));
}
}
}
}
}
}
}
项目:incubator-tephra
文件:DataJanitorState.java
/**
* 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;
}
}
项目:incubator-tephra
文件:DataJanitorState.java
/**
* 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);
}
项目:incubator-tephra
文件:DataJanitorState.java
/**
* 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);
}
项目:incubator-tephra
文件:TransactionAwareHTableTest.java
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()));
}
}
}
项目:incubator-tephra
文件:TransactionAwareHTableTest.java
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()));
}
}
}
项目:incubator-tephra
文件:SecondaryIndexTable.java
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);
}
项目:incubator-tephra
文件:TransactionAwareHTableTest.java
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()));
}
}
}
项目:incubator-tephra
文件:TransactionAwareHTableTest.java
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()));
}
}
}
项目:incubator-tephra
文件:HBaseTransactionPruningPlugin.java
@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);
}
});
}
项目:QDrill
文件:HBasePStore.java
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;
}
项目:ditb
文件:CoprocessorHost.java
/** 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);
}
}
}
}
项目:incubator-omid
文件:HBaseCellId.java
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;
}
项目:incubator-tephra
文件:DataJanitorState.java
/**
* 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);
}
}
项目:incubator-omid
文件:HBaseTransaction.java
/**
* 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();
}
}
项目:incubator-omid
文件:HBaseTransaction.java
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;
}
项目:hadooparchitecturebook
文件:BasicFraudHBaseService.java
@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);
}
项目:hadooparchitecturebook
文件:HBaseUtils.java
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();
}
}
项目:hadooparchitecturebook
文件:HBaseUtils.java
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();
}
}
项目:incubator-tephra
文件:DataJanitorState.java
/**
* 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());
}
}
项目:incubator-tephra
文件:DataJanitorState.java
/**
* 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);
}
}
项目:incubator-tephra
文件:DataJanitorState.java
/**
* 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);
}
}
项目:incubator-tephra
文件:DataJanitorState.java
@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()));
}
}
}
项目:incubator-tephra
文件:InvalidListPruneTest.java
@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);
}
});
}
项目:incubator-tephra
文件:DataJanitorState.java
@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);
}
项目:incubator-tephra
文件:DataJanitorState.java
@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()));
}
}
}
项目:incubator-tephra
文件:TransactionAwareHTableTest.java
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);
}
}
项目:incubator-tephra
文件:DataJanitorState.java
/**
* 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);
}
}
项目:incubator-tephra
文件:DataJanitorState.java
/**
* 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);
}
}