当前位置: 首页>>代码示例>>Java>>正文


Java Cell.getFamily方法代码示例

本文整理汇总了Java中org.apache.hadoop.hbase.Cell.getFamily方法的典型用法代码示例。如果您正苦于以下问题:Java Cell.getFamily方法的具体用法?Java Cell.getFamily怎么用?Java Cell.getFamily使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.hbase.Cell的用法示例。


在下文中一共展示了Cell.getFamily方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: preWALWrite

import org.apache.hadoop.hbase.Cell; //导入方法依赖的package包/类
@Override
public boolean preWALWrite(ObserverContext<? extends WALCoprocessorEnvironment> env,
    HRegionInfo info, WALKey logKey, WALEdit logEdit) throws IOException {
  boolean bypass = false;
  // check table name matches or not.
  if (!Bytes.equals(info.getTableName(), this.tableName)) {
    return bypass;
  }
  preWALWriteCalled = true;
  // here we're going to remove one keyvalue from the WALEdit, and add
  // another one to it.
  List<Cell> cells = logEdit.getCells();
  Cell deletedCell = null;
  for (Cell cell : cells) {
    // assume only one kv from the WALEdit matches.
    byte[] family = cell.getFamily();
    byte[] qulifier = cell.getQualifier();

    if (Arrays.equals(family, ignoredFamily) &&
        Arrays.equals(qulifier, ignoredQualifier)) {
      LOG.debug("Found the KeyValue from WALEdit which should be ignored.");
      deletedCell = cell;
    }
    if (Arrays.equals(family, changedFamily) &&
        Arrays.equals(qulifier, changedQualifier)) {
      LOG.debug("Found the KeyValue from WALEdit which should be changed.");
      cell.getValueArray()[cell.getValueOffset()] += 1;
    }
  }
  if (null != row) {
    cells.add(new KeyValue(row, addedFamily, addedQualifier));
  }
  if (deletedCell != null) {
    LOG.debug("About to delete a KeyValue from WALEdit.");
    cells.remove(deletedCell);
  }
  return bypass;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:39,代码来源:SampleRegionWALObserver.java

示例2: testSecureWAL

import org.apache.hadoop.hbase.Cell; //导入方法依赖的package包/类
@Test
public void testSecureWAL() throws Exception {
  TableName tableName = TableName.valueOf("TestSecureWAL");
  HTableDescriptor htd = new HTableDescriptor(tableName);
  htd.addFamily(new HColumnDescriptor(tableName.getName()));
  HRegionInfo regioninfo = new HRegionInfo(tableName,
    HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW, false);
  final int total = 10;
  final byte[] row = Bytes.toBytes("row");
  final byte[] family = Bytes.toBytes("family");
  final byte[] value = Bytes.toBytes("Test value");
  FileSystem fs = TEST_UTIL.getTestFileSystem();
  final WALFactory wals = new WALFactory(TEST_UTIL.getConfiguration(), null, "TestSecureWAL");

  // Write the WAL
  final WAL wal = wals.getWAL(regioninfo.getEncodedNameAsBytes());

  for (int i = 0; i < total; i++) {
    WALEdit kvs = new WALEdit();
    kvs.add(new KeyValue(row, family, Bytes.toBytes(i), value));
    wal.append(htd, regioninfo, new WALKey(regioninfo.getEncodedNameAsBytes(), tableName,
        System.currentTimeMillis()), kvs, true);
  }
  wal.sync();
  final Path walPath = DefaultWALProvider.getCurrentFileName(wal);
  wals.shutdown();

  // Insure edits are not plaintext
  long length = fs.getFileStatus(walPath).getLen();
  FSDataInputStream in = fs.open(walPath);
  byte[] fileData = new byte[(int)length];
  IOUtils.readFully(in, fileData);
  in.close();
  assertFalse("Cells appear to be plaintext", Bytes.contains(fileData, value));

  // Confirm the WAL can be read back
  WAL.Reader reader = wals.createReader(TEST_UTIL.getTestFileSystem(), walPath);
  int count = 0;
  WAL.Entry entry = new WAL.Entry();
  while (reader.next(entry) != null) {
    count++;
    List<Cell> cells = entry.getEdit().getCells();
    assertTrue("Should be one KV per WALEdit", cells.size() == 1);
    for (Cell cell: cells) {
      byte[] thisRow = cell.getRow();
      assertTrue("Incorrect row", Bytes.equals(thisRow, row));
      byte[] thisFamily = cell.getFamily();
      assertTrue("Incorrect family", Bytes.equals(thisFamily, family));
      byte[] thisValue = cell.getValue();
      assertTrue("Incorrect value", Bytes.equals(thisValue, value));
    }
  }
  assertEquals("Should have read back as many KVs as written", total, count);
  reader.close();
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:56,代码来源:TestSecureWAL.java


注:本文中的org.apache.hadoop.hbase.Cell.getFamily方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。