| 141 | |
| 142 | |
| 143 | Future<Option<uint64_t>> CoordinatorProcess::elect() |
| 144 | { |
| 145 | if (state == ELECTING) { |
| 146 | return electing; |
| 147 | } else if (state == ELECTED) { |
| 148 | return index - 1; // The last learned position! |
| 149 | } else if (state == WRITING) { |
| 150 | return Failure("Coordinator already elected, and is currently writing"); |
| 151 | } |
| 152 | |
| 153 | CHECK_EQ(state, INITIAL); |
| 154 | |
| 155 | state = ELECTING; |
| 156 | |
| 157 | electing = getLastProposal() |
| 158 | .then(defer(self(), &Self::updateProposal, lambda::_1)) |
| 159 | .then(defer(self(), &Self::runPromisePhase)) |
| 160 | .then(defer(self(), &Self::checkPromisePhase, lambda::_1)) |
| 161 | .onReady(defer(self(), &Self::electingFinished, lambda::_1)) |
| 162 | .onFailed(defer(self(), &Self::electingFailed)) |
| 163 | .onDiscarded(defer(self(), &Self::electingAborted)); |
| 164 | |
| 165 | return electing; |
| 166 | } |
| 167 | |
| 168 | |
| 169 | Future<uint64_t> CoordinatorProcess::getLastProposal() |