31 ARMARX_INFO <<
"Persistence strategies=" << persistenceStrategiesStr;
33 std::vector<std::string> persistenceStrategies = split(persistenceStrategiesStr,
',');
35 ARMARX_INFO <<
"Found " << persistenceStrategies.size() <<
" persistence strategies";
39 std::vector<std::string>
identifiers = split(identifiersStr,
',');
40 std::string identifier =
"defaultStrategy";
41 ARMARX_INFO <<
"Persistence identifiers=" << identifiersStr;
45 std::shared_ptr<armem::server::ltm::persistence::RedundantPersistenceStrategy>
46 redundantPersistence =
47 std::make_shared<armem::server::ltm::persistence::RedundantPersistenceStrategy>();
50 for (
size_t i = 0; i < persistenceStrategies.size(); i++)
52 std::string
s = persistenceStrategies.at(i);
68 std::shared_ptr<armem::server::ltm::persistence::DiskPersistence> diskPersistence =
69 std::make_shared<armem::server::ltm::persistence::DiskPersistence>(
70 std::filesystem::path(exportPath));
71 diskPersistence->setIdentifier(identifier);
75 redundantPersistence->addStrategy(diskPersistence);
80 ARMARX_WARNING <<
"Persistence strategy=" <<
s <<
" currently deactivated";
101 else if (
s ==
"mongodb")
123 persistenceStrategy_(
std::
make_shared<persistence::RedundantPersistenceStrategy>())
128 const std::string& exportName,
130 const std::shared_ptr<persistence::RedundantPersistenceStrategy>& persistenceStrategy) :
134 persistenceStrategy_(persistenceStrategy)
143 if (persistenceStrategy_)
145 persistenceStrategy_->setExportName(
memoryName);
163 ARMARX_IMPORTANT <<
"Storing of data finished, starting to generate and save statistics...";
191 for (
auto& core_segment : persistenceStrategy_->getContainerKeys(
id()))
195 std::shared_ptr<persistence::MemoryPersistenceStrategy> coreSegmentPersistenceStrategy(
196 persistenceStrategy_);
199 id().withCoreSegmentName(core_segment),
201 coreSegmentPersistenceStrategy);
217 persistenceStrategy_->containsContainer(
id(), coreSegmentName);
219 return foundCoreSegment;
222 std::shared_ptr<CoreSegment>
234 std::shared_ptr<persistence::MemoryPersistenceStrategy> coreSegmentPersistenceStrategy(
235 persistenceStrategy_);
238 id().withCoreSegmentName(coreSegmentName),
240 coreSegmentPersistenceStrategy);
263 [&wmMemory](
auto& ltmCoreSegment)
266 ltmCoreSegment.loadAllReferences(wmCoreSegment);
271 armem::wm::CoreSegment existingWmCoreSegment =
272 wmMemory.getCoreSegment(wmCoreSegment.name());
273 existingWmCoreSegment.append(wmCoreSegment);
277 wmMemory.addCoreSegment(wmCoreSegment);
289 ARMARX_DEBUG <<
"Memory: Load latest N references for all core segments (id="
293 [&wmMemory, &
n](
auto& ltmCoreSegment)
296 ltmCoreSegment.loadLatestNReferences(
n, wmCoreSegment);
301 armem::wm::CoreSegment existingWmCoreSegment =
302 wmMemory.getCoreSegment(wmCoreSegment.name());
303 existingWmCoreSegment.append(wmCoreSegment);
307 wmMemory.addCoreSegment(wmCoreSegment);
315 std::list<std::string> coreSegNames)
321 ARMARX_DEBUG <<
"Memory: Load latest references for set of core segments (id="
325 [&wmMemory, &
n, &coreSegNames](
auto& ltmCoreSegment)
330 ltmCoreSegment.id().coreSegmentName) != coreSegNames.end());
333 ARMARX_DEBUG <<
"Load core segment=" << ltmCoreSegment.id().coreSegmentName;
335 ltmCoreSegment.loadLatestNReferences(
n, wmCoreSegment);
342 existingWmCoreSegment.
append(wmCoreSegment);
351 ARMARX_DEBUG <<
"Skipping loading CoreSegment with name "
353 <<
" from LTM into WM as it is not in the defined list";
367 [&](
auto& wmCoreSegment)
369 std::shared_ptr<persistence::MemoryPersistenceStrategy>
370 coreSegmentPersistenceStrategy(persistenceStrategy_);
374 id().withCoreSegmentName(wmCoreSegment.id().coreSegmentName),
376 coreSegmentPersistenceStrategy);
378 ltmCoreSegment.
resolve(wmCoreSegment);
398 <<
"During storage of memory '" << wmMemory.
id().
str()
399 <<
"' I noticed that the corresponding LTM has no id set. "
400 <<
"I set the id of the LTM to the same name, however this should not happen!";
408 [&](
const auto& wmCoreSegment)
410 std::shared_ptr<persistence::MemoryPersistenceStrategy>
411 coreSegmentPersistenceStrategy(persistenceStrategy_);
415 id().withCoreSegmentName(wmCoreSegment.id().coreSegmentName),
417 coreSegmentPersistenceStrategy);
420 ltmCoreSegment.
store(wmCoreSegment, simulatedVersion);
441 auto firstTimeStarted = this->
statistics.firstStarted;
442 if (!firstTimeStarted.isValid())
445 ARMARX_DEBUG <<
"No Statistics will be saved because firstStarted is invalid: "
454 if (first_stats.empty())
457 ARMARX_DEBUG <<
"No Statistics will be saved because no actual data was recorded.";
460 std::map<std::string,
461 std::map<std::string, ltm::processor::SnapshotFilter::FilterStatistics>>
463 std::map<std::string, armarx::core::time::DateTime> times;
469 information[
"LTM"] = first_stats;
473 ARMARX_DEBUG <<
"Something went wrong after getting the statistics";
489 ARMARX_DEBUG <<
"Something went wrong with the statistics saving process";
493 std::vector<std::string>
494 Memory::split(std::string
str,
char delimiter)
498 std::stringstream ss(
str);
499 std::vector<std::string> res;
501 while (std::getline(ss, token, delimiter))
503 res.push_back(token);