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


Java LedgerHandle类代码示例

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


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

示例1: createLedgers

import org.apache.bookkeeper.client.LedgerHandle; //导入依赖的package包/类
@Test
public void createLedgers() throws Exception {
    try {
        BookKeeper bookKeeperClient = getKeeper();
        LedgerHandle ledger = bookKeeperClient.createLedger(BookKeeper.DigestType.MAC, "123456".getBytes(Charsets.UTF_8));
        long entryId = ledger.addEntry("Hello World".getBytes());
        System.out.println(entryId);
        Enumeration<LedgerEntry> enumeration = ledger.readEntries(0, 99);
        while (enumeration.hasMoreElements()) {
            LedgerEntry entry = enumeration.nextElement();
            System.out.println(entry.getEntryId());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:aCoder2013,项目名称:fastmq,代码行数:17,代码来源:BookKeeperTest.java

示例2: BookKeeperEditLogInputStream

import org.apache.bookkeeper.client.LedgerHandle; //导入依赖的package包/类
/**
 * Construct BookKeeper edit log input stream. 
 * Starts reading from firstBookKeeperEntry. This allows the stream
 * to take a shortcut during recovery, as it doesn't have to read
 * every edit log transaction to find out what the last one is.
 */
BookKeeperEditLogInputStream(LedgerHandle lh, EditLogLedgerMetadata metadata,
                             long firstBookKeeperEntry) 
    throws IOException {
  this.lh = lh;
  this.firstTxId = metadata.getFirstTxId();
  this.lastTxId = metadata.getLastTxId();
  this.logVersion = metadata.getDataLayoutVersion();
  this.inProgress = metadata.isInProgress();

  if (firstBookKeeperEntry < 0
      || firstBookKeeperEntry > lh.getLastAddConfirmed()) {
    throw new IOException("Invalid first bk entry to read: "
        + firstBookKeeperEntry + ", LAC: " + lh.getLastAddConfirmed());
  }
  BufferedInputStream bin = new BufferedInputStream(
      new LedgerInputStream(lh, firstBookKeeperEntry));
  tracker = new FSEditLogLoader.PositionTrackingInputStream(bin);
  DataInputStream in = new DataInputStream(tracker);

  reader = new FSEditLogOp.Reader(in, tracker, logVersion);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:28,代码来源:BookKeeperEditLogInputStream.java

示例3: addComplete

import org.apache.bookkeeper.client.LedgerHandle; //导入依赖的package包/类
@Override
public void addComplete(int rc, LedgerHandle handle,
                        long entryId, Object ctx) {
  synchronized(this) {
    outstandingRequests.decrementAndGet();
    if (!transmitResult.compareAndSet(BKException.Code.OK, rc)) {
      LOG.warn("Tried to set transmit result to (" + rc + ") \""
          + BKException.getMessage(rc) + "\""
          + " but is already (" + transmitResult.get() + ") \""
          + BKException.getMessage(transmitResult.get()) + "\"");
    }
    CountDownLatch l = syncLatch;
    if (l != null) {
      l.countDown();
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:BookKeeperEditLogOutputStream.java

示例4: BookKeeperEditLogInputStream

import org.apache.bookkeeper.client.LedgerHandle; //导入依赖的package包/类
/**
 * Construct BookKeeper edit log input stream. 
 * Starts reading from firstBookKeeperEntry. This allows the stream
 * to take a shortcut during recovery, as it doesn't have to read
 * every edit log transaction to find out what the last one is.
 */
BookKeeperEditLogInputStream(LedgerHandle lh, EditLogLedgerMetadata metadata,
                             long firstBookKeeperEntry) 
    throws IOException {
  this.lh = lh;
  this.firstTxId = metadata.getFirstTxId();
  this.lastTxId = metadata.getLastTxId();
  this.logVersion = metadata.getDataLayoutVersion();
  this.inProgress = metadata.isInProgress();

  if (firstBookKeeperEntry < 0
      || firstBookKeeperEntry > lh.getLastAddConfirmed()) {
    throw new IOException("Invalid first bk entry to read: "
        + firstBookKeeperEntry + ", LAC: " + lh.getLastAddConfirmed());
  }
  BufferedInputStream bin = new BufferedInputStream(
      new LedgerInputStream(lh, firstBookKeeperEntry));
  tracker = new FSEditLogLoader.PositionTrackingInputStream(bin);
  DataInputStream in = new DataInputStream(tracker);

  reader = FSEditLogOp.Reader.create(in, tracker, logVersion);
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:28,代码来源:BookKeeperEditLogInputStream.java

示例5: close

import org.apache.bookkeeper.client.LedgerHandle; //导入依赖的package包/类
@Override
public void close() throws LogNotAvailableException {
    LedgerHandle _out = out;
    if (_out == null) {
        return;
    }
    try {
        LOGGER.log(Level.SEVERE, "Closing ledger " + _out.getId()
            + ", with LastAddConfirmed=" + _out.getLastAddConfirmed()
            + ", LastAddPushed=" + _out.getLastAddPushed()
            + " length=" + _out.getLength()
            + ", errorOccurred:" + errorOccurredDuringWrite);

        _out.close();
    } catch (InterruptedException | BKException err) {
        throw new LogNotAvailableException(err);
    } finally {
        out = null;
    }
}
 
开发者ID:diennea,项目名称:herddb,代码行数:21,代码来源:BookkeeperCommitLog.java

示例6: verifyRecoveredLedgers

import org.apache.bookkeeper.client.LedgerHandle; //导入依赖的package包/类
/**
 * Helper method to verify that we can read the recovered ledger entries.
 * 
 * @param numLedgers
 *            Number of ledgers to verify
 * @param startEntryId
 *            Start Entry Id to read
 * @param endEntryId
 *            End Entry Id to read
 * @throws BKException
 * @throws InterruptedException
 */
private void verifyRecoveredLedgers(int numLedgers, long startEntryId, long endEntryId) throws BKException,
        InterruptedException {
    // Get a set of LedgerHandles for all of the ledgers to verify
    List<LedgerHandle> lhs = new ArrayList<LedgerHandle>();
    for (int i = 0; i < numLedgers; i++) {
        lhs.add(bkc.openLedger(i + 1, digestType, System.getProperty("passwd").getBytes()));
    }
    // Read the ledger entries to verify that they are all present and
    // correct in the new bookie.
    for (LedgerHandle lh : lhs) {
        Enumeration<LedgerEntry> entries = lh.readEntries(startEntryId, endEntryId);
        while (entries.hasMoreElements()) {
            LedgerEntry entry = entries.nextElement();
            assertTrue(new String(entry.getEntry()).equals("LedgerId: " + entry.getLedgerId() + ", EntryId: "
                    + entry.getEntryId()));
        }
    }

}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:32,代码来源:BookieRecoveryTest.java

示例7: asyncReadEntry

import org.apache.bookkeeper.client.LedgerHandle; //导入依赖的package包/类
void asyncReadEntry(PositionImpl position, ReadEntryCallback callback, Object ctx) {
    LedgerHandle currentLedger = this.currentLedger;
    if (log.isDebugEnabled()) {
        log.debug("[{}] Reading entry ledger {}: {}", name, position.getLedgerId(), position.getEntryId());
    }
    if (position.getLedgerId() == currentLedger.getId()) {
        LedgerHandle ledger = currentLedger;
        entryCache.asyncReadEntry(ledger, position, callback, ctx);
    } else {
        getLedgerHandle(position.getLedgerId()).thenAccept(ledger -> {
            entryCache.asyncReadEntry(ledger, position, callback, ctx);
        }).exceptionally(ex -> {
            log.error("[{}] Error opening ledger for reading at position {} - {}", name, position, ex.getMessage());
            callback.readEntryFailed(new ManagedLedgerException(ex), ctx);
            return null;
        });
    }

}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:20,代码来源:ManagedLedgerImpl.java

示例8: recoveredCursor

import org.apache.bookkeeper.client.LedgerHandle; //导入依赖的package包/类
private void recoveredCursor(PositionImpl position, Map<String, Long> properties, LedgerHandle recoveredFromCursorLedger) {
    // if the position was at a ledger that didn't exist (since it will be deleted if it was previously empty),
    // we need to move to the next existing ledger
    if (!ledger.ledgerExists(position.getLedgerId())) {
        long nextExistingLedger = ledger.getNextValidLedger(position.getLedgerId());
        position = PositionImpl.get(nextExistingLedger, -1);
    }
    log.info("[{}] Cursor {} recovered to position {}", ledger.getName(), name, position);

    messagesConsumedCounter = -getNumberOfEntries(Range.openClosed(position, ledger.getLastPosition()));
    markDeletePosition = position;
    readPosition = ledger.getNextValidPosition(position);
    lastMarkDeleteEntry = new MarkDeleteEntry(markDeletePosition, properties, null, null);
    // assign cursor-ledger so, it can be deleted when new ledger will be switched
    this.cursorLedger = recoveredFromCursorLedger;
    STATE_UPDATER.set(this, State.NoLedger);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:18,代码来源:ManagedCursorImpl.java

示例9: asyncDeleteLedger

import org.apache.bookkeeper.client.LedgerHandle; //导入依赖的package包/类
private void asyncDeleteLedger(final LedgerHandle lh, int retry) {
    if (lh == null || retry <= 0) {
        if (lh != null) {
            log.warn("[{}-{}] Failed to delete ledger after retries {}", ledger.getName(), name, lh.getId());
        }
        return;
    }

    ledger.mbean.startCursorLedgerDeleteOp();
    bookkeeper.asyncDeleteLedger(lh.getId(), (rc, ctx) -> {
        ledger.mbean.endCursorLedgerDeleteOp();
        if (rc != BKException.Code.OK) {
            log.warn("[{}] Failed to delete ledger {}: {}", ledger.getName(), lh.getId(),
                    BKException.getMessage(rc));
            if (rc != BKException.Code.NoSuchLedgerExistsException) {
                ledger.getScheduledExecutor().schedule(safeRun(() -> {
                    asyncDeleteLedger(lh, retry - 1);
                }), DEFAULT_LEDGER_DELETE_BACKOFF_TIME_SEC, TimeUnit.SECONDS);
            }
            return;
        } else {
            log.info("[{}][{}] Successfully closed & deleted ledger {} in cursor", ledger.getName(), name,
                    lh.getId());
        }
    }, null);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:27,代码来源:ManagedCursorImpl.java

示例10: testCloseAllocatorAfterAbort

import org.apache.bookkeeper.client.LedgerHandle; //导入依赖的package包/类
@Test(timeout = 60000)
public void testCloseAllocatorAfterAbort() throws Exception {
    String allocationPath = "/allocation3";
    SimpleLedgerAllocator allocator = createAllocator(allocationPath);
    allocator.allocate();
    ZKTransaction txn = newTxn();
    // close during obtaining ledger.
    LedgerHandle lh = FutureUtils.result(allocator.tryObtain(txn, NULL_LISTENER));
    txn.addOp(DefaultZKOp.of(Op.setData("/unexistedpath", "data".getBytes(UTF_8), -1)));
    try {
        FutureUtils.result(txn.execute());
        fail("Should fail the transaction when setting unexisted path");
    } catch (ZKException ke) {
        // expected
    }
    Utils.close(allocator);
    byte[] data = zkc.get().getData(allocationPath, false, null);
    assertEquals((Long) lh.getId(), Long.valueOf(new String(data, UTF_8)));
    // the ledger is not deleted.
    bkc.get().openLedger(lh.getId(), BookKeeper.DigestType.CRC32,
            dlConf.getBKDigestPW().getBytes(UTF_8));
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:23,代码来源:TestLedgerAllocator.java

示例11: closeComplete

import org.apache.bookkeeper.client.LedgerHandle; //导入依赖的package包/类
@Override
public void closeComplete(int rc, LedgerHandle lh, Object ctx) {
    checkArgument(ledger.getId() == lh.getId(), "ledgerId %s doesn't match with acked ledgerId %s", ledger.getId(),
            lh.getId());

    if (rc == BKException.Code.OK) {
        log.debug("Successfuly closed ledger {}", lh.getId());
    } else {
        log.warn("Error when closing ledger {}. Status={}", lh.getId(), BKException.getMessage(rc));
    }

    ml.ledgerClosed(lh);
    updateLatency();

    AddEntryCallback cb = callbackUpdater.getAndSet(this, null);
    if (cb != null) {
        cb.addComplete(PositionImpl.get(lh.getId(), entryId), ctx);
        ml.notifyCursors();
        this.recycle();
    }
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:22,代码来源:OpAddEntry.java

示例12: getLedgerHandle

import org.apache.bookkeeper.client.LedgerHandle; //导入依赖的package包/类
private static LedgerHandle getLedgerHandle() {
    final LedgerHandle lh = mock(LedgerHandle.class);
    final LedgerEntry ledgerEntry = mock(LedgerEntry.class, Mockito.CALLS_REAL_METHODS);
    doReturn(new byte[10]).when(ledgerEntry).getEntry();
    doReturn(Unpooled.wrappedBuffer(new byte[10])).when(ledgerEntry).getEntryBuffer();
    doReturn((long) 10).when(ledgerEntry).getLength();

    doAnswer(new Answer<Object>() {
        public Object answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            long firstEntry = (Long) args[0];
            long lastEntry = (Long) args[1];
            ReadCallback callback = (ReadCallback) args[2];
            Object ctx = args[3];

            Vector<LedgerEntry> entries = new Vector<LedgerEntry>();
            for (int i = 0; i <= (lastEntry - firstEntry); i++) {
                entries.add(ledgerEntry);
            }
            callback.readComplete(0, lh, entries.elements(), ctx);
            return null;
        }
    }).when(lh).asyncReadEntries(anyLong(), anyLong(), any(ReadCallback.class), any());

    return lh;
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:27,代码来源:EntryCacheTest.java

示例13: createLogSegmentWriter

import org.apache.bookkeeper.client.LedgerHandle; //导入依赖的package包/类
private BKLogSegmentWriter createLogSegmentWriter(DistributedLogConfiguration conf,
                                                  long logSegmentSequenceNumber,
                                                  long startTxId,
                                                  ZKDistributedLock lock) throws Exception {
    LedgerHandle lh = bkc.get().createLedger(3, 2, 2,
            BookKeeper.DigestType.CRC32, conf.getBKDigestPW().getBytes(UTF_8));
    return new BKLogSegmentWriter(
            runtime.getMethodName(),
            runtime.getMethodName(),
            conf,
            LogSegmentMetadata.LEDGER_METADATA_CURRENT_LAYOUT_VERSION,
            new BKLogSegmentEntryWriter(lh),
            lock,
            startTxId,
            logSegmentSequenceNumber,
            scheduler,
            NullStatsLogger.INSTANCE,
            NullStatsLogger.INSTANCE,
            new AlertStatsLogger(NullStatsLogger.INSTANCE, "test"),
            PermitLimiter.NULL_PERMIT_LIMITER,
            new SettableFeatureProvider("", 0),
            ConfUtils.getConstDynConf(conf));
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:24,代码来源:TestBKLogSegmentWriter.java

示例14: createLedger

import org.apache.bookkeeper.client.LedgerHandle; //导入依赖的package包/类
public Future<LedgerHandle> createLedger(int ensembleSize,
                                         int writeQuorumSize,
                                         int ackQuorumSize) {
    BookKeeper bk;
    try {
        bk = get();
    } catch (IOException ioe) {
        return Future.exception(ioe);
    }
    final Promise<LedgerHandle> promise = new Promise<LedgerHandle>();
    bk.asyncCreateLedger(ensembleSize, writeQuorumSize, ackQuorumSize,
            BookKeeper.DigestType.CRC32, passwd, new AsyncCallback.CreateCallback() {
                @Override
                public void createComplete(int rc, LedgerHandle lh, Object ctx) {
                    if (BKException.Code.OK == rc) {
                        promise.updateIfEmpty(new Return<LedgerHandle>(lh));
                    } else {
                        promise.updateIfEmpty(new Throw<LedgerHandle>(BKException.create(rc)));
                    }
                }
            }, null);
    return promise;
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:24,代码来源:BookKeeperClient.java

示例15: tryObtain

import org.apache.bookkeeper.client.LedgerHandle; //导入依赖的package包/类
@Override
public synchronized Future<LedgerHandle> tryObtain(final Transaction<Object> txn,
                                                   final OpListener<LedgerHandle> listener) {
    if (Phase.ERROR == phase) {
        return Future.exception(new AllocationException(Phase.ERROR,
                "Error on allocating ledger under " + allocatePath));
    }
    if (Phase.HANDING_OVER == phase || Phase.HANDED_OVER == phase || null != tryObtainTxn) {
        return Future.exception(new ConcurrentObtainException(phase,
                "Ledger handle is handling over to another thread : " + phase));
    }
    tryObtainTxn = txn;
    tryObtainListener = listener;
    if (null != allocatedLh) {
        completeAllocation(allocatedLh);
    }
    return allocatePromise;
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:19,代码来源:SimpleLedgerAllocator.java


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