org.apache.bookkeeper.meta.ZkVersion类的使用及代码示例

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

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

ZkVersion介绍

暂无

代码示例

代码示例来源:origin: twitter/distributedlog

@Override
  public Future<Void> apply(List<Void> values) {
    return Utils.zkDelete(zkc, poolPath, new ZkVersion(-1));
  }
});

代码示例来源:origin: twitter/distributedlog

synchronized int getZkVersion() {
  return ((ZkVersion) version).getZnodeVersion();
}

代码示例来源:origin: twitter/distributedlog

synchronized MaxLogSegmentSequenceNo update(ZkVersion version, long logSegmentSeqNo) {
  if (version.compare(this.version) == Version.Occurred.AFTER) {
    this.version = version;
    this.maxSeqNo = logSegmentSeqNo;
  }
  return this;
}

代码示例来源:origin: twitter/distributedlog

@Test(timeout = 60000)
public void testStoreMaxLogSegmentSequenceNumber() throws Exception {
  Transaction<Object> updateTxn = lsmStore.transaction();
  Versioned<Long> value = new Versioned<Long>(999L, new ZkVersion(0));
  final Promise<Version> result = new Promise<Version>();
  lsmStore.storeMaxLogSegmentSequenceNumber(updateTxn, rootZkPath, value,
      new Transaction.OpListener<Version>() {
    @Override
    public void onCommit(Version r) {
      result.setValue(r);
    }
    @Override
    public void onAbort(Throwable t) {
      result.setException(t);
    }
  });
  FutureUtils.result(updateTxn.execute());
  assertEquals(1, ((ZkVersion) FutureUtils.result(result)).getZnodeVersion());
  Stat stat = new Stat();
  byte[] data = zkc.get().getData(rootZkPath, false, stat);
  assertEquals(999L, DLUtils.deserializeLogSegmentSequenceNumber(data));
  assertEquals(1, stat.getVersion());
}

代码示例来源:origin: twitter/distributedlog

@Test(timeout = 60000)
public void testStoreMaxTxnId() throws Exception {
  Transaction<Object> updateTxn = lsmStore.transaction();
  Versioned<Long> value = new Versioned<Long>(999L, new ZkVersion(0));
  final Promise<Version> result = new Promise<Version>();
  lsmStore.storeMaxTxnId(updateTxn, rootZkPath, value,
      new Transaction.OpListener<Version>() {
    @Override
    public void onCommit(Version r) {
      result.setValue(r);
    }
    @Override
    public void onAbort(Throwable t) {
      result.setException(t);
    }
  });
  FutureUtils.result(updateTxn.execute());
  assertEquals(1, ((ZkVersion) FutureUtils.result(result)).getZnodeVersion());
  Stat stat = new Stat();
  byte[] data = zkc.get().getData(rootZkPath, false, stat);
  assertEquals(999L, DLUtils.deserializeTransactionId(data));
  assertEquals(1, stat.getVersion());
}

代码示例来源:origin: twitter/distributedlog

synchronized MaxLogSegmentSequenceNo update(int zkVersion, long logSegmentSeqNo) {
  return update(new ZkVersion(zkVersion), logSegmentSeqNo);
}

代码示例来源:origin: twitter/distributedlog

/**
 * Delete the given <i>path</i> from zookeeper.
 *
 * @param zk
 *          zookeeper client
 * @param path
 *          path to delete
 * @param version
 *          version used to set data
 * @return future representing the version after this operation.
 */
public static Future<Void> zkDelete(ZooKeeper zk, String path, ZkVersion version) {
  final Promise<Void> promise = new Promise<Void>();
  zk.delete(path, version.getZnodeVersion(), new AsyncCallback.VoidCallback() {
    @Override
    public void processResult(int rc, String path, Object ctx) {
      if (KeeperException.Code.OK.intValue() == rc) {
        promise.updateIfEmpty(new Return<Void>(null));
        return;
      }
      promise.updateIfEmpty(new Throw<Void>(
          KeeperException.create(KeeperException.Code.get(rc))));
      return;
    }
  }, null);
  return promise;
}

代码示例来源:origin: twitter/distributedlog

