So many changes. Broken.
[invirt/third/libt4.git] / log.cc
1 #include "include/log.h"
2 #include "include/paxos.h"
3
4 // Maintains durable state (i.e. surviving power failures) needed for correct
5 // operation of Paxos as a log.
6
7 log::log(string _me) : name("paxos-" + _me + ".log") {}
8
9 void log::replay() {
10     auto from = unmarshall(read());
11     string type;
12
13     DEBUG_LOG << "Replaying paxos log from disk";
14     while (from >> type) {
15         if (handlers.count(type)) {
16             handlers[type](from);
17         } else {
18             DEBUG_LOG << "unknown log record";
19             VERIFY(0);
20         }
21     }
22 }
23
24 string log::read() {
25     return (std::stringstream() << std::ifstream(name).rdbuf()).str();
26 }
27
28 void log::write(string s) {
29     DEBUG_LOG << s;
30     std::ofstream(name, std::ios::trunc) << s;
31 }