org.apache.hadoop.hbase.regionserver.HStore.compact()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(183)

本文整理了Java中org.apache.hadoop.hbase.regionserver.HStore.compact()方法的一些代码示例,展示了HStore.compact()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HStore.compact()方法的具体详情如下:
包路径:org.apache.hadoop.hbase.regionserver.HStore
类名称:HStore
方法名:compact

HStore.compact介绍

[英]Compact the StoreFiles. This method may take some time, so the calling thread must be able to block for long periods.

During this time, the Store can work as usual, getting values from StoreFiles and writing new StoreFiles from the memstore. Existing StoreFiles are not destroyed until the new compacted StoreFile is completely written-out to disk.

The compactLock prevents multiple simultaneous compactions. The structureLock prevents us from interfering with other write operations.

We don't want to hold the structureLock for the whole time, as a compact() can be lengthy and we want to allow cache-flushes during this period.

Compaction event should be idempotent, since there is no IO Fencing for the region directory in hdfs. A region server might still try to complete the compaction after it lost the region. That is why the following events are carefully ordered for a compaction: 1. Compaction writes new files under region/.tmp directory (compaction output) 2. Compaction atomically moves the temporary file under region directory 3. Compaction appends a WAL edit containing the compaction input and output files. Forces sync on WAL. 4. Compaction deletes the input files from the region directory. Failure conditions are handled like this: - If RS fails before 2, compaction wont complete. Even if RS lives on and finishes the compaction later, it will only write the new data file to the region directory. Since we already have this data, this will be idempotent but we will have a redundant copy of the data. - If RS fails between 2 and 3, the region will have a redundant copy of the data. The RS that failed won't be able to finish snyc() for WAL because of lease recovery in WAL. - If RS fails after 3, the region region server who opens the region will pick up the the compaction marker from the WAL and replay it by removing the compaction input files. Failed RS can also attempt to delete those files, but the operation will be idempotent See HBASE-2231 for details.
[中]压缩存储文件。此方法可能需要一些时间,因此调用线程必须能够长时间阻塞。
在此期间,存储可以像往常一样工作,从StoreFiles获取值并从memstore写入新的StoreFiles。在新压缩的StoreFile完全写入磁盘之前,不会销毁现有的StoreFile。
compactLock可防止多个同时压缩。structureLock防止我们干扰其他写入操作。
我们不希望一直保持structureLock,因为compact()可能很长,我们希望在此期间允许缓存刷新。
压缩事件应该是幂等的,因为hdfs中的区域目录没有IO防护。区域服务器在丢失区域后仍可能尝试完成压缩。这就是为什么要为压缩仔细排序以下事件:1。压缩在region/下写入新文件。tmp目录(压缩输出)2。压缩以原子方式将临时文件移动到区域目录3下。压缩附加包含压缩输入和输出文件的WAL编辑。强制同步沃尔。4.压缩从区域目录中删除输入文件。失效条件的处理如下:-如果RS在2之前失效,压实将无法完成。即使RS继续存在并稍后完成压缩,它也只会将新数据文件写入区域目录。因为我们已经有了这些数据,这将是幂等的,但我们将有一个冗余的数据副本。-如果RS在2到3之间出现故障,则该区域将有一个冗余的数据副本。失败的RS将无法为WAL完成snyc(),因为WAL的租赁恢复。-如果RS在3之后失败,则打开区域的区域服务器将从WAL中拾取压缩标记,并通过删除压缩输入文件进行重播。失败的RS也可以尝试删除这些文件,但操作将是幂等的。有关详细信息,请参阅HBASE-2231。

代码示例

代码示例来源:origin: apache/hbase

