DiskPersistence Class Reference

Persistence strategy that writes items (e.g. More...

#include <RobotAPI/libraries/armem/server/ltm/persistence/disk/DiskPersistence.h>

+ Inheritance diagram for DiskPersistence:

Public Member Functions

bool containsContainer (const armarx::armem::MemoryID &id, std::string key) override
 Checks if the container is available for the current memory id.
 
bool containsItem (const armarx::armem::MemoryID &id, std::string key) override
 Checks if current container contains the item defined by its key.
 
void createPropertyDefinitions (PropertyDefinitionsPtr &defs, const std::string &prefix) override
 
 DiskPersistence ()
 
 DiskPersistence (const std::filesystem::path &memoryParentPath)
 
 DiskPersistence (const std::string &identifier, const std::string &exportName, const std::filesystem::path &memoryParentPath)
 
void flushBatch ()
 Explicitly flush all pending batch writes to disk.
 
size_t getBatchPendingCount () const
 Get the current number of items pending in the batch buffer.
 
const BatchWriteStatisticsgetBatchStatistics () const
 Get batch write statistics.
 
std::vector< std::string > getContainerKeys (const armarx::armem::MemoryID &id) override
 Returns all containers for the current id.
 
std::vector< std::string > getItemKeys (const armarx::armem::MemoryID &id) override
 Returns all items for the current id.
 
size_t getStorageErrorCount () const
 
bool isBatchWriteEnabled () const
 Check if batch writing is enabled.
 
void resetBatchStatistics ()
 Reset batch write statistics.
 
void resetStorageErrorCount ()
 
std::vector< unsigned char > retrieveItem (const armarx::armem::MemoryID &id, std::string key) override
 Reads the data of the file with name 'key' at the current location.
 
void setBatchSizeThreshold (size_t size)
 Set the maximum number of items to accumulate before auto-flushing.
 
void setBatchTimeThresholdMs (size_t ms)
 Set the maximum time to hold items before auto-flushing.
 
void setBatchWriteEnabled (bool enable)
 Enable or disable batch writing.
 
void setMinAvailableDiskSpace (const int minDiskSpace)
 
void storeItem (const armarx::armem::MemoryID &id, std::string key, std::vector< unsigned char > &data) override
 Create a new file with name 'key' and stores the data inside it.
 
void validateStoragePermissions ()
 
virtual ~DiskPersistence ()
 Destructor - flushes pending batch and stops batch thread.
 
- Public Member Functions inherited from MemoryPersistenceStrategy
virtual void disable ()
 
virtual void enable ()
 
std::string getExportName ()
 
std::string getIdentifier ()
 
virtual bool isEnabled ()
 
 MemoryPersistenceStrategy ()
 
 MemoryPersistenceStrategy (const std::string &identifier, const std::string &exportName, bool enabled=true)
 
std::vector< unsigned char > retrieveItem (const armarx::armem::MemoryID &memoryId, ItemIdentifier itemIdentifier)
 
virtual ItemResult retrieveItemWithOrigin (const armarx::armem::MemoryID &id, std::string &key)
 Retrieves the actual data but also appends the origin which is in this case the strategy identifier.
 
virtual void setExportName (const std::string &exportName)
 
void setIdentifier (const std::string &identifier)
 
void storeItem (const armarx::armem::MemoryID &memoryId, ItemIdentifier itemIdentifer, std::vector< unsigned char > &data)
 
virtual ~MemoryPersistenceStrategy ()=default
 

Public Attributes

int minDiskSpace = 50
 

Additional Inherited Members

- Static Public Attributes inherited from MemoryPersistenceStrategy
static const constexpr char * DATA_FILENAME = "data.aron"
 
static const int DEPTH_TO_DATA_FILES = 7
 
static const constexpr char * MEMORY_EXPORT_SUFFIX = "_"
 
static const constexpr char * METADATA_FILENAME = "metadata.aron"
 
static const constexpr char * TYPE_FILENAME = "type.aron"
 
- Protected Attributes inherited from MemoryPersistenceStrategy
bool enabled_ = true
 If false, the strategy is not writing or reading anything.
 
std::string exportName_
 Name of the specific memory export where our items should be stored.
 
std::string identifier_
 Name of the strategy.
 

Detailed Description

Persistence strategy that writes items (e.g.

json files) to a specific container (a directory) Use it to write the data of a WM to disk.

Where are the items written (=:location)? /memoryParentPath/exportName/path(id)/

How is the file of an item named? -> Just they key (e.g. filename = key = "data.aron.json") If you might want a more sophisticated solution fell free to implement your custom ItemIdentifier today!

Definition at line 106 of file DiskPersistence.h.

Constructor & Destructor Documentation

◆ DiskPersistence() [1/3]

DiskPersistence ( )
inline

Definition at line 109 of file DiskPersistence.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DiskPersistence() [2/3]

DiskPersistence ( const std::filesystem::path & memoryParentPath)
inline

Definition at line 113 of file DiskPersistence.h.

+ Here is the call graph for this function:

◆ DiskPersistence() [3/3]

DiskPersistence ( const std::string & identifier,
const std::string & exportName,
const std::filesystem::path & memoryParentPath )
inline
Parameters
identifierbasically a unique name for the strategy (important if you use different strategies
See also
RedundantPersistenceStrategy)
Parameters
exportNameidentifier for the exported memory. A new directory with name is created beneath the memoryParentPath. Everything is stored inside it.
memoryParentPathpath where the memory should be exported to

Definition at line 123 of file DiskPersistence.h.

+ Here is the call graph for this function:

◆ ~DiskPersistence()

virtual ~DiskPersistence ( )
inlinevirtual

Destructor - flushes pending batch and stops batch thread.

Definition at line 133 of file DiskPersistence.h.

Member Function Documentation

◆ containsContainer()

bool containsContainer ( const armarx::armem::MemoryID & id,
std::string key )
overridevirtual

Checks if the container is available for the current memory id.

Returns
true if the current location contains the directory with name 'key'

Implements MemoryPersistenceStrategy.

Definition at line 137 of file DiskPersistence.cpp.

+ Here is the call graph for this function:

◆ containsItem()

bool containsItem ( const armarx::armem::MemoryID & id,
std::string key )
overridevirtual

Checks if current container contains the item defined by its key.

Returns
true if the current location contains a file with the name 'key'

Implements MemoryPersistenceStrategy.

Definition at line 153 of file DiskPersistence.cpp.

◆ createPropertyDefinitions()

void createPropertyDefinitions ( PropertyDefinitionsPtr & defs,
const std::string & prefix )
inlineoverridevirtual

Implements MemoryPersistenceStrategy.

Definition at line 177 of file DiskPersistence.h.

◆ flushBatch()

void flushBatch ( )

Explicitly flush all pending batch writes to disk.

This is automatically called when batch thresholds are reached.

Definition at line 524 of file DiskPersistence.cpp.

+ Here is the caller graph for this function:

◆ getBatchPendingCount()

size_t getBatchPendingCount ( ) const

Get the current number of items pending in the batch buffer.

Definition at line 530 of file DiskPersistence.cpp.

◆ getBatchStatistics()

const BatchWriteStatistics & getBatchStatistics ( ) const
inline

Get batch write statistics.

Definition at line 237 of file DiskPersistence.h.

◆ getContainerKeys()

std::vector< std::string > getContainerKeys ( const armarx::armem::MemoryID & id)
overridevirtual

Returns all containers for the current id.

Returns
containers <=> directories at current location (=/memoryParentPath/exportName/path(id)/)

Implements MemoryPersistenceStrategy.

Definition at line 14 of file DiskPersistence.cpp.

+ Here is the call graph for this function:

◆ getItemKeys()

std::vector< std::string > getItemKeys ( const armarx::armem::MemoryID & id)
overridevirtual

Returns all items for the current id.

Returns
items <=> files at the current location (=/memoryParentPath/exportName/path(id)/)

Implements MemoryPersistenceStrategy.

Definition at line 97 of file DiskPersistence.cpp.

◆ getStorageErrorCount()

size_t getStorageErrorCount ( ) const
inline

Definition at line 246 of file DiskPersistence.h.

◆ isBatchWriteEnabled()

bool isBatchWriteEnabled ( ) const
inline

Check if batch writing is enabled.

Definition at line 209 of file DiskPersistence.h.

◆ resetBatchStatistics()

void resetBatchStatistics ( )
inline

Reset batch write statistics.

Definition at line 242 of file DiskPersistence.h.

◆ resetStorageErrorCount()

void resetStorageErrorCount ( )
inline

Definition at line 251 of file DiskPersistence.h.

◆ retrieveItem()

std::vector< unsigned char > retrieveItem ( const armarx::armem::MemoryID & id,
std::string key )
overridevirtual

Reads the data of the file with name 'key' at the current location.

Returns
data if a file was found, an empty vector if the file is empty or was not found

Implements MemoryPersistenceStrategy.

Definition at line 261 of file DiskPersistence.cpp.

◆ setBatchSizeThreshold()

void setBatchSizeThreshold ( size_t size)
inline

Set the maximum number of items to accumulate before auto-flushing.

Parameters
sizeMaximum batch size (default: 100)

Definition at line 215 of file DiskPersistence.h.

◆ setBatchTimeThresholdMs()

void setBatchTimeThresholdMs ( size_t ms)
inline

Set the maximum time to hold items before auto-flushing.

Parameters
msMaximum time in milliseconds (default: 100ms)

Definition at line 221 of file DiskPersistence.h.

◆ setBatchWriteEnabled()

void setBatchWriteEnabled ( bool enable)

Enable or disable batch writing.

When enabled, writes are accumulated and flushed in batches for better I/O performance.

Parameters
enableTrue to enable batching, false for immediate writes (default behavior)

Definition at line 466 of file DiskPersistence.cpp.

+ Here is the call graph for this function:

◆ setMinAvailableDiskSpace()

void setMinAvailableDiskSpace ( const int minDiskSpace)
inline

Definition at line 183 of file DiskPersistence.h.

◆ storeItem()

void storeItem ( const armarx::armem::MemoryID & id,
std::string key,
std::vector< unsigned char > & data )
overridevirtual

Create a new file with name 'key' and stores the data inside it.

Implements MemoryPersistenceStrategy.

Definition at line 164 of file DiskPersistence.cpp.

+ Here is the call graph for this function:

◆ validateStoragePermissions()

void validateStoragePermissions ( )

Definition at line 443 of file DiskPersistence.cpp.

+ Here is the call graph for this function:

Member Data Documentation

◆ minDiskSpace

int minDiskSpace = 50

Definition at line 195 of file DiskPersistence.h.


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