private synchronized void setVersion(ZkVersion newVersion) {
  Version.Occurred occurred = newVersion.compare(version);
  if (occurred == Version.Occurred.AFTER) {
    LOG.info("Ledger allocator for {} moved version from {} to {}.",
        new Object[] { allocatePath, version, newVersion });
    version = newVersion;
  } else {
    LOG.warn("Ledger allocator for {} received an old version {}, current version is {}.",
        new Object[] { allocatePath, newVersion , version });
  }
}

代码示例来源:origin: twitter/distributedlog

@Override
  public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
    if (KeeperException.Code.OK.intValue() != rc) {
      numFailures.incrementAndGet();
      latch.countDown();
      return;
    }
    Versioned<byte[]> allocatorData =
        new Versioned<byte[]>(data, new ZkVersion(stat.getVersion()));
    SimpleLedgerAllocator allocator =
        new SimpleLedgerAllocator(path, allocatorData, quorumConfigProvider, zkc, bkc);
    allocator.start();
    pendingList.add(allocator);
    if (numPendings.decrementAndGet() == 0 && numFailures.get() == 0) {
      latch.countDown();
    }
  }
};

代码示例来源:origin: twitter/distributedlog

/**
 * Set <code>data</code> to zookeeper <code>path</code>.
 *
 * @param zk
 *          zookeeper client
 * @param path
 *          path to set data
 * @param data
 *          data to set
 * @param version
 *          version used to set data
 * @return future representing the version after this operation.
 */
public static Future<ZkVersion> zkSetData(ZooKeeper zk, String path, byte[] data, ZkVersion version) {
  final Promise<ZkVersion> promise = new Promise<ZkVersion>();
  zk.setData(path, data, version.getZnodeVersion(), new AsyncCallback.StatCallback() {
    @Override
    public void processResult(int rc, String path, Object ctx, Stat stat) {
      if (KeeperException.Code.OK.intValue() == rc) {
        promise.updateIfEmpty(new Return<ZkVersion>(new ZkVersion(stat.getVersion())));
        return;
      }
      promise.updateIfEmpty(new Throw<ZkVersion>(
          KeeperException.create(KeeperException.Code.get(rc))));
      return;
    }
  }, null);
  return promise;
}

代码示例来源:origin: twitter/distributedlog

@Override
protected void commitOpResult(OpResult opResult) {
  assert(opResult instanceof OpResult.SetDataResult);
  OpResult.SetDataResult setDataResult = (OpResult.SetDataResult) opResult;
  listener.onCommit(new ZkVersion(setDataResult.getStat().getVersion()));
}

代码示例来源:origin: twitter/distributedlog

private synchronized void completeAllocation(LedgerHandle lh) {
  allocatedLh = lh;
  if (null == tryObtainTxn) {
    return;
  }
  org.apache.zookeeper.Op zkSetDataOp = org.apache.zookeeper.Op.setData(
      allocatePath, DistributedLogConstants.EMPTY_BYTES, version.getZnodeVersion());
  ZKVersionedSetOp commitOp = new ZKVersionedSetOp(zkSetDataOp, this);
  tryObtainTxn.addOp(commitOp);
  setPhase(Phase.HANDING_OVER);
  FutureUtils.setValue(allocatePromise, lh);
}

代码示例来源:origin: twitter/distributedlog

@Override
  public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
    boolean retry = false;
    SimpleLedgerAllocator newAllocator = null;
    if (KeeperException.Code.OK.intValue() == rc) {
      Versioned<byte[]> allocatorData =
          new Versioned<byte[]>(data, new ZkVersion(stat.getVersion()));
      logger.info("Rescuing ledger allocator {}.", path);
      newAllocator = new SimpleLedgerAllocator(path, allocatorData, quorumConfigProvider, zkc, bkc);
      newAllocator.start();
      logger.info("Rescued ledger allocator {}.", path);
    } else if (KeeperException.Code.NONODE.intValue() == rc) {
      logger.info("Ledger allocator {} doesn't exist, skip rescuing it.", path);
    } else {
      retry = true;
    }
    synchronized (LedgerAllocatorPool.this) {
      rescueMap.remove(ledgerAllocator.allocatePath);
      if (null != newAllocator) {
        pendingList.addLast(newAllocator);
      }
    }
    if (retry) {
      scheduleAllocatorRescue(ledgerAllocator);
    }
  }
}, null);

代码示例来源:origin: twitter/distributedlog

