this is tricky
Some checks failed
EIVE/eive-obsw/pipeline/pr-main There was a failure building this commit

This commit is contained in:
Robin Müller 2023-06-24 11:46:56 +02:00
parent a8ab40674f
commit 53b48ad99b
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
2 changed files with 33 additions and 10 deletions

View File

@ -17,7 +17,7 @@
using namespace returnvalue; using namespace returnvalue;
static constexpr bool DEBUG_DUMPS = false; static constexpr bool DEBUG_DUMPS = true;
PersistentTmStore::PersistentTmStore(PersistentTmStoreArgs args) PersistentTmStore::PersistentTmStore(PersistentTmStoreArgs args)
: SystemObject(args.objectId), : SystemObject(args.objectId),
@ -74,16 +74,21 @@ ReturnValue_t PersistentTmStore::buildDumpSet(uint32_t fromUnixSeconds, uint32_t
continue; continue;
} }
DumpIndex dumpIndex;
dumpIndex.epoch = fileEpoch;
dumpIndex.suffixIdx = extractSuffix(file.string());
if (DEBUG_DUMPS) { if (DEBUG_DUMPS) {
sif::debug << "Inserting file " << fileOrDir.path() << std::endl; sif::debug << "Inserting file " << fileOrDir.path() << std::endl;
if (dumpIndex.suffixIdx.has_value()) {
sif::debug << "Suffix: " << static_cast<int>(dumpIndex.suffixIdx.value()) << std::endl;
}
} }
dumpParams.orderedDumpFilestamps.emplace(dumpIndex); DumpIndex dumpIndex;
dumpIndex.epoch = fileEpoch;
// Multiple files for the same time are supported via a special suffix. We smply count the
// number of copies and later try to dump the same number of files with the additonal
// suffixes
auto& iter = dumpParams.orderedDumpFilestamps.find(dumpIndex);
if (iter != dumpParams.orderedDumpFilestamps.end()) {
iter->additionalFiles++;
} else {
dumpIndex.additionalFiles = 0;
dumpParams.orderedDumpFilestamps.emplace(dumpIndex);
}
} }
} }
return returnvalue::OK; return returnvalue::OK;
@ -301,7 +306,7 @@ ReturnValue_t PersistentTmStore::loadNextDumpFile() {
timeval tv{}; timeval tv{};
tv.tv_sec = dumpIndex.epoch; tv.tv_sec = dumpIndex.epoch;
size_t fullPathLength = 0; size_t fullPathLength = 0;
createFileName(tv, dumpIndex.suffixIdx, fullPathLength); createFileName(tv, dumpParams.currentSameFileIdx, fullPathLength);
dumpParams.currentFile = dumpParams.currentFile =
path(std::string(reinterpret_cast<const char*>(filePathBuf.data()), fullPathLength)); path(std::string(reinterpret_cast<const char*>(filePathBuf.data()), fullPathLength));
dumpParams.fileSize = std::filesystem::file_size(dumpParams.currentFile, e); dumpParams.fileSize = std::filesystem::file_size(dumpParams.currentFile, e);
@ -321,6 +326,22 @@ ReturnValue_t PersistentTmStore::loadNextDumpFile() {
} }
ifile.read(reinterpret_cast<char*>(fileBuf.data()), ifile.read(reinterpret_cast<char*>(fileBuf.data()),
static_cast<std::streamsize>(dumpParams.fileSize)); static_cast<std::streamsize>(dumpParams.fileSize));
if (dumpIndex.additionalFiles > 0) {
dumpParams.currentSameFileIdx++;
}
if (dumpIndex.additionalFiles > 0 and not dumpParams.currentSameFileIdx.has_value()) {
if (not dumpParams.currentSameFileIdx.has_value()) {
// Initialze the file index and stay on same file
dumpParams.currentSameFileIdx = 0;
continue;
} else if (dumpParams.currentSameFileIdx.value() < dumpIndex.additionalFiles) {
dumpParams.currentSameFileIdx += 1;
continue;
}
}
// File will change, reset this field for correct state-keeping.
dumpParams.currentSameFileIdx = std::nullopt;
// Increment iterator for next cycle. // Increment iterator for next cycle.
dumpParams.dumpIter++; dumpParams.dumpIter++;
return returnvalue::OK; return returnvalue::OK;

View File

@ -40,7 +40,8 @@ struct PersistentTmStoreArgs {
struct DumpIndex { struct DumpIndex {
uint32_t epoch; uint32_t epoch;
std::optional<uint8_t> suffixIdx; // Number of additional files with a suffix like .0, .1 etc.
uint8_t additionalFiles;
// Define a custom comparison function based on the epoch variable // Define a custom comparison function based on the epoch variable
bool operator<(const DumpIndex& other) const { return epoch < other.epoch; } bool operator<(const DumpIndex& other) const { return epoch < other.epoch; }
}; };
@ -120,6 +121,7 @@ class PersistentTmStore : public TmStoreFrontendSimpleIF, public SystemObject {
std::filesystem::path currentFile; std::filesystem::path currentFile;
std::set<DumpIndex> orderedDumpFilestamps{}; std::set<DumpIndex> orderedDumpFilestamps{};
std::set<DumpIndex>::iterator dumpIter; std::set<DumpIndex>::iterator dumpIter;
std::optional<uint8_t> currentSameFileIdx = 0;
size_t fileSize = 0; size_t fileSize = 0;
size_t currentSize = 0; size_t currentSize = 0;
}; };