Action Engine
Loading...
Searching...
No Matches
act::ChunkStoreReader Class Reference

Detailed Description

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 ChunkStoreReaderOptionsGetOptions () 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.
 

Constructor & Destructor Documentation

◆ ChunkStoreReader()

act::ChunkStoreReader::ChunkStoreReader ( ChunkStore *absl_nonnull chunk_store,
ChunkStoreReaderOptions options = ChunkStoreReaderOptions() )
explicit

Constructs a ChunkStoreReader for the given ChunkStore, setting options if provided.

Parameters
chunk_storeThe ChunkStore to read from. Must not be null.
optionsOptions for the reader, such as whether to read in order, buffer size, and timeout.

Member Function Documentation

◆ Cancel()

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.

◆ GetOptions()

const ChunkStoreReaderOptions & act::ChunkStoreReader::GetOptions ( ) const
inlinenodiscard

Returns the current options of the ChunkStoreReader.

Returns
The current options of the reader.

◆ GetStatus()

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.

◆ Next() [1/2]

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.

Parameters
timeoutAn optional timeout for reading the next chunk. If not provided, the default timeout from options_ will be used.
Returns
The next chunk, or std::nullopt if there are no more chunks to read. If unsuccessful, returns an error status, which may indicate cancellation or timeout.
Note
Issues encountered while reading from the store are NOT returned here, but rather in the GetStatus() method.

◆ Next() [2/2]

template<typename T>
absl::StatusOr< std::optional< T > > act::ChunkStoreReader::Next ( std::optional< absl::Duration > timeout = std::nullopt)
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.

◆ SetOptions()

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.

Parameters
optionsThe options to set for the reader.
Note
You can use designated initializers to set only the options you want to be different from the defaults. For example:
reader.SetOptions({.ordered = false});

The documentation for this class was generated from the following files: