org.rocksdb.TransactionLogIterator Java Examples

The following examples show how to use org.rocksdb.TransactionLogIterator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ByteStoreManager.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
void replaySince(final long transactionNumber, ReplayHandler replayHandler) {
  final ReplayHandlerWithPtrResolution replayHandlerWrapper = new ReplayHandlerWithPtrResolution(replayHandler);

  try (ReplayHandlerAdapter handler =
           new ReplayHandlerAdapter(db.getDefaultColumnFamily().getID(), replayHandlerWrapper, handleIdToNameMap);
       TransactionLogIterator iterator = db.getUpdatesSince(transactionNumber)) {
    while (iterator.isValid()) {
      iterator.status();

      final TransactionLogIterator.BatchResult result = iterator.getBatch(); // requires isValid and status check
      LOGGER.debug("Requested sequence number: {}, iterator sequence number: {}",
          transactionNumber, result.sequenceNumber());

      result.writeBatch()
          .iterate(handler);

      if (!iterator.isValid()) {
        break;
      }
      iterator.next(); // requires isValid
    }

    for (String updatedStore : handler.getUpdatedStores()) {
      final long latestTransactionNumber = metadataManager.getLatestTransactionNumber();
      metadataManager.setLatestTransactionNumber(updatedStore, latestTransactionNumber, latestTransactionNumber);
    }
  } catch (RocksDBException e) {
    throw new DatastoreException(e);
  }
}
 
Example #2
Source File: Webapp.java    From outbackcdx with Apache License 2.0 5 votes vote down vote up
Response changeFeed(Web.Request request) throws Web.ResponseException, IOException {
    String collection = request.param("collection");
    long since = Long.parseLong(request.param("since", "0"));
    long size = 10*1024*1024;
    if (request.param("size") != null) {
        size = Long.parseLong(request.param("size"));
    }

    final Index index = getIndex(request);

    if (verbose) {
        out.println(String.format("%s Received request %s. Retrieving deltas for collection <%s> since sequenceNumber %s", new Date(), request, collection, since));
    }

    try {
        /* This method must not close logReader, or you will get a segfault.
         * The response payload stream class ChangeFeedJsonStream closes it
         * when it's finished with it. */
        TransactionLogIterator logReader = index.getUpdatesSince(since);

        ChangeFeedJsonStream streamer = new ChangeFeedJsonStream(logReader, size);
        Response response = new Response(OK, "application/json", streamer);
        response.addHeader("Access-Control-Allow-Origin", "*");
        return response;
    } catch (RocksDBException e) {
        System.err.println(new Date() + " " + request.method() + " " + request.url() + " - " + e);
        if (!"Requested sequence not yet written in the db".equals(e.getMessage())) {
            e.printStackTrace();
        }
        throw new Web.ResponseException(
                new Response(Status.INTERNAL_ERROR, "text/plain", e.toString() + "\n"));
    }
}
 
Example #3
Source File: RDBStore.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
@Override
public DBUpdatesWrapper getUpdatesSince(long sequenceNumber)
    throws SequenceNumberNotFoundException {

  DBUpdatesWrapper dbUpdatesWrapper = new DBUpdatesWrapper();
  try {
    TransactionLogIterator transactionLogIterator =
        db.getUpdatesSince(sequenceNumber);

    // Only the first record needs to be checked if its seq number <
    // ( 1 + passed_in_sequence_number). For example, if seqNumber passed
    // in is 100, then we can read from the WAL ONLY if the first sequence
    // number is <= 101. If it is 102, then 101 may already be flushed to
    // SST. If it 99, we can skip 99 and 100, and then read from 101.

    boolean checkValidStartingSeqNumber = true;

    while (transactionLogIterator.isValid()) {
      TransactionLogIterator.BatchResult result =
          transactionLogIterator.getBatch();
      long currSequenceNumber = result.sequenceNumber();
      if (checkValidStartingSeqNumber &&
          currSequenceNumber > 1 + sequenceNumber) {
        throw new SequenceNumberNotFoundException("Unable to read data from" +
            " RocksDB wal to get delta updates. It may have already been" +
            "flushed to SSTs.");
      }
      // If the above condition was not satisfied, then it is OK to reset
      // the flag.
      checkValidStartingSeqNumber = false;
      if (currSequenceNumber <= sequenceNumber) {
        transactionLogIterator.next();
        continue;
      }
      dbUpdatesWrapper.addWriteBatch(result.writeBatch().data(),
          result.sequenceNumber());
      transactionLogIterator.next();
    }
  } catch (RocksDBException e) {
    LOG.error("Unable to get delta updates since sequenceNumber {} ",
        sequenceNumber, e);
  }
  return dbUpdatesWrapper;
}
 
Example #4
Source File: Index.java    From outbackcdx with Apache License 2.0 4 votes vote down vote up
public TransactionLogIterator getUpdatesSince(long sequenceNumber) throws RocksDBException {
    TransactionLogIterator logReader = db.getUpdatesSince(sequenceNumber);
    return logReader;
}
 
Example #5
Source File: Webapp.java    From outbackcdx with Apache License 2.0 4 votes vote down vote up
ChangeFeedJsonStream(TransactionLogIterator logReader, long batchSize) {
    this.logReader = logReader;
    this.batchSize = batchSize;
}