store.compact(compaction.get(), NoLimitThroughputController.INSTANCE, null);
if (storeFiles != null && !storeFiles.isEmpty()) {
 if (deleteCompacted) {

代码示例来源:origin: apache/hbase

store.compact(compaction, throughputController, user);
} catch (InterruptedIOException iioe) {
 String msg = "compaction interrupted";

代码示例来源:origin: apache/hbase

@Test
public void testLowestModificationTime() throws Exception {
 Configuration conf = HBaseConfiguration.create();
 FileSystem fs = FileSystem.get(conf);
 // Initialize region
 init(name.getMethodName(), conf);
 int storeFileNum = 4;
 for (int i = 1; i <= storeFileNum; i++) {
  LOG.info("Adding some data for the store file #"+i);
  this.store.add(new KeyValue(row, family, qf1, i, (byte[])null), null);
  this.store.add(new KeyValue(row, family, qf2, i, (byte[])null), null);
  this.store.add(new KeyValue(row, family, qf3, i, (byte[])null), null);
  flush(i);
 }
 // after flush; check the lowest time stamp
 long lowestTimeStampFromManager = StoreUtils.getLowestTimestamp(store.getStorefiles());
 long lowestTimeStampFromFS = getLowestTimeStampFromFS(fs, store.getStorefiles());
 assertEquals(lowestTimeStampFromManager,lowestTimeStampFromFS);
 // after compact; check the lowest time stamp
 store.compact(store.requestCompaction().get(), NoLimitThroughputController.INSTANCE, null);
 lowestTimeStampFromManager = StoreUtils.getLowestTimestamp(store.getStorefiles());
 lowestTimeStampFromFS = getLowestTimeStampFromFS(fs, store.getStorefiles());
 assertEquals(lowestTimeStampFromManager, lowestTimeStampFromFS);
}

代码示例来源:origin: harbby/presto-connectors

public List<StoreFile> compact(CompactionContext compaction,
  CompactionThroughputController throughputController) throws IOException {
 return compact(compaction, throughputController, null);

代码示例来源:origin: org.apache.hbase/hbase-mapreduce

store.compact(compaction.get(), NoLimitThroughputController.INSTANCE, null);
if (storeFiles != null && !storeFiles.isEmpty()) {
 if (deleteCompacted) {

代码示例来源:origin: com.aliyun.hbase/alihbase-mapreduce

store.compact(compaction.get(), NoLimitThroughputController.INSTANCE, null);
if (storeFiles != null && !storeFiles.isEmpty()) {
 if (deleteCompacted) {

代码示例来源:origin: harbby/presto-connectors

/**
 * Execute the actual compaction job.
 * If the compact once flag is not specified, execute the compaction until
 * no more compactions are needed. Uses the Configuration settings provided.
 */
private void compactStoreFiles(final Path tableDir, final HTableDescriptor htd,
  final HRegionInfo hri, final String familyName, final boolean compactOnce,
  final boolean major) throws IOException {
 HStore store = getStore(conf, fs, tableDir, htd, hri, familyName, tmpDir);
 LOG.info("Compact table=" + htd.getTableName() +
  " region=" + hri.getRegionNameAsString() +
  " family=" + familyName);
 if (major) {
  store.triggerMajorCompaction();
 }
 do {
  CompactionContext compaction = store.requestCompaction(Store.PRIORITY_USER, null);
  if (compaction == null) break;
  List<StoreFile> storeFiles =
    store.compact(compaction, NoLimitCompactionThroughputController.INSTANCE);
  if (storeFiles != null && !storeFiles.isEmpty()) {
   if (keepCompactedFiles && deleteCompacted) {
    for (StoreFile storeFile: storeFiles) {
     fs.delete(storeFile.getPath(), false);
    }
   }
  }
 } while (store.needsCompaction() && !compactOnce);
}

代码示例来源:origin: org.apache.hbase/hbase-server

@Test
public void testLowestModificationTime() throws Exception {
 Configuration conf = HBaseConfiguration.create();
 FileSystem fs = FileSystem.get(conf);
 // Initialize region
 init(name.getMethodName(), conf);
 int storeFileNum = 4;
 for (int i = 1; i <= storeFileNum; i++) {
  LOG.info("Adding some data for the store file #"+i);
  this.store.add(new KeyValue(row, family, qf1, i, (byte[])null), null);
  this.store.add(new KeyValue(row, family, qf2, i, (byte[])null), null);
  this.store.add(new KeyValue(row, family, qf3, i, (byte[])null), null);
  flush(i);
 }
 // after flush; check the lowest time stamp
 long lowestTimeStampFromManager = StoreUtils.getLowestTimestamp(store.getStorefiles());
 long lowestTimeStampFromFS = getLowestTimeStampFromFS(fs, store.getStorefiles());
 assertEquals(lowestTimeStampFromManager,lowestTimeStampFromFS);
 // after compact; check the lowest time stamp
 store.compact(store.requestCompaction().get(), NoLimitThroughputController.INSTANCE, null);
 lowestTimeStampFromManager = StoreUtils.getLowestTimestamp(store.getStorefiles());
 lowestTimeStampFromFS = getLowestTimeStampFromFS(fs, store.getStorefiles());
 assertEquals(lowestTimeStampFromManager, lowestTimeStampFromFS);
}

相关文章

HStore类方法