#include #include #include "../FieldLists.h" #include "HistoryFileWriter.h" /* This program creates history/Index.xml. This is what gets loaded by * ServerList so we know which instances of the server are responsible for * which data files. * * Currently this is very simple and it helps me set up my test environment. * Ideally this will evolve into the final version which automatically updates * whenever we get a new data file or a server goes out of commission. */ static int64_t getIndex(bool first, HistoryFileReader &reader) { int64_t position; if (first) position = reader.findFirst(0); else position = reader.findLast(0x7fffffffffffffff); if (position == HistoryFileReader::INVALID) return 0; Record::Ref record; reader.readForward(position, record); if (!record) return 0; bool success; int64_t id; record->lookUpValue(MainFields::id).getInt(success, id); if (success) return id; else return 0; } struct ServerInfo { std::string hostName; std::string port; }; static ServerInfo getNextServer() { return { "joey-mousepad", "7797" }; } static std::string removeDir(std::string const &path) { return *explode("/", path).rbegin(); } XmlNode makeIndex(std::string const &filePattern) { XmlNode result; result.name = "INDEX"; XmlNode &serverList = result["CURRENT"]; serverList.properties["version_number"] = ntoa(time(NULL)); std::vector< std::string > fileList; glob_t results; int error = glob(filePattern.c_str(), GLOB_NOSORT | GLOB_TILDE | GLOB_NOMAGIC, NULL, &results); if (!error) for (char **current = results.gl_pathv; *current; current++) fileList.push_back(*current); globfree(&results); for (std::string const &fileName : fileList) { HistoryFileReader reader(fileName); if (!reader.isGood()) { std::cerr<<"Warning: "< * * Here are the corresponding outputs found in the log file when I ran * ./history_server -f ../../../live_server/config_common.txt * {Wed Jan 30 14:23:49 2019} 0 HistoryDirectory.C 108 HistoryDirectory {loading history file} fileId 1525762307537872549 fileName history/1548416647.history xml {{end 22743602605} {file_name 1548416647.history} {host_name joey-mousepad} {port 7797} {start 22735630088}} * {Wed Jan 30 14:23:49 2019} 0 HistoryDirectory.C 108 HistoryDirectory {loading history file} fileId 1526297334097225287 fileName history/1548675842.history xml {{end 22751837172} {file_name 1548675842.history} {host_name joey-mousepad} {port 7797} {start 22743602605}} * {Wed Jan 30 14:23:49 2019} 0 HistoryDirectory.C 108 HistoryDirectory {loading history file} fileId 1526849946534038603 fileName history/1548762242.history xml {{end 22759983167} {file_name 1548762242.history} {host_name joey-mousepad} {port 7797} {start 22751837172}} */