Java 类org.apache.hadoop.hbase.io.hfile.HFileWriterV3 实例源码

项目:Megh    文件:HadoopFilePerformanceTest.java   
public void writeHFile(Path file, Compression.Algorithm compression) throws Exception
{

  CacheConfig cacheConf = new CacheConfig(conf);
  cacheConf.shouldEvictOnClose();
  FSDataOutputStream fos = hdfs.create(file);
  KeyValue.KVComparator comparator = new KeyValue.RawBytesComparator();

  HFileContext context = new HFileContextBuilder()
      .withBlockSize(blockSize)
      .withCompression(compression)
      .build();

  logger.debug("context.getBlockSize(): {}", context.getBlocksize());
  logger.debug("context.getCompression(): {}", context.getCompression());
  logger.debug("context.getDataBlockEncoding(): {}", context.getDataBlockEncoding());
  logger.debug("context.getBytesPerChecksum(): {}", context.getBytesPerChecksum());

  HFile.Writer writer = new HFileWriterV3(conf, cacheConf, hdfs, file, fos, comparator, context);

  for (int i = 0; i < testSize; i++) {
    writer.append(getKey(i).getBytes(), getValue().getBytes());
    //logger.debug("fos.getPos(): {}", fos.getPos() );
  }

  //writer.appendFileInfo(StoreFile.MAJOR_COMPACTION_KEY, Bytes.toBytes(true));
  writer.close();
}