Esempio n. 1
0
  /**
   * Find the best editlog input stream to read from txid. If a journal throws an
   * CorruptionException while reading from a txn id, it means that it has more transactions, but
   * can't find any from fromTxId. If this is the case and no other journal has transactions, we
   * should throw an exception as it means more transactions exist, we just can't load them.
   *
   * @param fromTxnId Transaction id to start from.
   * @return A edit log input stream with tranactions fromTxId or null if no more exist
   */
  @Override
  public EditLogInputStream getInputStream(long fromTxnId) throws IOException {
    JournalManager bestjm = null;
    long bestjmNumTxns = 0;
    CorruptionException corruption = null;

    for (JournalAndStream jas : journals) {
      JournalManager candidate = jas.getManager();
      long candidateNumTxns = 0;
      try {
        candidateNumTxns = candidate.getNumberOfTransactions(fromTxnId);
      } catch (CorruptionException ce) {
        corruption = ce;
      } catch (IOException ioe) {
        continue; // error reading disk, just skip
      }

      if (candidateNumTxns > bestjmNumTxns) {
        bestjm = candidate;
        bestjmNumTxns = candidateNumTxns;
      }
    }

    if (bestjm == null) {
      if (corruption != null) {
        throw new IOException("No non-corrupt logs for txid " + fromTxnId, corruption);
      } else {
        return null;
      }
    }
    return bestjm.getInputStream(fromTxnId);
  }
Esempio n. 2
0
 public void startLogSegment(long txId) throws IOException {
   Preconditions.checkState(stream == null);
   disabled = false;
   stream = journal.startLogSegment(txId);
 }
Esempio n. 3
0
 public JournalIdGenerator(JournalManager journal, int maxItem) {
   System.out.println("MAX STORE IN ID GENERATOR = " + maxItem);
   lastId = journal.getMaxIdSaved();
   counter = journal.getCounter();
   MAX_STORED_INDEX = maxItem;
 }