예제 #1
0
파일: Main.java 프로젝트: gildafnai82/craq
 /**
  * @param args
  * @throws InterruptedException
  * @throws IOException
  */
 public static void main(String[] args) throws IOException, InterruptedException {
   if (args.length < 1 || !(args[0].equals("client") || args[0].equals("bookie"))) {
     usage();
     return;
   }
   String newArgs[] = new String[args.length - 1];
   System.arraycopy(args, 1, newArgs, 0, newArgs.length);
   if (args[0].equals("bookie")) {
     BookieServer.main(newArgs);
   } else {
     BookieClient.main(newArgs);
   }
 }
예제 #2
0
  /**
   * Determines the last entry written to a ledger not closed properly due to a client crash
   *
   * @param passwd
   */
  boolean recover(byte[] passwd)
      throws IOException, InterruptedException, BKException, KeeperException {
    /*
     * Create BookieClient objects and send a request to each one.
     */

    for (InetSocketAddress s : bookies) {
      LOG.info(s);
      BookieClient client = new BookieClient(s, 3000);
      clients.add(client);
      client.readEntry(lId, -1, this, null);
    }

    /*
     * Wait until I have received enough responses
     */
    synchronized (counter) {
      LOG.info("Counter: " + counter.get() + ", " + minimum + ", " + qMode);
      if (counter.get() < minimum) {
        LOG.info("Waiting...");
        counter.wait(5000);
      }
    }

    /*
     * Obtain largest hint
     */
    LedgerHandle lh = new LedgerHandle(self, lId, 0, qSize, qMode, passwd);
    for (InetSocketAddress addr : bookies) {
      lh.addBookieForReading(addr);
    }

    boolean notLegitimate = true;
    long readCounter = 0;
    while (notLegitimate) {
      readCounter = getNextHint();
      if (readCounter > -1) {
        lh.setLast(readCounter);
        boolean hasMore = true;
        while (hasMore) {
          hasMore = false;
          LOG.debug("Recovering: " + lh.getLast());
          LedgerSequence ls = lh.readEntries(lh.getLast(), lh.getLast());
          LOG.debug("Received entry for: " + lh.getLast());

          byte[] le = ls.nextElement().getEntry();
          if (le != null) {
            if (notLegitimate) notLegitimate = false;
            lh.addEntry(le);
            hasMore = true;
          }
        }
      } else break;
    }

    /*
     * Write counter as the last entry of ledger
     */
    if (!notLegitimate) {
      lh.setAddConfirmed(readCounter);
      lh.close();

      return true;
    } else {
      lh.setLast(0);
      lh.close();

      return false;
    }
  }