當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。