Class CfdpTransferStore

java.lang.Object
org.yamcs.cfdp.CfdpTransferStore

public class CfdpTransferStore extends Object
Manages the per-service directory where the CFDP transfers in progress are stored.

For each transfer (identified by its unique id) the following files may exist:

  • <id>.data and <id>.journal: the file data (see DiskDataFile).
  • <id>.state: a TransferSnapshot protobuf message with the state of the transfer, written atomically.
The class is direction agnostic: the content of the files is interpreted by the transfers.

The operations which force data to the disk (fsync) are slow (milliseconds) so they are performed asynchronously by a dedicated I/O thread: the CFDP state machine just hands over the snapshot to be written (saveStateAsync(long, AbstractDataFile, TransferSnapshot)); consecutive snapshots of the same transfer are coalesced. Before writing a snapshot, the data file is synced such that the state never refers to data which is not on disk.

  • Field Details

  • Constructor Details

  • Method Details

    • getDirectory

      public Path getDirectory()
    • dataPath

      public Path dataPath(long id)
    • journalPath

      public Path journalPath(long id)
    • statePath

      public Path statePath(long id)
    • createDataFile

      public DiskDataFile createDataFile(long id) throws IOException
      Create a new empty data file for the transfer; existing files are truncated.
      Throws:
      IOException
    • openDataFile

      public DiskDataFile openDataFile(long id, long maxEnd) throws IOException
      Open the existing data file of the transfer, verifying its integrity (see DiskDataFile).
      Parameters:
      maxEnd - data beyond this offset is discarded; -1 for no limit
      Throws:
      IOException
    • writeState

      public void writeState(long id, TransferSnapshot snapshot) throws IOException
      Atomically write the state of a transfer (tmp file + fsync + rename).
      Throws:
      IOException
    • saveStateAsync

      public void saveStateAsync(long id, AbstractDataFile dataFile, TransferSnapshot snapshot)
      Asynchronously syncs the data file (if not null) and then writes the snapshot.

      If there is already a pending write for the same transfer, the snapshot replaces the pending one.

    • saveState

      public void saveState(long id, AbstractDataFile dataFile, TransferSnapshot snapshot) throws IOException
      Same as saveStateAsync(long, AbstractDataFile, TransferSnapshot) but waits for the write to finish.
      Throws:
      IOException
    • syncAsync

      public void syncAsync(AbstractDataFile dataFile)
      Asynchronously syncs the data file.
    • deleteAsync

      public void deleteAsync(long id, AbstractDataFile dataFile)
      Asynchronously deletes the data file and all the files of the transfer, after the pending writes.
    • supplyAsync

      public <T> CompletableFuture<T> supplyAsync(Callable<T> task)
      Runs a (blocking) I/O task on the I/O thread, after the pending operations.
    • flush

      public void flush()
      Waits for all the pending operations to finish
    • close

      public void close()
      Waits for the pending operations to finish and stops the I/O thread.
    • readState

      public TransferSnapshot readState(long id) throws IOException
      Reads the state of the transfer.
      Returns:
      null if there is no state file
      Throws:
      IOException
    • listTransferIds

      public SortedSet<Long> listTransferIds() throws IOException
      Returns the ids of all the transfers which have at least one file in the directory.

      Left-over temporary files are removed.

      Throws:
      IOException
    • delete

      public void delete(long id)
      Delete all the files of the given transfer