org.apache.hadoop.hbase.zookeeper.ZKUtil.positionToByteArray()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(126)

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

ZKUtil.positionToByteArray介绍

暂无

代码示例

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

  1. @Override
  2. public void setLastSequenceIds(String peerId, Map<String, Long> lastSeqIds)
  3. throws ReplicationException {
  4. try {
  5. // No need CAS and retry here, because it'll call setLastSequenceIds() for disabled peers
  6. // only, so no conflict happen.
  7. List<ZKUtilOp> listOfOps = new ArrayList<>();
  8. for (Entry<String, Long> lastSeqEntry : lastSeqIds.entrySet()) {
  9. String path = getSerialReplicationRegionPeerNode(lastSeqEntry.getKey(), peerId);
  10. ZKUtil.createWithParents(zookeeper, path);
  11. listOfOps.add(ZKUtilOp.setData(path, ZKUtil.positionToByteArray(lastSeqEntry.getValue())));
  12. }
  13. if (!listOfOps.isEmpty()) {
  14. ZKUtil.multiOrSequential(zookeeper, listOfOps, true);
  15. }
  16. } catch (KeeperException e) {
  17. throw new ReplicationException("Failed to set last sequence ids, peerId=" + peerId
  18. + ", size of lastSeqIds=" + lastSeqIds.size(), e);
  19. }
  20. }

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

  1. private void addLastSeqIdsToOps(String queueId, Map<String, Long> lastSeqIds,
  2. List<ZKUtilOp> listOfOps) throws KeeperException, ReplicationException {
  3. String peerId = new ReplicationQueueInfo(queueId).getPeerId();
  4. for (Entry<String, Long> lastSeqEntry : lastSeqIds.entrySet()) {
  5. String path = getSerialReplicationRegionPeerNode(lastSeqEntry.getKey(), peerId);
  6. Pair<Long, Integer> p = getLastSequenceIdWithVersion(lastSeqEntry.getKey(), peerId);
  7. byte[] data = ZKUtil.positionToByteArray(lastSeqEntry.getValue());
  8. if (p.getSecond() < 0) { // ZNode does not exist.
  9. ZKUtil.createWithParents(zookeeper,
  10. path.substring(0, path.lastIndexOf(ZNodePaths.ZNODE_PATH_SEPARATOR)));
  11. listOfOps.add(ZKUtilOp.createAndFailSilent(path, data));
  12. continue;
  13. }
  14. // Perform CAS in a specific version v0 (HBASE-20138)
  15. int v0 = p.getSecond();
  16. long lastPushedSeqId = p.getFirst();
  17. if (lastSeqEntry.getValue() <= lastPushedSeqId) {
  18. continue;
  19. }
  20. listOfOps.add(ZKUtilOp.setData(path, data, v0));
  21. }
  22. }

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

  1. @Override
  2. public void setWALPosition(ServerName serverName, String queueId, String fileName, long position,
  3. Map<String, Long> lastSeqIds) throws ReplicationException {
  4. try {
  5. for (int retry = 0;; retry++) {
  6. List<ZKUtilOp> listOfOps = new ArrayList<>();
  7. if (position > 0) {
  8. listOfOps.add(ZKUtilOp.setData(getFileNode(serverName, queueId, fileName),
  9. ZKUtil.positionToByteArray(position)));
  10. }
  11. // Persist the max sequence id(s) of regions for serial replication atomically.
  12. addLastSeqIdsToOps(queueId, lastSeqIds, listOfOps);
  13. if (listOfOps.isEmpty()) {
  14. return;
  15. }
  16. try {
  17. ZKUtil.multiOrSequential(zookeeper, listOfOps, false);
  18. return;
  19. } catch (KeeperException.BadVersionException | KeeperException.NodeExistsException e) {
  20. LOG.warn(
  21. "Bad version(or node exist) when persist the last pushed sequence id to zookeeper storage, "
  22. + "Retry = " + retry + ", serverName=" + serverName + ", queueId=" + queueId
  23. + ", fileName=" + fileName);
  24. }
  25. }
  26. } catch (KeeperException e) {
  27. throw new ReplicationException("Failed to set log position (serverName=" + serverName
  28. + ", queueId=" + queueId + ", fileName=" + fileName + ", position=" + position + ")", e);
  29. }
  30. }

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

  1. @Override
  2. protected Pair<Long, Integer> getLastSequenceIdWithVersion(String encodedRegionName,
  3. String peerId) throws KeeperException {
  4. Pair<Long, Integer> oldPair = super.getLastSequenceIdWithVersion(encodedRegionName, peerId);
  5. if (getLastSeqIdOpIndex < 100) {
  6. // Let the ZNode version increase.
  7. String path = getSerialReplicationRegionPeerNode(encodedRegionName, peerId);
  8. ZKUtil.createWithParents(zookeeper, path);
  9. ZKUtil.setData(zookeeper, path, ZKUtil.positionToByteArray(100L));
  10. }
  11. getLastSeqIdOpIndex++;
  12. return oldPair;
  13. }
  14. };

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

  1. @Override
  2. public void setLastSequenceIds(String peerId, Map<String, Long> lastSeqIds)
  3. throws ReplicationException {
  4. try {
  5. // No need CAS and retry here, because it'll call setLastSequenceIds() for disabled peers
  6. // only, so no conflict happen.
  7. List<ZKUtilOp> listOfOps = new ArrayList<>();
  8. for (Entry<String, Long> lastSeqEntry : lastSeqIds.entrySet()) {
  9. String path = getSerialReplicationRegionPeerNode(lastSeqEntry.getKey(), peerId);
  10. ZKUtil.createWithParents(zookeeper, path);
  11. listOfOps.add(ZKUtilOp.setData(path, ZKUtil.positionToByteArray(lastSeqEntry.getValue())));
  12. }
  13. if (!listOfOps.isEmpty()) {
  14. ZKUtil.multiOrSequential(zookeeper, listOfOps, true);
  15. }
  16. } catch (KeeperException e) {
  17. throw new ReplicationException("Failed to set last sequence ids, peerId=" + peerId
  18. + ", size of lastSeqIds=" + lastSeqIds.size(), e);
  19. }
  20. }

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

  1. private void addLastSeqIdsToOps(String queueId, Map<String, Long> lastSeqIds,
  2. List<ZKUtilOp> listOfOps) throws KeeperException, ReplicationException {
  3. String peerId = new ReplicationQueueInfo(queueId).getPeerId();
  4. for (Entry<String, Long> lastSeqEntry : lastSeqIds.entrySet()) {
  5. String path = getSerialReplicationRegionPeerNode(lastSeqEntry.getKey(), peerId);
  6. Pair<Long, Integer> p = getLastSequenceIdWithVersion(lastSeqEntry.getKey(), peerId);
  7. byte[] data = ZKUtil.positionToByteArray(lastSeqEntry.getValue());
  8. if (p.getSecond() < 0) { // ZNode does not exist.
  9. ZKUtil.createWithParents(zookeeper,
  10. path.substring(0, path.lastIndexOf(ZNodePaths.ZNODE_PATH_SEPARATOR)));
  11. listOfOps.add(ZKUtilOp.createAndFailSilent(path, data));
  12. continue;
  13. }
  14. // Perform CAS in a specific version v0 (HBASE-20138)
  15. int v0 = p.getSecond();
  16. long lastPushedSeqId = p.getFirst();
  17. if (lastSeqEntry.getValue() <= lastPushedSeqId) {
  18. continue;
  19. }
  20. listOfOps.add(ZKUtilOp.setData(path, data, v0));
  21. }
  22. }

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

  1. @Override
  2. public void setWALPosition(ServerName serverName, String queueId, String fileName, long position,
  3. Map<String, Long> lastSeqIds) throws ReplicationException {
  4. try {
  5. for (int retry = 0;; retry++) {
  6. List<ZKUtilOp> listOfOps = new ArrayList<>();
  7. if (position > 0) {
  8. listOfOps.add(ZKUtilOp.setData(getFileNode(serverName, queueId, fileName),
  9. ZKUtil.positionToByteArray(position)));
  10. }
  11. // Persist the max sequence id(s) of regions for serial replication atomically.
  12. addLastSeqIdsToOps(queueId, lastSeqIds, listOfOps);
  13. if (listOfOps.isEmpty()) {
  14. return;
  15. }
  16. try {
  17. ZKUtil.multiOrSequential(zookeeper, listOfOps, false);
  18. return;
  19. } catch (KeeperException.BadVersionException | KeeperException.NodeExistsException e) {
  20. LOG.warn(
  21. "Bad version(or node exist) when persist the last pushed sequence id to zookeeper storage, "
  22. + "Retry = " + retry + ", serverName=" + serverName + ", queueId=" + queueId
  23. + ", fileName=" + fileName);
  24. }
  25. }
  26. } catch (KeeperException e) {
  27. throw new ReplicationException("Failed to set log position (serverName=" + serverName
  28. + ", queueId=" + queueId + ", fileName=" + fileName + ", position=" + position + ")", e);
  29. }
  30. }

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

  1. @Override
  2. public void setLogPosition(String queueId, String filename, long position) {
  3. try {
  4. String znode = ZKUtil.joinZNode(this.myQueuesZnode, queueId);
  5. znode = ZKUtil.joinZNode(znode, filename);
  6. // Why serialize String of Long and not Long as bytes?
  7. ZKUtil.setData(this.zookeeper, znode, ZKUtil.positionToByteArray(position));
  8. } catch (KeeperException e) {
  9. this.abortable.abort("Failed to write replication wal position (filename=" + filename
  10. + ", position=" + position + ")", e);
  11. }
  12. }

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

  1. private void checkAndMigrateQueuesToPB(ZooKeeperWatcher zkw, String znode, String rs)
  2. throws KeeperException, NoNodeException, InterruptedException {
  3. String rsPath = ZKUtil.joinZNode(znode, rs);
  4. List<String> peers = ZKUtil.listChildrenNoWatch(zkw, rsPath);
  5. if (peers == null || peers.isEmpty()) return;
  6. String peerPath = null;
  7. for (String peer : peers) {
  8. peerPath = ZKUtil.joinZNode(rsPath, peer);
  9. List<String> files = ZKUtil.listChildrenNoWatch(zkw, peerPath);
  10. if (files == null || files.isEmpty()) continue;
  11. String filePath = null;
  12. for (String file : files) {
  13. filePath = ZKUtil.joinZNode(peerPath, file);
  14. byte[] data = ZKUtil.getData(zkw, filePath);
  15. if (data == null || Bytes.equals(data, HConstants.EMPTY_BYTE_ARRAY)) continue;
  16. if (ProtobufUtil.isPBMagicPrefix(data)) continue;
  17. ZKUtil.setData(zkw, filePath,
  18. ZKUtil.positionToByteArray(Long.parseLong(Bytes.toString(data))));
  19. }
  20. }
  21. }

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

  1. if (data == null) {
  2. ZKUtil
  3. .createSetData(this.watcher, nodePath, ZKUtil.positionToByteArray(lastSequenceId));
  4. } else {
  5. lastRecordedFlushedSequenceId =
  6. if (lastRecordedFlushedSequenceId < lastSequenceId) {
  7. ZKUtil.setData(this.watcher, nodePath, ZKUtil.positionToByteArray(lastSequenceId));

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

  1. ZKUtil.setData(zkw, nodePath, ZKUtil.positionToByteArray(minSeqIdForLogReplay));

相关文章