gpt4 book ai didi

com.twitter.distributedlog.impl.metadata.ZKLogMetadataForWriter类的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 11:07:50 25 4
gpt4 key购买 nike

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

ZKLogMetadataForWriter介绍

[英]Log Metadata for writer
[中]writer的日志元数据

代码示例

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

return checkLogMetadataPaths(zk, logRootPath, ownAllocator)
    .flatMap(new AbstractFunction1<List<Versioned<byte[]>>, Future<List<Versioned<byte[]>>>>() {
      @Override

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

LedgerAllocator createLedgerAllocator(ZKLogMetadataForWriter logMetadata) throws IOException {
  LedgerAllocator ledgerAllocatorDelegator;
  if (!dynConf.getEnableLedgerAllocatorPool()) {
    QuorumConfigProvider quorumConfigProvider =
        new DynamicQuorumConfigProvider(dynConf);
    LedgerAllocator allocator = new SimpleLedgerAllocator(
        logMetadata.getAllocationPath(),
        logMetadata.getAllocationData(),
        quorumConfigProvider,
        writerZKC,
        writerBKC);
    ledgerAllocatorDelegator = new LedgerAllocatorDelegator(allocator, true);
  } else {
    ledgerAllocatorDelegator = ledgerAllocator;
  }
  return ledgerAllocatorDelegator;
}

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

if (pathExists(metadatas.get(MetadataIndex.LOG_ROOT_PARENT))) {
  pathsToCreate.add(null);
} else {
if (pathExists(metadatas.get(MetadataIndex.LOG_ROOT))) {
  pathsToCreate.add(null);
} else {
if (pathExists(metadatas.get(MetadataIndex.MAX_TXID))) {
  pathsToCreate.add(null);
} else {
if (pathExists(metadatas.get(MetadataIndex.VERSION))) {
  pathsToCreate.add(null);
} else {
  byte[] versionData = intToBytes(LAYOUT_VERSION);
  pathsToCreate.add(versionData);
  zkOps.add(Op.create(logRootPath + VERSION_PATH, versionData, acl, createMode));
if (pathExists(metadatas.get(MetadataIndex.LOCK))) {
  pathsToCreate.add(null);
} else {
if (pathExists(metadatas.get(MetadataIndex.READ_LOCK))) {
  pathsToCreate.add(null);
} else {
if (pathExists(metadatas.get(MetadataIndex.LOGSEGMENTS))) {
  pathsToCreate.add(null);

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

ensureMetadataExist(maxTxnIdData);
  ensureMetadataExist(maxTxnIdData);
  Preconditions.checkArgument(LAYOUT_VERSION == bytesToInt(versionData.getValue()));
  ensureMetadataExist(metadatas.get(MetadataIndex.LOCK));
  ensureMetadataExist(metadatas.get(MetadataIndex.READ_LOCK));
  ensureMetadataExist(maxLSSNData);
  try {
    DLUtils.deserializeLogSegmentSequenceNumber(maxLSSNData.getValue());
  if (ownAllocator) {
    allocationData = metadatas.get(MetadataIndex.ALLOCATION);
    ensureMetadataExist(allocationData);
  } else {
    allocationData = new Versioned<byte[]>(null, null);
  return new ZKLogMetadataForWriter(uri, logName, logIdentifier,
      maxLSSNData, maxTxnIdData, allocationData);
} catch (IllegalArgumentException iae) {

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

FutureUtils.result(ZKLogMetadataForWriter.of(uri, logName, logIdentifier,
        zkc.get(), zkc.getDefaultACL(), ownAllocator, true));
    FutureUtils.result(ZKLogMetadataForWriter.checkLogMetadataPaths(zkc.get(), logRootPath, ownAllocator));
  assertTrue(ZKLogMetadataForWriter.pathExists(metadata));
  assertTrue(((ZkVersion) metadata.getVersion()).getZnodeVersion() >= 0);
Versioned<byte[]> logSegmentsData = logMetadata.getMaxLSSNData();
Versioned<byte[]> maxTxIdData = logMetadata.getMaxTxIdData();
  Versioned<byte[]> allocationData = logMetadata.getAllocationData();
  assertEquals(0, allocationData.getValue().length);

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

@SuppressWarnings("unchecked")
@Test(timeout = 60000)
public void testProcessLogMetadatasNoAllocatorPath() throws Exception {
  String rootPath = "/test-missing-version";
  URI uri = DLMTestUtil.createDLMURI(2181, rootPath);
  String logName = "test-log";
  String logIdentifier = "<default>";
  Versioned<byte[]> maxTxnIdData =
      new Versioned<byte[]>(DLUtils.serializeTransactionId(1L), new ZkVersion(1));
  Versioned<byte[]> logSegmentsData =
      new Versioned<byte[]>(DLUtils.serializeLogSegmentSequenceNumber(1L), new ZkVersion(1));
  List<Versioned<byte[]>> metadatas = Lists.newArrayList(
      new Versioned<byte[]>(null, null),
      new Versioned<byte[]>(null, null),
      maxTxnIdData,
      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)),
      logSegmentsData);
  ZKLogMetadataForWriter metadata =
      ZKLogMetadataForWriter.processLogMetadatas(uri, logName, logIdentifier, metadatas, false);
  assertTrue(maxTxnIdData == metadata.getMaxTxIdData());
  assertTrue(logSegmentsData == metadata.getMaxLSSNData());
  assertNull(metadata.getAllocationData().getValue());
  assertNull(metadata.getAllocationData().getVersion());
}

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

@SuppressWarnings("unchecked")
@Test(timeout = 60000, expected = UnexpectedException.class)
public void testProcessLogMetadatasWrongVersion() 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(9999), null));
  ZKLogMetadataForWriter.processLogMetadatas(uri, logName, logIdentifier, metadatas, false);
}

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

maxLogSegmentSequenceNo = new MaxLogSegmentSequenceNo(logMetadata.getMaxLSSNData());
inprogressLSSNs = new LinkedList<Long>();
maxTxId = new MaxTxId(zooKeeperClient, logMetadata.getMaxTxIdPath(),
    conf.getSanityCheckTxnID(), logMetadata.getMaxTxIdData());

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

static void createLog(DistributedLogConfiguration conf, ZooKeeperClient zkc, URI uri, String streamName)
    throws IOException, InterruptedException {
  Future<ZKLogMetadataForWriter> createFuture = ZKLogMetadataForWriter.of(
          uri, streamName, conf.getUnpartitionedStreamName(), zkc.get(), zkc.getDefaultACL(), true, true);
  FutureUtils.result(createFuture);
}

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

private static void createLog(ZooKeeperClient zk, URI uri, String logName, String logIdentifier)
    throws Exception {
  final String logRootPath = getLogRootPath(uri, logName, logIdentifier);
  final String logSegmentsPath = logRootPath + LOGSEGMENTS_PATH;
  final String maxTxIdPath = logRootPath + MAX_TXID_PATH;
  final String lockPath = logRootPath + LOCK_PATH;
  final String readLockPath = logRootPath + READ_LOCK_PATH;
  final String versionPath = logRootPath + VERSION_PATH;
  final String allocationPath = logRootPath + ALLOCATION_PATH;
  Utils.zkCreateFullPathOptimistic(zk, logRootPath, new byte[0],
      zk.getDefaultACL(), CreateMode.PERSISTENT);
  Transaction txn = zk.get().transaction();
  txn.create(logSegmentsPath, DLUtils.serializeLogSegmentSequenceNumber(
          DistributedLogConstants.UNASSIGNED_LOGSEGMENT_SEQNO),
      zk.getDefaultACL(), CreateMode.PERSISTENT);
  txn.create(maxTxIdPath, DLUtils.serializeTransactionId(0L),
      zk.getDefaultACL(), CreateMode.PERSISTENT);
  txn.create(lockPath, DistributedLogConstants.EMPTY_BYTES,
      zk.getDefaultACL(), CreateMode.PERSISTENT);
  txn.create(readLockPath, DistributedLogConstants.EMPTY_BYTES,
      zk.getDefaultACL(), CreateMode.PERSISTENT);
  txn.create(versionPath, ZKLogMetadataForWriter.intToBytes(LAYOUT_VERSION),
      zk.getDefaultACL(), CreateMode.PERSISTENT);
  txn.create(allocationPath, DistributedLogConstants.EMPTY_BYTES,
      zk.getDefaultACL(), CreateMode.PERSISTENT);
  txn.commit();
}

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

@SuppressWarnings("unchecked")
  @Test(timeout = 60000)
  public void testProcessLogMetadatasAllocatorPath() throws Exception {
    String rootPath = "/test-missing-version";
    URI uri = DLMTestUtil.createDLMURI(2181, rootPath);
    String logName = "test-log";
    String logIdentifier = "<default>";
    Versioned<byte[]> maxTxnIdData =
        new Versioned<byte[]>(DLUtils.serializeTransactionId(1L), new ZkVersion(1));
    Versioned<byte[]> logSegmentsData =
        new Versioned<byte[]>(DLUtils.serializeLogSegmentSequenceNumber(1L), new ZkVersion(1));
    Versioned<byte[]> allocationData =
        new Versioned<byte[]>(DLUtils.ledgerId2Bytes(1L), new ZkVersion(1));
    List<Versioned<byte[]>> metadatas = Lists.newArrayList(
        new Versioned<byte[]>(null, null),
        new Versioned<byte[]>(null, null),
        maxTxnIdData,
        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)),
        logSegmentsData,
        allocationData);
    ZKLogMetadataForWriter metadata =
        ZKLogMetadataForWriter.processLogMetadatas(uri, logName, logIdentifier, metadatas, true);
    assertTrue(maxTxnIdData == metadata.getMaxTxIdData());
    assertTrue(logSegmentsData == metadata.getMaxLSSNData());
    assertTrue(allocationData == metadata.getAllocationData());
  }
}

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

@SuppressWarnings("unchecked")
@Test(timeout = 60000, expected = UnexpectedException.class)
public void testProcessLogMetadatasMissingLockPath() 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[]>(null, null));
  ZKLogMetadataForWriter.processLogMetadatas(uri, logName, logIdentifier, metadatas, false);
}

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

Future<BKLogWriteHandler> asyncCreateWriteHandler(final boolean lockHandler) {
  final ZooKeeper zk;
  try {
    zk = writerZKC.get();
  } catch (InterruptedException e) {
    LOG.error("Failed to initialize zookeeper client : ", e);
    return Future.exception(new DLInterruptedException("Failed to initialize zookeeper client", e));
  } catch (ZooKeeperClient.ZooKeeperConnectionException e) {
    return Future.exception(FutureUtils.zkException(e, uri.getPath()));
  }
  boolean ownAllocator = null == ledgerAllocator;
  // Fetching Log Metadata
  Future<ZKLogMetadataForWriter> metadataFuture =
      ZKLogMetadataForWriter.of(uri, name, streamIdentifier,
          zk, writerZKC.getDefaultACL(),
          ownAllocator, conf.getCreateStreamIfNotExists() || ownAllocator);
  return metadataFuture.flatMap(new AbstractFunction1<ZKLogMetadataForWriter, Future<BKLogWriteHandler>>() {
    @Override
    public Future<BKLogWriteHandler> apply(ZKLogMetadataForWriter logMetadata) {
      Promise<BKLogWriteHandler> createPromise = new Promise<BKLogWriteHandler>();
      createWriteHandler(logMetadata, lockHandler, createPromise);
      return createPromise;
    }
  });
}

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

@SuppressWarnings("unchecked")
@Test(timeout = 60000, expected = UnexpectedException.class)
public void testProcessLogMetadatasMissingReadLockPath() 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[]>(null, null));
  ZKLogMetadataForWriter.processLogMetadatas(uri, logName, logIdentifier, metadatas, false);
}

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

