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];
30 pxs->accepted_value.clear();
33 } else if (type == "propseen") {
34 from >> pxs->promise.n >> pxs->promise.m;
35 LOG << "logread: high update: " << pxs->promise.n << "(" << pxs->promise.m << ")";
36 } else if (type == "accepted") {
38 from >> pxs->accepted.n >> pxs->accepted.m;
41 pxs->accepted_value = v;
42 LOG << "logread: prop update " << pxs->accepted.n << "(" << pxs->accepted.m << ") with v = " << pxs->accepted_value;
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, ios::trunc);
68 // XXX should be an atomic operation
69 void log::loginstance(unsigned instance, string v) {
70 ofstream f(name, ios::app);
71 f << "done " << instance << " " << v << "\n";
75 // an acceptor should call logprop(promise) when it
76 // receives a prepare to which it responds prepare_ok().
77 void log::logprop(prop_t promise) {
78 ofstream f(name, ios::app);
79 f << "propseen " << promise.n << " " << promise.m << "\n";
83 // an acceptor should call logaccept(accepted, accepted_value) 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, ios::app);
87 f << "accepted " << n.n << " " << n.m << " " << v << "\n";