Apache Mesos
replica.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_REPLICA_HPP__
18 #define __LOG_REPLICA_HPP__
19 
20 #include <stdint.h>
21 
22 #include <list>
23 #include <string>
24 
25 #include <process/future.hpp>
26 #include <process/pid.hpp>
27 #include <process/protobuf.hpp>
28 
29 #include <stout/interval.hpp>
30 
31 #include "messages/log.hpp"
32 
33 namespace mesos {
34 namespace internal {
35 namespace log {
36 
37 namespace protocol {
38 
39 // Some replica protocol declarations.
43 
44 } // namespace protocol {
45 
46 
47 // Forward declaration.
48 class ReplicaProcess;
49 
50 
51 class Replica
52 {
53 public:
54  // Constructs a new replica process using specified path to a
55  // directory for storing the underlying log. If a replica starts
56  // with an empty log, it will not be allowed to vote (i.e., cannot
57  // reply to any request except the recover request). The recover
58  // process will later decide if this replica can be re-allowed to
59  // vote depending on the status of other replicas.
60  explicit Replica(const std::string& path);
61  virtual ~Replica();
62 
63  // Returns all the actions between the specified positions, unless
64  // those positions are invalid, in which case returns an error.
66  uint64_t from,
67  uint64_t to) const;
68 
69  // Returns true if the specified position is missing in the log
70  // (i.e., unlearned or holes).
71  process::Future<bool> missing(uint64_t position) const;
72 
73  // Returns missing positions in the log (i.e., unlearned or holes)
74  // within the specified range [from, to]. We use interval set, a
75  // more compact representation of set, to store missing positions.
77  uint64_t from,
78  uint64_t to) const;
79 
80  // Returns the beginning position of the log.
81  process::Future<uint64_t> beginning() const;
82 
83  // Returns the last written position in the log.
84  process::Future<uint64_t> ending() const;
85 
86  // Returns the current status of this replica.
88 
89  // Returns the highest implicit promise this replica has given.
90  process::Future<uint64_t> promised() const;
91 
92  // Updates the status of this replica. Returns true if status was
93  // updated successfully, false otherwise. Made "virtual" for
94  // mocking in tests.
95  virtual process::Future<bool> update(const Metadata::Status& status);
96 
97  // Returns the PID associated with this replica.
98  process::PID<ReplicaProcess> pid() const;
99 
100 private:
101  ReplicaProcess* process;
102 };
103 
104 } // namespace log {
105 } // namespace internal {
106 } // namespace mesos {
107 
108 #endif // __LOG_REPLICA_HPP__
Protocol< RecoverRequest, RecoverResponse > recover
Definition: path.hpp:29
Try< bool > update(const std::string &link, const Handle &parent, uint16_t protocol, const action::Mirror &mirror)
Definition: replica.hpp:51
Result< ProcessStatus > status(pid_t pid)
Definition: proc.hpp:166
Definition: agent.hpp:25
Protocol< PromiseRequest, PromiseResponse > promise
Definition: protobuf.hpp:459
Result< Process > process(pid_t pid)
Definition: freebsd.hpp:30
A "process identifier" used to uniquely identify a process when dispatching messages.
Definition: pid.hpp:289
Definition: attributes.hpp:24
Result< Credentials > read(const Path &path)
Definition: credentials.hpp:35
Protocol< WriteRequest, WriteResponse > write
Definition: future.hpp:58