this is tricky
Some checks failed
EIVE/eive-obsw/pipeline/pr-main There was a failure building this commit
Some checks failed
EIVE/eive-obsw/pipeline/pr-main There was a failure building this commit
This commit is contained in:
parent
a8ab40674f
commit
53b48ad99b
@ -17,7 +17,7 @@
|
||||
|
||||
using namespace returnvalue;
|
||||
|
||||
static constexpr bool DEBUG_DUMPS = false;
|
||||
static constexpr bool DEBUG_DUMPS = true;
|
||||
|
||||
PersistentTmStore::PersistentTmStore(PersistentTmStoreArgs args)
|
||||
: SystemObject(args.objectId),
|
||||
@ -74,18 +74,23 @@ ReturnValue_t PersistentTmStore::buildDumpSet(uint32_t fromUnixSeconds, uint32_t
|
||||
continue;
|
||||
}
|
||||
|
||||
DumpIndex dumpIndex;
|
||||
dumpIndex.epoch = fileEpoch;
|
||||
dumpIndex.suffixIdx = extractSuffix(file.string());
|
||||
if (DEBUG_DUMPS) {
|
||||
sif::debug << "Inserting file " << fileOrDir.path() << std::endl;
|
||||
if (dumpIndex.suffixIdx.has_value()) {
|
||||
sif::debug << "Suffix: " << static_cast<int>(dumpIndex.suffixIdx.value()) << std::endl;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@ -301,7 +306,7 @@ ReturnValue_t PersistentTmStore::loadNextDumpFile() {
|
||||
timeval tv{};
|
||||
tv.tv_sec = dumpIndex.epoch;
|
||||
size_t fullPathLength = 0;
|
||||
createFileName(tv, dumpIndex.suffixIdx, fullPathLength);
|
||||
createFileName(tv, dumpParams.currentSameFileIdx, fullPathLength);
|
||||
dumpParams.currentFile =
|
||||
path(std::string(reinterpret_cast<const char*>(filePathBuf.data()), fullPathLength));
|
||||
dumpParams.fileSize = std::filesystem::file_size(dumpParams.currentFile, e);
|
||||
@ -321,6 +326,22 @@ ReturnValue_t PersistentTmStore::loadNextDumpFile() {
|
||||
}
|
||||
ifile.read(reinterpret_cast<char*>(fileBuf.data()),
|
||||
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.
|
||||
dumpParams.dumpIter++;
|
||||
return returnvalue::OK;
|
||||
|
@ -40,7 +40,8 @@ struct PersistentTmStoreArgs {
|
||||
|
||||
struct DumpIndex {
|
||||
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
|
||||
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::set<DumpIndex> orderedDumpFilestamps{};
|
||||
std::set<DumpIndex>::iterator dumpIter;
|
||||
std::optional<uint8_t> currentSameFileIdx = 0;
|
||||
size_t fileSize = 0;
|
||||
size_t currentSize = 0;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user