Example #1
0
 public void force() throws IOException {
   SyncCounter counter = lastCounter.get();
   if (counter != null) {
     try {
       counter.block(0);
       if (counter.getrc() != BKException.Code.OK) {
         throw new IOException("Force append failed", BKException.create(counter.getrc()));
       }
     } catch (InterruptedException e) {
       Thread.currentThread().interrupt();
       throw new IOException(e);
     } finally {
       lastCounter.remove();
     }
   }
 }
Example #2
0
 private void replicateLedgerFragment(
     LedgerHandle lh,
     final LedgerFragment ledgerFragment,
     final Map<Integer, BookieSocketAddress> targetBookieAddresses)
     throws InterruptedException, BKException {
   SyncCounter syncCounter = new SyncCounter();
   ResultCallBack resultCallBack = new ResultCallBack(syncCounter);
   SingleFragmentCallback cb =
       new SingleFragmentCallback(
           resultCallBack,
           lh,
           ledgerFragment.getFirstEntryId(),
           getReplacedBookiesMap(ledgerFragment, targetBookieAddresses));
   syncCounter.inc();
   Set<BookieSocketAddress> targetBookieSet = new HashSet<BookieSocketAddress>();
   targetBookieSet.addAll(targetBookieAddresses.values());
   asyncRecoverLedgerFragment(lh, ledgerFragment, cb, targetBookieSet);
   syncCounter.block(0);
   if (syncCounter.getrc() != BKException.Code.OK) {
     throw BKException.create(bkc.getReturnRc(syncCounter.getrc()));
   }
 }
Example #3
0
  /**
   * 写入事务日志
   *
   * @param tlog
   * @return
   * @throws BKException
   * @throws InterruptedException
   */
  public SyncCounter writeLog(TransactionLogRecord tlog) throws InterruptedException {
    int recordSize = tlog.calculateTotalRecordSize();
    long futureFilePosition = handle.getLength() + recordSize;
    if (futureFilePosition >= conf.getBtmConf().getMaxLogSizeInMb() * 1024 * 1024) {
      if (log.isDebugEnabled())
        log.debug(
            "log file is full (size would be: "
                + futureFilePosition
                + ", max allowed: "
                + conf.getBtmConf().getMaxLogSizeInMb()
                + "Mbs");
      return null;
    }

    ByteBuffer buf = ByteBuffer.allocate(recordSize);
    buf.putInt(tlog.getStatus());
    buf.putInt(tlog.getRecordLength());
    buf.putInt(tlog.getHeaderLength());
    buf.putLong(tlog.getTime());
    buf.putInt(tlog.getSequenceNumber());
    buf.putInt(tlog.getCrc32());
    buf.put((byte) tlog.getGtrid().getArray().length);
    buf.put(tlog.getGtrid().getArray());
    Set<String> uniqueNames = tlog.getUniqueNames();
    buf.putInt(uniqueNames.size());
    for (String uniqueName : uniqueNames) {
      buf.putShort((short) uniqueName.length());
      buf.put(uniqueName.getBytes());
    }
    buf.putInt(tlog.getEndRecord());

    byte[] data = buf.array();
    SyncCounter counter = new SyncCounter();
    counter.inc();
    handle.asyncAddEntry(data, new SyncAddCallback(), counter);
    lastCounter.set(counter);
    return counter;
  }
Example #4
0
  /**
   * Open a ledger as an administrator without recovering the ledger. This means that no digest
   * password checks are done. Otherwise, the call is identical to BookKeeper#openLedgerNoRecovery
   *
   * @param lId ledger identifier
   * @see BookKeeper#openLedgerNoRecovery
   */
  public LedgerHandle openLedgerNoRecovery(final long lId)
      throws InterruptedException, BKException {
    SyncCounter counter = new SyncCounter();
    counter.inc();
    new LedgerOpenOp(bkc, lId, new SyncOpenCallback(), counter).initiateWithoutRecovery();
    /*
     * Wait
     */
    counter.block(0);
    if (counter.getrc() != BKException.Code.OK) {
      throw BKException.create(counter.getrc());
    }

    return counter.getLh();
  }
Example #5
0
    /**
     * Implementation of callback interface for synchronous read method.
     *
     * @param rc return code
     * @param leder ledger identifier
     * @param entry entry identifier
     * @param ctx control object
     */
    public void addComplete(int rc, LedgerHandle lh, long entry, Object ctx) {
      SyncCounter counter = (SyncCounter) ctx;

      counter.setrc(rc);
      counter.dec();
    }
Example #6
0
 @Override
 public void processResult(int rc, String s, Object obj) {
   sync.setrc(rc);
   sync.dec();
 }