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


Java Writables类代码示例

本文整理汇总了Java中org.apache.hadoop.hbase.util.Writables的典型用法代码示例。如果您正苦于以下问题:Java Writables类的具体用法?Java Writables怎么用?Java Writables使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Writables类属于org.apache.hadoop.hbase.util包,在下文中一共展示了Writables类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: nodeDataChanged

import org.apache.hadoop.hbase.util.Writables; //导入依赖的package包/类
@Override
public void nodeDataChanged(String path) {
  if (keysParentZNode.equals(ZKUtil.getParent(path))) {
    try {
      byte[] data = ZKUtil.getDataAndWatch(watcher, path);
      if (data == null || data.length == 0) {
        LOG.debug("Ignoring empty node "+path);
        return;
      }

      AuthenticationKey key = (AuthenticationKey)Writables.getWritable(data,
          new AuthenticationKey());
      secretManager.addKey(key);
    } catch (KeeperException ke) {
      LOG.fatal("Error reading data from zookeeper", ke);
      watcher.abort("Error reading updated key znode "+path, ke);
    } catch (IOException ioe) {
      LOG.fatal("Error reading key writables", ioe);
      watcher.abort("Error reading key writables from znode "+path, ioe);
    }
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:23,代码来源:ZKSecretWatcher.java

示例2: refreshNodes

import org.apache.hadoop.hbase.util.Writables; //导入依赖的package包/类
private void refreshNodes(List<ZKUtil.NodeAndData> nodes) {
  for (ZKUtil.NodeAndData n : nodes) {
    String path = n.getNode();
    String keyId = ZKUtil.getNodeName(path);
    try {
      byte[] data = n.getData();
      if (data == null || data.length == 0) {
        LOG.debug("Ignoring empty node "+path);
        continue;
      }
      AuthenticationKey key = (AuthenticationKey)Writables.getWritable(
          data, new AuthenticationKey());
      secretManager.addKey(key);
    } catch (IOException ioe) {
      LOG.fatal("Failed reading new secret key for id '" + keyId +
          "' from zk", ioe);
      watcher.abort("Error deserializing key from znode "+path, ioe);
    }
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:21,代码来源:ZKSecretWatcher.java

示例3: addKeyToZK

import org.apache.hadoop.hbase.util.Writables; //导入依赖的package包/类
public void addKeyToZK(AuthenticationKey key) {
  String keyZNode = getKeyNode(key.getKeyId());
  try {
    byte[] keyData = Writables.getBytes(key);
    // TODO: is there any point in retrying beyond what ZK client does?
    ZKUtil.createSetData(watcher, keyZNode, keyData);
  } catch (KeeperException ke) {
    LOG.fatal("Unable to synchronize master key "+key.getKeyId()+
        " to znode "+keyZNode, ke);
    watcher.abort("Unable to synchronize secret key "+
        key.getKeyId()+" in zookeeper", ke);
  } catch (IOException ioe) {
    // this can only happen from an error serializing the key
    watcher.abort("Failed serializing key "+key.getKeyId(), ioe);
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:17,代码来源:ZKSecretWatcher.java

示例4: updateKeyInZK

import org.apache.hadoop.hbase.util.Writables; //导入依赖的package包/类
public void updateKeyInZK(AuthenticationKey key) {
  String keyZNode = getKeyNode(key.getKeyId());
  try {
    byte[] keyData = Writables.getBytes(key);
    try {
      ZKUtil.updateExistingNodeData(watcher, keyZNode, keyData, -1);
    } catch (KeeperException.NoNodeException ne) {
      // node was somehow removed, try adding it back
      ZKUtil.createSetData(watcher, keyZNode, keyData);
    }
  } catch (KeeperException ke) {
    LOG.fatal("Unable to update master key "+key.getKeyId()+
        " in znode "+keyZNode);
    watcher.abort("Unable to synchronize secret key "+
        key.getKeyId()+" in zookeeper", ke);
  } catch (IOException ioe) {
    // this can only happen from an error serializing the key
    watcher.abort("Failed serializing key "+key.getKeyId(), ioe);
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:21,代码来源:ZKSecretWatcher.java

示例5: parseFrom

import org.apache.hadoop.hbase.util.Writables; //导入依赖的package包/类
/**
 * @param bytes A pb serialized {@link HTableDescriptor} instance with pb magic prefix
 * @return An instance of {@link HTableDescriptor} made from <code>bytes</code>
 * @throws DeserializationException
 * @throws IOException
 * @see #toByteArray()
 */
public static HTableDescriptor parseFrom(final byte [] bytes)
throws DeserializationException, IOException {
  if (!ProtobufUtil.isPBMagicPrefix(bytes)) {
    return (HTableDescriptor)Writables.getWritable(bytes, new HTableDescriptor());
  }
  int pblen = ProtobufUtil.lengthOfPBMagic();
  TableSchema.Builder builder = TableSchema.newBuilder();
  TableSchema ts;
  try {
    ProtobufUtil.mergeFrom(builder, bytes, pblen, bytes.length - pblen);
    ts = builder.build();
  } catch (IOException e) {
    throw new DeserializationException(e);
  }
  return convert(ts);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:24,代码来源:HTableDescriptor.java

示例6: offlineParentInMeta

import org.apache.hadoop.hbase.util.Writables; //导入依赖的package包/类
/**
 * Offline parent in meta.
 * Used when splitting.
 * @param catalogTracker
 * @param parent
 * @param a Split daughter region A
 * @param b Split daughter region B
 * @throws NotAllMetaRegionsOnlineException
 * @throws IOException
 */
public static void offlineParentInMeta(CatalogTracker catalogTracker,
    HRegionInfo parent, final HRegionInfo a, final HRegionInfo b)
throws NotAllMetaRegionsOnlineException, IOException {
  HRegionInfo copyOfParent = new HRegionInfo(parent);
  copyOfParent.setOffline(true);
  copyOfParent.setSplit(true);
  Put put = new Put(copyOfParent.getRegionName());
  addRegionInfo(put, copyOfParent);
  put.add(HConstants.CATALOG_FAMILY, HConstants.SPLITA_QUALIFIER,
    Writables.getBytes(a));
  put.add(HConstants.CATALOG_FAMILY, HConstants.SPLITB_QUALIFIER,
    Writables.getBytes(b));
  putToMetaTable(catalogTracker, put);
  LOG.info("Offlined parent region " + parent.getRegionNameAsString() +
    " in META");
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:27,代码来源:MetaEditor.java

示例7: listAllRegions

import org.apache.hadoop.hbase.util.Writables; //导入依赖的package包/类
/**
 * Used in tests.
 *
 * Lists all of the regions currently in META.
 * @param conf
 * @param offlined True if we are to include offlined regions, false and we'll
 * leave out offlined regions from returned list.
 * @return List of all user-space regions.
 * @throws IOException
 */
public static List<HRegionInfo> listAllRegions(Configuration conf, final boolean offlined)
throws IOException {
  final List<HRegionInfo> regions = new ArrayList<HRegionInfo>();
  MetaScannerVisitor visitor = new BlockingMetaScannerVisitor(conf) {
      @Override
      public boolean processRowInternal(Result result) throws IOException {
        if (result == null || result.isEmpty()) {
          return true;
        }
        byte [] bytes = result.getValue(HConstants.CATALOG_FAMILY,
          HConstants.REGIONINFO_QUALIFIER);
        if (bytes == null) {
          LOG.warn("Null REGIONINFO_QUALIFIER: " + result);
          return true;
        }
        HRegionInfo regionInfo = Writables.getHRegionInfo(bytes);
        // If region offline AND we are not to include offlined regions, return.
        if (regionInfo.isOffline() && !offlined) return true;
        regions.add(regionInfo);
        return true;
      }
  };
  metaScan(conf, visitor);
  return regions;
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:36,代码来源:MetaScanner.java

示例8: isTableAvailable

import org.apache.hadoop.hbase.util.Writables; //导入依赖的package包/类
public boolean isTableAvailable(final byte[] tableName) throws IOException {
  final AtomicBoolean available = new AtomicBoolean(true);
  final AtomicInteger regionCount = new AtomicInteger(0);
  MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
    @Override
    public boolean processRow(Result row) throws IOException {
      byte[] value = row.getValue(HConstants.CATALOG_FAMILY,
          HConstants.REGIONINFO_QUALIFIER);
      HRegionInfo info = Writables.getHRegionInfoOrNull(value);
      if (info != null && !info.isSplitParent()) {
        if (Bytes.equals(tableName, info.getTableName())) {
          value = row.getValue(HConstants.CATALOG_FAMILY,
              HConstants.SERVER_QUALIFIER);
          if (value == null) {
            available.set(false);
            return false;
          }
          regionCount.incrementAndGet();
        }
      }
      return true;
    }
  };
  MetaScanner.metaScan(conf, this, visitor, null);
  return available.get() && (regionCount.get() > 0);
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:27,代码来源:HConnectionManager.java

示例9: addRegionToMETA

import org.apache.hadoop.hbase.util.Writables; //导入依赖的package包/类
/**
 * Inserts a new region's meta information into the passed <code>meta</code> region. Used by the
 * HMaster bootstrap code adding new table to ROOT table.
 * @param meta META HRegion to be updated
 * @param r HRegion to add to <code>meta</code>
 * @throws IOException
 */
public static void addRegionToMETA(HRegion meta, HRegion r) throws IOException {
  meta.checkResources();
  // The row key is the region name
  byte[] row = r.getRegionName();
  Integer lid = meta.obtainRowLock(row);
  try {
    final long now = EnvironmentEdgeManager.currentTimeMillis();
    final List<KeyValue> edits = new ArrayList<KeyValue>(2);
    edits.add(new KeyValue(row, HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER, now,
        Writables.getBytes(r.getRegionInfo())));
    // Set into the root table the version of the meta table.
    edits.add(new KeyValue(row, HConstants.CATALOG_FAMILY, HConstants.META_VERSION_QUALIFIER,
        now, Bytes.toBytes(HConstants.META_VERSION)));
    meta.put(HConstants.CATALOG_FAMILY, edits);
  } finally {
    meta.releaseRowLock(lid);
  }
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:26,代码来源:HRegion.java

示例10: createMultiRegionsInMeta

import org.apache.hadoop.hbase.util.Writables; //导入依赖的package包/类
/**
 * Create rows in META for regions of the specified table with the specified
 * start keys.  The first startKey should be a 0 length byte array if you
 * want to form a proper range of regions.
 * @param conf
 * @param htd
 * @param startKeys
 * @return list of region info for regions added to meta
 * @throws IOException
 */
public List<HRegionInfo> createMultiRegionsInMeta(final Configuration conf,
    final HTableDescriptor htd, byte [][] startKeys)
throws IOException {
  HTable meta = new HTable(conf, HConstants.META_TABLE_NAME);
  Arrays.sort(startKeys, Bytes.BYTES_COMPARATOR);
  List<HRegionInfo> newRegions = new ArrayList<HRegionInfo>(startKeys.length);
  // add custom ones
  for (int i = 0; i < startKeys.length; i++) {
    int j = (i + 1) % startKeys.length;
    HRegionInfo hri = new HRegionInfo(htd.getName(), startKeys[i],
        startKeys[j]);
    Put put = new Put(hri.getRegionName());
    put.add(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER,
      Writables.getBytes(hri));
    meta.put(put);
    LOG.info("createMultiRegionsInMeta: inserted " + hri.toString());
    newRegions.add(hri);
  }

  meta.close();
  return newRegions;
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:33,代码来源:HBaseTestingUtility.java

示例11: getMetaTableRows

import org.apache.hadoop.hbase.util.Writables; //导入依赖的package包/类
/**
 * Returns all rows from the .META. table for a given user table
 *
 * @throws IOException When reading the rows fails.
 */
public List<byte[]> getMetaTableRows(byte[] tableName) throws IOException {
  // TODO: Redo using MetaReader.
  HTable t = new HTable(new Configuration(this.conf), HConstants.META_TABLE_NAME);
  List<byte[]> rows = new ArrayList<byte[]>();
  ResultScanner s = t.getScanner(new Scan());
  for (Result result : s) {
    byte[] val = result.getValue(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER);
    if (val == null) {
      LOG.error("No region info for row " + Bytes.toString(result.getRow()));
      // TODO figure out what to do for this new hosed case.
      continue;
    }
    HRegionInfo info = Writables.getHRegionInfo(val);
    if (Bytes.compareTo(info.getTableName(), tableName) == 0) {
      LOG.info("getMetaTableRows: row -> " +
          Bytes.toStringBinary(result.getRow()) + info);
      rows.add(result.getRow());
    }
  }
  s.close();
  t.close();
  return rows;
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:29,代码来源:HBaseTestingUtility.java

示例12: testGetHRegionInfo

import org.apache.hadoop.hbase.util.Writables; //导入依赖的package包/类
@Test
public void testGetHRegionInfo() throws IOException {
  assertNull(CatalogJanitor.getHRegionInfo(new Result()));
  List<KeyValue> kvs = new ArrayList<KeyValue>();
  Result r = new Result(kvs);
  assertNull(CatalogJanitor.getHRegionInfo(r));
  byte [] f = HConstants.CATALOG_FAMILY;
  // Make a key value that doesn't have the expected qualifier.
  kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY, f,
    HConstants.SERVER_QUALIFIER, f));
  r = new Result(kvs);
  assertNull(CatalogJanitor.getHRegionInfo(r));
  // Make a key that does not have a regioninfo value.
  kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY, f,
    HConstants.REGIONINFO_QUALIFIER, f));
  HRegionInfo hri = CatalogJanitor.getHRegionInfo(new Result(kvs));
  assertTrue(hri == null);
  // OK, give it what it expects
  kvs.clear();
  kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY, f,
    HConstants.REGIONINFO_QUALIFIER,
    Writables.getBytes(HRegionInfo.FIRST_META_REGIONINFO)));
  hri = CatalogJanitor.getHRegionInfo(new Result(kvs));
  assertNotNull(hri);
  assertTrue(hri.equals(HRegionInfo.FIRST_META_REGIONINFO));
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:27,代码来源:TestCatalogJanitor.java

示例13: makeResultFromHRegionInfo

import org.apache.hadoop.hbase.util.Writables; //导入依赖的package包/类
private Result makeResultFromHRegionInfo(HRegionInfo region, HRegionInfo splita,
    HRegionInfo splitb) throws IOException {
  List<KeyValue> kvs = new ArrayList<KeyValue>();
  kvs.add(new KeyValue(
      region.getRegionName(),
      HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER,
      Writables.getBytes(region)));

  if (splita != null) {
    kvs.add(new KeyValue(
        region.getRegionName(),
        HConstants.CATALOG_FAMILY, HConstants.SPLITA_QUALIFIER,
        Writables.getBytes(splita)));
  }

  if (splitb != null) {
    kvs.add(new KeyValue(
        region.getRegionName(),
        HConstants.CATALOG_FAMILY, HConstants.SPLITB_QUALIFIER,
        Writables.getBytes(splitb)));
  }

  return new Result(kvs);
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:25,代码来源:TestCatalogJanitor.java

示例14: getMetaTableRowResult

import org.apache.hadoop.hbase.util.Writables; //导入依赖的package包/类
/**
 * @param sn ServerName to use making startcode and server in meta
 * @param hri Region to serialize into HRegionInfo
 * @return A mocked up Result that fakes a Get on a row in the
 * <code>.META.</code> table.
 * @throws IOException
 */
private Result getMetaTableRowResult(final HRegionInfo hri,
    final ServerName sn)
throws IOException {
  // TODO: Move to a utilities class.  More than one test case can make use
  // of this facility.
  List<KeyValue> kvs = new ArrayList<KeyValue>();
  kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY,
    HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER,
    Writables.getBytes(hri)));
  kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY,
    HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER,
    Bytes.toBytes(sn.getHostAndPort())));
  kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY,
    HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER,
    Bytes.toBytes(sn.getStartcode())));
  return new Result(kvs);
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:25,代码来源:TestAssignmentManager.java

示例15: createRegion

import org.apache.hadoop.hbase.util.Writables; //导入依赖的package包/类
protected HRegionInfo createRegion(Configuration conf, final HTable htbl,
    byte[] startKey, byte[] endKey) throws IOException {
  HTable meta = new HTable(conf, HConstants.META_TABLE_NAME);
  HTableDescriptor htd = htbl.getTableDescriptor();
  HRegionInfo hri = new HRegionInfo(htbl.getTableName(), startKey, endKey);

  LOG.info("manually adding regioninfo and hdfs data: " + hri.toString());
  Path rootDir = new Path(conf.get(HConstants.HBASE_DIR));
  FileSystem fs = rootDir.getFileSystem(conf);
  Path p = new Path(rootDir + "/" + htd.getNameAsString(),
      hri.getEncodedName());
  fs.mkdirs(p);
  Path riPath = new Path(p, HRegion.REGIONINFO_FILE);
  FSDataOutputStream out = fs.create(riPath);
  hri.write(out);
  out.close();

  // add to meta.
  Put put = new Put(hri.getRegionName());
  put.add(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER,
      Writables.getBytes(hri));
  meta.put(put);
  meta.flushCommits();
  return hri;
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:26,代码来源:OfflineMetaRebuildTestCore.java


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