首批通过分布式安全可靠测评,为关键业务系统打造
与 HBase 的兼容性
更新时间:2025-03-18 17:12:40
接口兼容性
OBKV-HBase 客户端实现了 HTableInterface 的接口,其接口的兼容性如下。
| Modifier and Type | Method and Description | 兼容性 |
|---|---|---|
| Result | append (Append append) Appends values to one or more columns within a single row. | 支持 |
| Object[] | batch(List<? extends Row> actions) Same as batch(List, Object[]), but returns an array of results instead of using a results parameter reference. |
不支持 |
| void | batch(List<? extends Row> actions, Object[] results) Method that does a batch call on Deletes, Gets, Puts, Increments, Appends and RowMutations. | 不支持 |
| boolean | checkAndDelete (byte[] row, byte[] family, byte[] qualifier, byte[] value,Delete delete) Atomically checks if a row/family/qualifier value matches the expected value. |
支持 |
| boolean | checkAndPut (byte[] row, byte[] family, byte[] qualifier, byte[] value, Put put) Atomically checks if a row/family/qualifier value matches the expected value. |
支持 |
| void | close() Releases any resources help or pending changes in internal buffers. | 支持 |
| <T extends CoprocessorProtocol,R>Map<byte[],R> | coprocessorExec(Class |
不支持 |
| <T extends CoprocessorProtocol,R> void | coprocessorExec(Class |
不支持 |
| <T extends CoprocessorProtocol > T | coprocessorProxy(Class |
不支持 |
| void | delete(Delete delete) Deletes the specified cells/row. | 支持 |
| void | delete(List<Delete> deletes) Deletes the specified cells/rows in bulk. | 支持 |
| boolean | exists(Get get) Test for the existence of columns in the table, as specified in the Get. | 支持 |
| void | flushCommits() Executes all the buffered Put operations. | 支持 |
| Result | get(Get get) Extracts certain cells from a given row. | 支持 |
| Result[] | get(List<Get> gets) Extracts certain cells from the given rows, in batch. | 支持 |
| org.apache.hadoop.conf.Configuration | getConfiguration() Returns the Returns the Configuration object used by this instance. | 支持 |
| Result | getRowOrBefore(byte[] row, byte[] family) Deprecated. As of version 0.92 this method is deprecated without replacement. getRowOrBefore is used internally to find entries in .META. and makes various assumptions about the table (which are true for .META. but not in general) to be efficient. | Deprecated |
| ResultScanner | getScanner(byte[] family) Gets a scanner on the current table for the given family. | 支持 |
| ResultScanner | getScanner(byte[] family, byte[] qualifier) Gets a scanner on the current table for the given family and qualifier. | 支持 |
| ResultScanner | getScanner(Scan scan) Returns a scanner on the current table as specified by the Scan object. | 支持 |
| HTableDescriptor | getTableDescriptor() Gets the table descriptor for this table. | 不支持 |
| byte[] | getTableName() Gets the name of this table. | 支持 |
| long | getWriteBufferSize() Returns the maximum size in bytes of the write buffer for this HTable. | 支持 |
| Result | increment(Increment increment) Increments one or more columns within a single row. | 支持 |
| long | incrementColumnValue(byte[] row, byte[] family, byte[] qualifier, long amount) Atomically increments a column value. | 支持 |
| long | incrementColumnValue(byte[] row, byte[] family, byte[] qualifier, long amount, Durability durability) Atomically increments a column value. | 支持 |
| boolean | isAutoFlush() Tells whether or not 'auto-flush' is turned on. | 支持 |
| RowLock | lockRow(byte[] row) RowLock and associated operations are deprecated | Deprecated |
| void | mutateRow(RowMutations rm) Performs multiple mutations atomically on a single row. | 不支持 |
| void | put(List<Put> puts) Puts some data in the table, in batch. | 支持 |
| void | put(Put put) Puts some data in the table. | 支持 |
| void | setAutoFlush(boolean autoFlush) See setAutoFlush(boolean, boolean) | 支持 |
| void | setAutoFlush(boolean autoFlush, boolean clearBufferOnFail) Turns 'auto-flush' on or off. | 支持 |
| void | setWriteBufferSize(long writeBufferSize) Sets the size of the buffer in bytes. | 支持 |
| void | unlockRow(RowLock rl) RowLock and associated operations are deprecated | Deprecated |
接口使用上的差别
因为架构实现上的差异,开源 HBase的代码迁移到 OBKV-HBase,需要调整一些配置代码。
开源 HBase 和 OBKV-HBase 数据访问代码没有变化,数据访问部分兼容。不同点主要在:
- Configuration:开源 HBase 和 OBKV-HBase 架构不同,配置项也不同。
- OHTableClient:需要基于 OBKV-HBase 的句柄来做数据访问。
如下面例子。
开源 HBase 的代码:
public class HBaseInsertDemo {
public static void main(String[] args) throws Exception {
// 配置HBase
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", "your_zookeeper_quorum"); // 设置ZooKeeper地址
conf.set("hbase.zookeeper.property.clientPort", "2181"); // 设置ZooKeeper端口
// 拿到Table句柄
TableName tableName = TableName.valueOf("your_table_name");
HTable table =new HTable(tableName, conf);
// 准备插入数据
Put put = new Put(Bytes.toBytes("row_key"));
put.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qualifier"), Bytes.toBytes("value")); // 列族,列标识符,值
table.put(put);
// 关闭资源
table.close();
System.out.println("数据插入成功!");
}
}
OBKV-HBase 的代码:
public class OBHBaseInsertDemo {
public static void main(String[] args) throws Exception {
// 配置HBase
Configuration conf = new Configuration();
conf.set(HBASE_OCEANBASE_FULL_USER_NAME, "");
conf.set(HBASE_OCEANBASE_PASSWORD, "");
conf.set(HBASE_OCEANBASE_PARAM_URL, "");
conf.set(HBASE_OCEANBASE_SYS_USER_NAME, "");
conf.set(HBASE_OCEANBASE_SYS_PASSWORD, "");
// 拿到Table句柄
TableName tableName = TableName.valueOf("your_table_name");
OHTableClient table = new OHTableClient(tableName, conf); // 创建 htable对象
// 准备插入数据
Put put = new Put(Bytes.toBytes("row_key"));
put.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qualifier"), Bytes.toBytes("value")); // 列族,列标识符,值
table.put(put);
// 关闭资源
table.close();
System.out.println("数据插入成功!");
}
}