4 // Paxos must maintain some durable state (i.e., that survives power
5 // failures) to run Paxos correct. This module implements a log with
6 // all durable state to run Paxos. Since the values chosen correspond
7 // to views, the log contains all views since the beginning of time.
9 log::log(proposer_acceptor *_acc, string _me) : pxs (_acc) {
10 name = "paxos-" + _me + ".log";
14 void log::logread(void) {
20 while (from >> type) {
26 pxs->values[instance] = v;
27 pxs->instance_h = instance;
28 LOG("logread: instance: " << instance << " w. v = " <<
29 pxs->values[instance]);
33 } else if (type == "propseen") {
34 from >> pxs->n_h.n >> pxs->n_h.m;
35 LOG("logread: high update: " << pxs->n_h.n << "(" << pxs->n_h.m << ")");
36 } else if (type == "accepted") {
38 from >> pxs->n_a.n >> pxs->n_a.m;
42 LOG("logread: prop update " << pxs->n_a.n << "(" << pxs->n_a.m << ") with v = " << pxs->v_a);
44 LOG("logread: unknown log record");
55 while (getline(from, v))
61 void log::restore(string s) {
62 LOG("restore: " << s);
63 ofstream f(name, std::ios::trunc);
68 // XXX should be an atomic operation
69 void log::loginstance(unsigned instance, string v) {
70 ofstream f(name, std::ios::app);
71 f << "done " << instance << " " << v << "\n";
75 // an acceptor should call logprop(n_h) when it
76 // receives a prepare to which it responds prepare_ok().
77 void log::logprop(prop_t n_h) {
78 ofstream f(name, std::ios::app);
79 f << "propseen " << n_h.n << " " << n_h.m << "\n";
83 // an acceptor should call logaccept(n_a, v_a) when it
84 // receives an accept RPC to which it replies accept_ok().
85 void log::logaccept(prop_t n, string v) {
86 ofstream f(name, std::ios::app);
87 f << "accepted " << n.n << " " << n.m << " " << v << "\n";