Ordered dumps #706
@ -40,7 +40,6 @@ ReturnValue_t PersistentTmStore::buildDumpSet(uint32_t fromUnixSeconds, uint32_t
|
|||||||
if (not fileOrDir.is_regular_file(e)) {
|
if (not fileOrDir.is_regular_file(e)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
sif::debug << "Path: " << fileOrDir.path() << std::endl;
|
|
||||||
dumpParams.fileSize = std::filesystem::file_size(fileOrDir.path(), e);
|
dumpParams.fileSize = std::filesystem::file_size(fileOrDir.path(), e);
|
||||||
if (e) {
|
if (e) {
|
||||||
sif::error << "PersistentTmStore: Could not retrieve file size: " << e.message() << std::endl;
|
sif::error << "PersistentTmStore: Could not retrieve file size: " << e.message() << std::endl;
|
||||||
@ -76,8 +75,8 @@ ReturnValue_t PersistentTmStore::buildDumpSet(uint32_t fromUnixSeconds, uint32_t
|
|||||||
DumpIndex dumpIndex;
|
DumpIndex dumpIndex;
|
||||||
dumpIndex.epoch = fileEpoch;
|
dumpIndex.epoch = fileEpoch;
|
||||||
dumpIndex.suffixIdx = extractSuffix(file.string());
|
dumpIndex.suffixIdx = extractSuffix(file.string());
|
||||||
|
// sif::debug << "Inserting file " << fileOrDir.path() << std::endl;
|
||||||
dumpParams.orderedDumpFilestamps.emplace(dumpIndex);
|
dumpParams.orderedDumpFilestamps.emplace(dumpIndex);
|
||||||
return returnvalue::OK;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
@ -87,10 +86,11 @@ std::optional<uint8_t> PersistentTmStore::extractSuffix(const std::string& pathS
|
|||||||
std::string numberStr;
|
std::string numberStr;
|
||||||
// Find the position of the dot at the end of the file path
|
// Find the position of the dot at the end of the file path
|
||||||
size_t dotPos = pathStr.find_last_of('.');
|
size_t dotPos = pathStr.find_last_of('.');
|
||||||
if (dotPos != std::string::npos && dotPos < pathStr.length() - 1) {
|
if ((dotPos < pathStr.length()) and not std::isdigit(pathStr[dotPos + 1])) {
|
||||||
// Extract the substring after the dot
|
return std::nullopt;
|
||||||
numberStr = pathStr.substr(dotPos + 1);
|
|
||||||
}
|
}
|
||||||
|
// Extract the substring after the dot
|
||||||
|
numberStr = pathStr.substr(dotPos + 1);
|
||||||
std::optional<uint8_t> number;
|
std::optional<uint8_t> number;
|
||||||
try {
|
try {
|
||||||
number = std::stoi(numberStr);
|
number = std::stoi(numberStr);
|
||||||
@ -202,7 +202,6 @@ ReturnValue_t PersistentTmStore::storePacket(PusTmReader& reader) {
|
|||||||
createMostRecentFile(suffix);
|
createMostRecentFile(suffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
sif::debug << "active file " << activeFile.value() << std::endl;
|
|
||||||
// Rollover conditions were handled, write to file now
|
// Rollover conditions were handled, write to file now
|
||||||
std::ofstream of(activeFile.value(), std::ios::app | std::ios::binary);
|
std::ofstream of(activeFile.value(), std::ios::app | std::ios::binary);
|
||||||
of.write(reinterpret_cast<const char*>(reader.getFullData()),
|
of.write(reinterpret_cast<const char*>(reader.getFullData()),
|
||||||
@ -298,12 +297,19 @@ ReturnValue_t PersistentTmStore::loadNextDumpFile() {
|
|||||||
createFileName(tv, dumpIndex.suffixIdx, fullPathLength);
|
createFileName(tv, dumpIndex.suffixIdx, 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));
|
||||||
std::ifstream ifile(dumpParams.currentFile, std::ios::binary);
|
dumpParams.fileSize = std::filesystem::file_size(dumpParams.currentFile, e);
|
||||||
if (ifile.bad()) {
|
if (e) {
|
||||||
sif::error << "PersistentTmStore: File is bad" << std::endl;
|
// TODO: Event?
|
||||||
|
sif::error << "PersistentTmStore: Could not load next dump file: " << e.message()
|
||||||
|
<< std::endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
sif::debug << baseName << " dump: Loading " << dumpParams.currentFile << std::endl;
|
std::ifstream ifile(dumpParams.currentFile, std::ios::binary);
|
||||||
|
if (ifile.bad()) {
|
||||||
|
sif::error << "PersistentTmStore: File is bad. Loading next file" << std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// sif::debug << baseName << " dump: Loading " << dumpParams.currentFile << std::endl;
|
||||||
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));
|
||||||
// Increment iterator for next cycle.
|
// Increment iterator for next cycle.
|
||||||
@ -368,7 +374,6 @@ ReturnValue_t PersistentTmStore::createMostRecentFile(std::optional<uint8_t> suf
|
|||||||
size_t currentIdx;
|
size_t currentIdx;
|
||||||
createFileName(currentTv, suffix, currentIdx);
|
createFileName(currentTv, suffix, currentIdx);
|
||||||
path newPath(std::string(reinterpret_cast<const char*>(filePathBuf.data()), currentIdx));
|
path newPath(std::string(reinterpret_cast<const char*>(filePathBuf.data()), currentIdx));
|
||||||
sif::debug << "creating new file: " << newPath << std::endl;
|
|
||||||
std::ofstream of(newPath, std::ios::binary);
|
std::ofstream of(newPath, std::ios::binary);
|
||||||
activeFile = newPath;
|
activeFile = newPath;
|
||||||
activeFileTv = currentTv;
|
activeFileTv = currentTv;
|
||||||
|
Loading…
Reference in New Issue
Block a user