MaxHistorySize.h
Go to the documentation of this file.
1#pragma once
2
4{
5 // TODO: Replace by ConstrainedHistorySize (not only max entries, e.g. delete oldest / delete least accessed / ...)
6
8 {
9 public:
10 /**
11 * @brief Set the maximum number of snapshots to be contained in an entity.
12 * Affected entities are to be update right away.
13 */
14 void setMaxHistorySize(long maxSize, const std::string& additionalInfo = "");
15
16 long getMaxHistorySize() const;
17
18 /**
19 * @brief Set the threshold for warning about unlimited history growth.
20 * When maxHistorySize is negative (unlimited) and the number of snapshots
21 * exceeds this threshold, a warning will be emitted.
22 * Set to 0 to disable the warning.
23 */
24 void setUnlimitedHistoryWarningThreshold(size_t threshold);
25
27
28 /**
29 * @brief Set the maximum number of snapshots to remove per truncate() call.
30 * This prevents long blocking when many snapshots need to be removed.
31 * Set to 0 for unlimited (remove all excess in one call).
32 */
33 void setTruncateMaxBatchSize(size_t batchSize);
34
35 size_t getTruncateMaxBatchSize() const;
36
37
38 protected:
39 /**
40 * @brief Maximum size of entity histories.
41 *
42 * If negative, the size of `history` is not limited.
43 * Default: 120,000 snapshots (10 minutes at 200Hz).
44 *
45 * @see Entity::maxHstorySize
46 */
47 long _maxHistorySize = 120000;
48
49 /**
50 * @brief Threshold for warning about unlimited history growth.
51 * When maxHistorySize < 0 and container size exceeds this value,
52 * a throttled warning is emitted. Set to 0 to disable.
53 * Default: 500,000 snapshots.
54 */
56
57 /**
58 * @brief Maximum number of snapshots to remove per truncate() call.
59 * Limits blocking time when many snapshots exceed the limit.
60 * Set to 0 for unlimited. Default: 100 snapshots per call.
61 */
63 };
64
65 template <class DerivedT>
67 {
68 public:
69 /**
70 * @brief Sets the maximum history size of entities in this container.
71 * This affects all current entities as well as new ones.
72 *
73 * @see MaxHistorySize::setMaxHistorySize()
74 */
75 void
76 setMaxHistorySize(long maxSize)
77 {
79 static_cast<DerivedT&>(*this).forEachChild([maxSize](auto& child)
80 { child.setMaxHistorySize(maxSize); });
81 }
82
83 /**
84 * @brief Sets the warning threshold for unlimited history growth.
85 * This affects all current entities as well as new ones.
86 *
87 * @see MaxHistorySize::setUnlimitedHistoryWarningThreshold()
88 */
89 void
91 {
93 static_cast<DerivedT&>(*this).forEachChild(
94 [threshold](auto& child)
95 { child.setUnlimitedHistoryWarningThreshold(threshold); });
96 }
97
98 /**
99 * @brief Sets the maximum batch size for truncation.
100 * This affects all current entities as well as new ones.
101 *
102 * @see MaxHistorySize::setTruncateMaxBatchSize()
103 */
104 void
105 setTruncateMaxBatchSize(size_t batchSize)
106 {
108 static_cast<DerivedT&>(*this).forEachChild(
109 [batchSize](auto& child) { child.setTruncateMaxBatchSize(batchSize); });
110 }
111 };
112} // namespace armarx::armem::server::wm::detail
void setMaxHistorySize(long maxSize)
Sets the maximum history size of entities in this container.
void setTruncateMaxBatchSize(size_t batchSize)
Sets the maximum batch size for truncation.
void setUnlimitedHistoryWarningThreshold(size_t threshold)
Sets the warning threshold for unlimited history growth.
long _maxHistorySize
Maximum size of entity histories.
size_t _truncateMaxBatchSize
Maximum number of snapshots to remove per truncate() call.
size_t _unlimitedHistoryWarningThreshold
Threshold for warning about unlimited history growth.
void setTruncateMaxBatchSize(size_t batchSize)
Set the maximum number of snapshots to remove per truncate() call.
void setUnlimitedHistoryWarningThreshold(size_t threshold)
Set the threshold for warning about unlimited history growth.
void setMaxHistorySize(long maxSize, const std::string &additionalInfo="")
Set the maximum number of snapshots to be contained in an entity.