Ejemplo n.º 1
0
  @Override
  protected void extractTransactions(
      long startingAtTransactionId,
      Visitor<CommittedTransactionRepresentation, IOException> accumulator)
      throws IOException {
    try {
      super.extractTransactions(startingAtTransactionId, accumulator);
    } catch (NoSuchTransactionException e) {
      // We no longer have transactions that far back. Which transaction is the farthest back?
      if (startingAtTransactionId < mandatoryStartTransactionId) {
        // We don't necessarily need to ask that far back. Ask which is the oldest transaction in
        // the log(s)
        // that we can possibly serve
        long oldestExistingTransactionId = logFileInformation.getFirstExistingTxId();
        if (oldestExistingTransactionId == -1) {
          // Seriously, there are no logs that we can serve?
          if (mandatoryStartTransactionId >= transactionIdStore.getLastCommittedTransactionId()) {
            // Although there are no mandatory transactions to stream, so we're good here.
            return;
          }

          // We are required to serve one or more transactions, but there are none, tell that
          throw e;
        }

        if (oldestExistingTransactionId <= mandatoryStartTransactionId) {
          super.extractTransactions(oldestExistingTransactionId, accumulator);
        }

        // We can't serve the mandatory transactions, tell that
        throw e;
      }
    }
  }
Ejemplo n.º 2
0
  /** @return a {@link RequestContext} specifying at which point the store copy started. */
  public RequestContext flushStoresAndStreamStoreFiles(StoreWriter writer, boolean includeLogs) {
    try {
      long lastAppliedTransaction = transactionIdStore.getLastClosedTransactionId();
      monitor.startFlushingEverything();
      logRotationControl.forceEverything();
      monitor.finishFlushingEverything();
      ByteBuffer temporaryBuffer = ByteBuffer.allocateDirect(1024 * 1024);

      // Copy the store files
      monitor.startStreamingStoreFiles();
      try (ResourceIterator<File> files = dataSource.listStoreFiles(includeLogs)) {
        while (files.hasNext()) {
          File file = files.next();
          try (StoreChannel fileChannel = fileSystem.open(file, "r")) {
            monitor.startStreamingStoreFile(file);
            writer.write(
                relativePath(storeDirectory, file),
                fileChannel,
                temporaryBuffer,
                file.length() > 0);
            monitor.finishStreamingStoreFile(file);
          }
        }
      } finally {
        monitor.finishStreamingStoreFiles();
      }

      return anonymous(lastAppliedTransaction);
    } catch (IOException e) {
      throw new ServerFailureException(e);
    }
  }