@Test(timeout = 60000, expected = LogNotFoundException.class)
public void testCreateLogMetadataWithCreateIfNotExistsSetToFalse() throws Exception {
  URI uri = DLMTestUtil.createDLMURI(zkPort, "");
  String logName = testName.getMethodName();
  String logIdentifier = "<default>";
  FutureUtils.result(ZKLogMetadataForWriter.of(uri, logName, logIdentifier,
          zkc.get(), zkc.getDefaultACL(), true, false));
}

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

@Test(timeout = 60000)
public void testCheckLogMetadataPathsWithoutAllocator() throws Exception {
  String logRootPath = "/" + testName.getMethodName();
  List<Versioned<byte[]>> metadatas =
      FutureUtils.result(ZKLogMetadataForWriter.checkLogMetadataPaths(
          zkc.get(), logRootPath, false));
  assertEquals("Should have 7 paths",
      7, metadatas.size());
  for (Versioned<byte[]> path : metadatas.subList(2, metadatas.size())) {
    assertNull(path.getValue());
    assertNull(path.getVersion());
  }
}

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

@SuppressWarnings("unchecked")
@Test(timeout = 60000, expected = UnexpectedException.class)
public void testProcessLogMetadatasMissingLogSegmentsPath() 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[]>(null, null));
  ZKLogMetadataForWriter.processLogMetadatas(uri, logName, logIdentifier, metadatas, false);
}

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

@Test(timeout = 60000)
public void testCheckLogMetadataPathsWithAllocator() throws Exception {
  String logRootPath = "/" + testName.getMethodName();
  List<Versioned<byte[]>> metadatas =
      FutureUtils.result(ZKLogMetadataForWriter.checkLogMetadataPaths(
          zkc.get(), logRootPath, true));
  assertEquals("Should have 8 paths",
      8, metadatas.size());
  for (Versioned<byte[]> path : metadatas.subList(2, metadatas.size())) {
    assertNull(path.getValue());
    assertNull(path.getVersion());
  }
}

代码示例来源: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);
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com