@Override
public void storeMaxLogSegmentSequenceNumber(Transaction<Object> txn,
                       String path,
                       Versioned<Long> lssn,
                       Transaction.OpListener<Version> listener) {
  Version version = lssn.getVersion();
  assert(version instanceof ZkVersion);
  ZkVersion zkVersion = (ZkVersion) version;
  byte[] data = DLUtils.serializeLogSegmentSequenceNumber(lssn.getValue());
  Op setDataOp = Op.setData(path, data, zkVersion.getZnodeVersion());
  ZKOp zkOp = new ZKVersionedSetOp(setDataOp, listener);
  txn.addOp(zkOp);
}

代码示例来源:origin: twitter/distributedlog

finalMetadatas.add(metadatas.get(i));
} else {
  finalMetadatas.add(new Versioned<byte[]>(dataCreated, new ZkVersion(0)));

代码示例来源:origin: twitter/distributedlog

@Override
public void storeMaxTxnId(Transaction<Object> txn,
             String path,
             Versioned<Long> transactionId,
             Transaction.OpListener<Version> listener) {
  Version version = transactionId.getVersion();
  assert(version instanceof ZkVersion);
  ZkVersion zkVersion = (ZkVersion) version;
  byte[] data = DLUtils.serializeTransactionId(transactionId.getValue());
  Op setDataOp = Op.setData(path, data, zkVersion.getZnodeVersion());
  ZKOp zkOp = new ZKVersionedSetOp(setDataOp, listener);
  txn.addOp(zkOp);
}

代码示例来源:origin: twitter/distributedlog

@Override
  public void processResult(int rc, String path, Object ctx, Stat stat) {
    if (KeeperException.Code.OK.intValue() == rc) {
      promise.updateIfEmpty(new Return<ZkVersion>(new ZkVersion(stat.getVersion())));
      return;
    }
    promise.updateIfEmpty(new Throw<ZkVersion>(
        KeeperException.create(KeeperException.Code.get(rc))));
    return;
  }
}, null);

代码示例来源:origin: twitter/distributedlog

@Test(timeout = 60000)
  public void testZkGetData() throws Exception {
    String path1 = "/zk-get-data/non-existent-path";
    Versioned<byte[]> data = FutureUtils.result(Utils.zkGetData(zkc.get(), path1, false));
    assertNull("No data should return from non-existent-path", data.getValue());
    assertNull("No version should return from non-existent-path", data.getVersion());

    String path2 = "/zk-get-data/path2";
    byte[] rawData = "test-data".getBytes(UTF_8);
    FutureUtils.result(Utils.zkAsyncCreateFullPathOptimistic(zkc, path2, rawData,
        zkc.getDefaultACL(), CreateMode.PERSISTENT));
    data = FutureUtils.result(Utils.zkGetData(zkc.get(), path2, false));
    assertArrayEquals("Data should return as written",
        rawData, data.getValue());
    assertEquals("Version should be zero",
        0, ((ZkVersion) data.getVersion()).getZnodeVersion());
  }
}

代码示例来源:origin: twitter/distributedlog

@SuppressWarnings("unchecked")
@Test(timeout = 60000, expected = UnexpectedException.class)
public void testProcessLogMetadatasMissingAllocatorPath() throws Exception {
  String rootPath = "/test-missing-version";
  URI uri = DLMTestUtil.createDLMURI(2181, rootPath);
  String logName = "test-log";
  String logIdentifier = "<default>";
  List<Versioned<byte[]>> metadatas = Lists.newArrayList(
      new Versioned<byte[]>(null, null),
      new Versioned<byte[]>(null, null),
      new Versioned<byte[]>(DLUtils.serializeTransactionId(1L), new ZkVersion(1)),
      new Versioned<byte[]>(ZKLogMetadataForWriter.intToBytes(ZKLogMetadata.LAYOUT_VERSION), null),
      new Versioned<byte[]>(new byte[0], new ZkVersion(1)),
      new Versioned<byte[]>(new byte[0], new ZkVersion(1)),
      new Versioned<byte[]>(DLUtils.serializeLogSegmentSequenceNumber(1L), new ZkVersion(1)),
      new Versioned<byte[]>(null, null));
  ZKLogMetadataForWriter.processLogMetadatas(uri, logName, logIdentifier, metadatas, true);
}

代码示例来源:origin: twitter/distributedlog

assertTrue(((ZkVersion) metadata.getVersion()).getZnodeVersion() >= 0);

相关文章

ZkVersion类方法