|
|
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 BatchWriteStatistics & | getBatchStatistics () const |
| Get batch write statistics. | |
| int | getCompressionLevel () const |
| std::size_t | getCompressionMinBytes () const |
| 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. | |
| bool | isCompressionEnabled () const |
| 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 | setCompressionEnabled (bool enable) |
| Enable transparent gzip compression of exported JSON files. | |
| void | setCompressionLevel (int level) |
| zlib level, 1 (fastest) to 9 (smallest). Default 1 - see gzipCompress(). | |
| void | setCompressionMinBytes (std::size_t bytes) |
| Only compress payloads of at least this many bytes. | |
| 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 |
Static Public Attributes | |
| static constexpr const char * | GZIP_SUFFIX = ".gz" |
| Suffix appended to the logical key when an item is stored compressed. | |
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" |
Additional Inherited Members | |
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. | |
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.
|
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:
|
inline |
|
inline |
| identifier | basically a unique name for the strategy (important if you use different strategies |
| exportName | identifier for the exported memory. A new directory with name is created beneath the memoryParentPath. Everything is stored inside it. |
| memoryParentPath | path where the memory should be exported to |
Definition at line 123 of file DiskPersistence.h.
Here is the call graph for this function:
|
inlinevirtual |
Destructor - flushes pending batch and stops batch thread.
Definition at line 133 of file DiskPersistence.h.
|
overridevirtual |
Checks if the container is available for the current memory id.
Implements MemoryPersistenceStrategy.
Definition at line 201 of file DiskPersistence.cpp.
Here is the call graph for this function:
|
overridevirtual |
Checks if current container contains the item defined by its key.
Implements MemoryPersistenceStrategy.
Definition at line 217 of file DiskPersistence.cpp.
|
inlineoverridevirtual |
Implements MemoryPersistenceStrategy.
Definition at line 177 of file DiskPersistence.h.
| void flushBatch | ( | ) |
Explicitly flush all pending batch writes to disk.
This is automatically called when batch thresholds are reached.
Definition at line 669 of file DiskPersistence.cpp.
Here is the caller graph for this function:| size_t getBatchPendingCount | ( | ) | const |
Get the current number of items pending in the batch buffer.
Definition at line 675 of file DiskPersistence.cpp.
|
inline |
Get batch write statistics.
Definition at line 276 of file DiskPersistence.h.
|
inline |
Definition at line 219 of file DiskPersistence.h.
|
inline |
Definition at line 231 of file DiskPersistence.h.
|
overridevirtual |
Returns all containers for the current id.
Implements MemoryPersistenceStrategy.
Definition at line 71 of file DiskPersistence.cpp.
Here is the call graph for this function:
|
overridevirtual |
Returns all items for the current id.
Implements MemoryPersistenceStrategy.
Definition at line 154 of file DiskPersistence.cpp.
|
inline |
Definition at line 285 of file DiskPersistence.h.
|
inline |
Check if batch writing is enabled.
Definition at line 248 of file DiskPersistence.h.
|
inline |
Definition at line 214 of file DiskPersistence.h.
|
inline |
Reset batch write statistics.
Definition at line 281 of file DiskPersistence.h.
|
inline |
Definition at line 290 of file DiskPersistence.h.
|
overridevirtual |
Reads the data of the file with name 'key' at the current location.
Implements MemoryPersistenceStrategy.
Definition at line 354 of file DiskPersistence.cpp.
Here is the call graph for this function:
|
inline |
Set the maximum number of items to accumulate before auto-flushing.
| size | Maximum batch size (default: 100) |
Definition at line 254 of file DiskPersistence.h.
|
inline |
Set the maximum time to hold items before auto-flushing.
| ms | Maximum time in milliseconds (default: 100ms) |
Definition at line 260 of file DiskPersistence.h.
| void setBatchWriteEnabled | ( | bool | enable | ) |
Enable or disable batch writing.
When enabled, writes are accumulated and flushed in batches for better I/O performance.
| enable | True to enable batching, false for immediate writes (default behavior) |
Definition at line 611 of file DiskPersistence.cpp.
Here is the call graph for this function:
|
inline |
Enable transparent gzip compression of exported JSON files.
When enabled, items whose key ends in ".json" and whose payload is at least getCompressionMinBytes() large are gzipped and stored under "<key>.gz". Reading is unaffected: containsItem()/retrieveItem() accept the plain (logical) key and transparently fall back to the ".gz" variant, and getItemKeys() reports logical keys. Exports written before this feature existed therefore keep working, and an export may freely mix both.
The compressed file deliberately gets a ".gz" suffix rather than being compressed in place under the original name: a reader that does not know about compression then simply does not find the file, instead of choking on unparsable content.
Definition at line 212 of file DiskPersistence.h.
Here is the call graph for this function:
|
inline |
zlib level, 1 (fastest) to 9 (smallest). Default 1 - see gzipCompress().
Definition at line 217 of file DiskPersistence.h.
|
inline |
Only compress payloads of at least this many bytes.
Defaults to one filesystem block (4096). Compressing anything smaller cannot free a single block, so it would cost compatibility (older readers no longer find the file) for no disk saving at all. In practice this leaves metadata.aron.json and type.aron.json as plain JSON and only compresses the instance data, which is where the size actually is.
Definition at line 229 of file DiskPersistence.h.
|
inline |
Definition at line 183 of file DiskPersistence.h.
|
overridevirtual |
Create a new file with name 'key' and stores the data inside it.
Implements MemoryPersistenceStrategy.
Definition at line 230 of file DiskPersistence.cpp.
Here is the call graph for this function:| void validateStoragePermissions | ( | ) |
|
staticconstexpr |
Suffix appended to the logical key when an item is stored compressed.
Definition at line 234 of file DiskPersistence.h.
| int minDiskSpace = 50 |
Definition at line 195 of file DiskPersistence.h.