Hbase CopyTable 里面 Java
Hbase CopyTable inside Java
我想把一个Hbasetable复制到另一个性能好的地方
中重用 CopyTable.java 中的代码
我一直在寻找 hbase 的文档,但它对我帮助不大 http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/mapreduce/CopyTable.html
查看这个 post 的 Whosebug 后:Can a main() method of class be invoked in another class in java
我想我可以直接使用它的 main class 来调用它。
问题:您认为完成此副本比使用 hbase-server 中的 CopyTable 更好吗?您认为使用此 CopyTable 有任何不便吗?
Question: Do you think anyway better to get this copy done rather than
using CopyTable from hbase-server ? Do you see any inconvenience using
this CopyTable ?
First thing is snapshot is better way than CopyTable
.
- HBase 快照允许您拍摄 table 的快照,而不会对区域服务器造成太大影响。快照、克隆和恢复操作不涉及数据复制。此外,将快照导出到另一个集群不会对区域服务器产生影响。
在0.94.6版本之前,备份或克隆table的唯一方法是使用CopyTable/ExportTable,或者在禁用[=76=后复制HDFS中的所有hfiles ].这些方法的缺点是您可以降低区域服务器性能(Copy/Export Table)或者您需要禁用 table,这意味着没有读取或写入;这通常是 unacceptable.
- Snapshot is not just rename, between multiple operations if you want to restore at one particular point then this is the right case to use :
快照是一组元数据信息,允许管理员返回到 table 的先前状态。快照不是 table 的副本;它只是一个文件名列表,不会复制数据。完整的快照还原意味着您返回到之前的“table 模式”,并且您恢复到之前的数据丢失了自拍摄快照以来所做的任何更改。
另外,参见 Snapshots+and+Repeatable+reads+for+HBase+Tables
另一种 Map reduce 方式比 CopyTable
:
您可以在您的代码中实现类似下面的内容,这是针对独立程序的,因为您编写了 mapreduce 作业以批量插入多个放置记录(可能是 100000)。
这提高了独立插入到 hbase 客户端的性能,您可以以 mapreduce 方式尝试这个
public void addMultipleRecordsAtaShot(final ArrayList<Put> puts, final String tableName) throws Exception {
try {
final HTable table = new HTable(HBaseConnection.getHBaseConfiguration(), getTable(tableName));
table.put(puts);
LOG.info("INSERT record[s] " + puts.size() + " to table " + tableName + " OK.");
} catch (final Throwable e) {
e.printStackTrace();
} finally {
LOG.info("Processed ---> " + puts.size());
if (puts != null) {
puts.clear();
}
}
}
除此之外,您还可以考虑以下...
启用比默认值大的写入缓冲区
1) table.setAutoFlush(false)
2) 设置缓冲区大小
<property>
<name>hbase.client.write.buffer</name>
<value>20971520</value> // you can double this for better performance 2 x 20971520 = 41943040
</property>
OR
void setWriteBufferSize(long writeBufferSize) throws IOException
缓冲区只会被刷新两次:
显式同花顺
使用 flushCommits()
调用将数据发送到服务器进行永久存储。
隐式同花顺
当您调用 put()
或 setWriteBufferSize()
时会触发此事件。
这两个调用都将当前使用的缓冲区大小与配置的限制进行比较,并可选择调用 flushCommits()
方法。
如果整个缓冲区被禁用,设置 setAutoFlush(true)
将强制客户端在每次调用 put()
.
时调用 flush 方法
我想把一个Hbasetable复制到另一个性能好的地方
中重用 CopyTable.java 中的代码我一直在寻找 hbase 的文档,但它对我帮助不大 http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/mapreduce/CopyTable.html
查看这个 post 的 Whosebug 后:Can a main() method of class be invoked in another class in java
我想我可以直接使用它的 main class 来调用它。
问题:您认为完成此副本比使用 hbase-server 中的 CopyTable 更好吗?您认为使用此 CopyTable 有任何不便吗?
Question: Do you think anyway better to get this copy done rather than using CopyTable from hbase-server ? Do you see any inconvenience using this CopyTable ?
First thing is snapshot is better way than CopyTable
.
- HBase 快照允许您拍摄 table 的快照,而不会对区域服务器造成太大影响。快照、克隆和恢复操作不涉及数据复制。此外,将快照导出到另一个集群不会对区域服务器产生影响。
在0.94.6版本之前,备份或克隆table的唯一方法是使用CopyTable/ExportTable,或者在禁用[=76=后复制HDFS中的所有hfiles ].这些方法的缺点是您可以降低区域服务器性能(Copy/Export Table)或者您需要禁用 table,这意味着没有读取或写入;这通常是 unacceptable.
- Snapshot is not just rename, between multiple operations if you want to restore at one particular point then this is the right case to use : 快照是一组元数据信息,允许管理员返回到 table 的先前状态。快照不是 table 的副本;它只是一个文件名列表,不会复制数据。完整的快照还原意味着您返回到之前的“table 模式”,并且您恢复到之前的数据丢失了自拍摄快照以来所做的任何更改。
另外,参见 Snapshots+and+Repeatable+reads+for+HBase+Tables
另一种 Map reduce 方式比 CopyTable
:
您可以在您的代码中实现类似下面的内容,这是针对独立程序的,因为您编写了 mapreduce 作业以批量插入多个放置记录(可能是 100000)。
这提高了独立插入到 hbase 客户端的性能,您可以以 mapreduce 方式尝试这个
public void addMultipleRecordsAtaShot(final ArrayList<Put> puts, final String tableName) throws Exception {
try {
final HTable table = new HTable(HBaseConnection.getHBaseConfiguration(), getTable(tableName));
table.put(puts);
LOG.info("INSERT record[s] " + puts.size() + " to table " + tableName + " OK.");
} catch (final Throwable e) {
e.printStackTrace();
} finally {
LOG.info("Processed ---> " + puts.size());
if (puts != null) {
puts.clear();
}
}
}
除此之外,您还可以考虑以下...
启用比默认值大的写入缓冲区
1) table.setAutoFlush(false)
2) 设置缓冲区大小
<property>
<name>hbase.client.write.buffer</name>
<value>20971520</value> // you can double this for better performance 2 x 20971520 = 41943040
</property>
OR
void setWriteBufferSize(long writeBufferSize) throws IOException
缓冲区只会被刷新两次:
显式同花顺
使用 flushCommits()
调用将数据发送到服务器进行永久存储。
隐式同花顺
当您调用 put()
或 setWriteBufferSize()
时会触发此事件。
这两个调用都将当前使用的缓冲区大小与配置的限制进行比较,并可选择调用 flushCommits()
方法。
如果整个缓冲区被禁用,设置 setAutoFlush(true)
将强制客户端在每次调用 put()
.