Package org.yamcs.cfdp
Class CfdpTransferStore
java.lang.Object
org.yamcs.cfdp.CfdpTransferStore
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>.dataand<id>.journal: the file data (seeDiskDataFile).<id>.state: aTransferSnapshotprotobuf message with the state of the transfer, written atomically.
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Waits for the pending operations to finish and stops the I/O thread.createDataFile(long id) Create a new empty data file for the transfer; existing files are truncated.dataPath(long id) voiddelete(long id) Delete all the files of the given transfervoiddeleteAsync(long id, AbstractDataFile dataFile) Asynchronously deletes the data file and all the files of the transfer, after the pending writes.voidflush()Waits for all the pending operations to finishjournalPath(long id) Returns the ids of all the transfers which have at least one file in the directory.openDataFile(long id, long maxEnd) Open the existing data file of the transfer, verifying its integrity (seeDiskDataFile).readState(long id) Reads the state of the transfer.voidsaveState(long id, AbstractDataFile dataFile, TransferSnapshot snapshot) Same assaveStateAsync(long, AbstractDataFile, TransferSnapshot)but waits for the write to finish.voidsaveStateAsync(long id, AbstractDataFile dataFile, TransferSnapshot snapshot) Asynchronously syncs the data file (if not null) and then writes the snapshot.statePath(long id) <T> CompletableFuture<T>supplyAsync(Callable<T> task) Runs a (blocking) I/O task on the I/O thread, after the pending operations.voidsyncAsync(AbstractDataFile dataFile) Asynchronously syncs the data file.voidwriteState(long id, TransferSnapshot snapshot) Atomically write the state of a transfer (tmp file + fsync + rename).
-
Field Details
-
DATA_EXT
- See Also:
-
JOURNAL_EXT
- See Also:
-
STATE_EXT
- See Also:
-
-
Constructor Details
-
CfdpTransferStore
- Throws:
IOException
-
-
Method Details
-
getDirectory
-
dataPath
-
journalPath
-
statePath
-
createDataFile
Create a new empty data file for the transfer; existing files are truncated.- Throws:
IOException
-
openDataFile
Open the existing data file of the transfer, verifying its integrity (seeDiskDataFile).- Parameters:
maxEnd- data beyond this offset is discarded; -1 for no limit- Throws:
IOException
-
writeState
Atomically write the state of a transfer (tmp file + fsync + rename).- Throws:
IOException
-
saveStateAsync
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 assaveStateAsync(long, AbstractDataFile, TransferSnapshot)but waits for the write to finish.- Throws:
IOException
-
syncAsync
Asynchronously syncs the data file. -
deleteAsync
Asynchronously deletes the data file and all the files of the transfer, after the pending writes. -
supplyAsync
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
Reads the state of the transfer.- Returns:
- null if there is no state file
- Throws:
IOException
-
listTransferIds
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
-