Apache Mesos
coordinator.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __LOG_COORDINATOR_HPP__
18 #define __LOG_COORDINATOR_HPP__
19 
20 #include <stdint.h>
21 
22 #include <string>
23 
24 #include <process/future.hpp>
25 #include <process/shared.hpp>
26 
27 #include <stout/option.hpp>
28 
29 #include "log/network.hpp"
30 #include "log/replica.hpp"
31 
32 namespace mesos {
33 namespace internal {
34 namespace log {
35 
36 // Forward declaration.
37 class CoordinatorProcess;
38 
39 
41 {
42 public:
44  size_t quorum,
45  const process::Shared<Replica>& replica,
46  const process::Shared<Network>& network);
47 
48  ~Coordinator();
49 
50  // Handles coordinator election. Returns the last committed (a.k.a.,
51  // learned) log position if the operation succeeds. Returns none if
52  // the election is not successful, but can be retried.
54 
55  // Handles coordinator demotion. Returns the last committed (a.k.a.,
56  // learned) log position if the operation succeeds. One should only
57  // call this function if the coordinator has been elected, and no
58  // write (append or truncate) is in progress.
60 
61  // Appends the specified bytes to the end of the log. Returns the
62  // position of the appended entry if the operation succeeds or none
63  // if the coordinator was demoted.
64  process::Future<Option<uint64_t>> append(const std::string& bytes);
65 
66  // Removes all log entries preceding the log entry at the given
67  // position (to). Returns the position at which the truncate
68  // operation is written if the operation succeeds or none if the
69  // coordinator was demoted.
71 
72 private:
73  CoordinatorProcess* process;
74 };
75 
76 } // namespace log {
77 } // namespace internal {
78 } // namespace mesos {
79 
80 #endif // __LOG_COORDINATOR_HPP__
process::Future< Option< uint64_t > > append(const std::string &bytes)
process::Future< Option< uint64_t > > elect()
Definition: owned.hpp:26
Definition: agent.hpp:25
process::Future< uint64_t > demote()
Coordinator(size_t quorum, const process::Shared< Replica > &replica, const process::Shared< Network > &network)
Definition: coordinator.hpp:40
Definition: attributes.hpp:24
Definition: executor.hpp:48
process::Future< Option< uint64_t > > truncate(uint64_t to)
Definition: future.hpp:58