|
Action Engine
|
A utility for reading chunks from a ChunkStore.
This class provides an interface for reading chunks from a ChunkStore. It supports reading chunks in order (explicitly specified) or unordered (as ingested to the store), and can buffer chunks in memory to improve performance.
The reader can be cancelled, which stops the background prefetch fiber and prevents further reading from the store. The remaining prefetched chunks can still be read until the buffer is empty.
#include <chunk_store_reader.h>
Public Member Functions | |
| ChunkStoreReader (ChunkStore *absl_nonnull chunk_store, ChunkStoreReaderOptions options=ChunkStoreReaderOptions()) | |
Constructs a ChunkStoreReader for the given ChunkStore, setting options if provided. | |
| void | Cancel () const |
| Cancels the background prefetch fiber and stops reading from the store. | |
| void | SetOptions (const ChunkStoreReaderOptions &options) |
| Sets the options for the ChunkStoreReader. | |
| const ChunkStoreReaderOptions & | GetOptions () const |
| Returns the current options of the ChunkStoreReader. | |
| absl::StatusOr< std::optional< Chunk > > | Next (std::optional< absl::Duration > timeout=std::nullopt) |
| Reads the next chunk from the ChunkStore. | |
| template<typename T> | |
| absl::StatusOr< std::optional< T > > | Next (std::optional< absl::Duration > timeout=std::nullopt) |
Same as Next(), but casts the chunk to the specified type T. | |
| absl::Status | GetStatus () const |
| Returns the status of the background prefetch loop. | |
|
explicit |
Constructs a ChunkStoreReader for the given ChunkStore, setting options if provided.
| chunk_store | The ChunkStore to read from. Must not be null. |
| options | Options for the reader, such as whether to read in order, buffer size, and timeout. |
| void act::ChunkStoreReader::Cancel | ( | ) | const |
Cancels the background prefetch fiber and stops reading from the store.
Does not prevent further reading of chunks that have already been prefetched into the buffer. The buffer will be closed, and no further chunks will be read from the store. If the reader is already cancelled, this method does nothing.
|
inlinenodiscard |
Returns the current options of the ChunkStoreReader.
| absl::Status act::ChunkStoreReader::GetStatus | ( | ) | const |
Returns the status of the background prefetch loop.
This status will be absl::OkStatus() unless and until the prefetch loop has encountered an error, and then it will contain the error status.
| absl::StatusOr< std::optional< Chunk > > act::ChunkStoreReader::Next | ( | std::optional< absl::Duration > | timeout = std::nullopt | ) |
Reads the next chunk from the ChunkStore.
If the reader is ordered, it will read the next chunk in the order of their seq numbers. If the reader is unordered, it will read the next chunk that has arrived in the store. This method respects cancellation and will return an error if the calling fiber has been cancelled.
| timeout | An optional timeout for reading the next chunk. If not provided, the default timeout from options_ will be used. |
std::nullopt if there are no more chunks to read. If unsuccessful, returns an error status, which may indicate cancellation or timeout.
|
inline |
Same as Next(), but casts the chunk to the specified type T.
The cast is done using the FromChunkAs<T>() function, which must be defined for the type T. For custom types, this is ensured by providing the overload EgltAssignInto(Chunk, T*) in the global namespace or that of the type T.
| void act::ChunkStoreReader::SetOptions | ( | const ChunkStoreReaderOptions & | options | ) |
Sets the options for the ChunkStoreReader.
This method can only be called before the reader is started (i.e., before the first call to Next()). If called after the reader has been started, the program will be terminated with a CHECK failure.
| options | The options to set for the reader. |