Apache Mesos
storage.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_STORAGE_HPP__
18 #define __LOG_STORAGE_HPP__
19 
20 #include <stdint.h>
21 
22 #include <string>
23 
24 #include <stout/interval.hpp>
25 #include <stout/nothing.hpp>
26 #include <stout/try.hpp>
27 
28 #include "messages/log.hpp"
29 
30 namespace mesos {
31 namespace internal {
32 namespace log {
33 
34 // Abstract interface for reading and writing records.
35 class Storage
36 {
37 public:
38  struct State
39  {
40  Metadata metadata; // The metadata for the replica.
41  uint64_t begin; // Beginning position of the log.
42  uint64_t end; // Ending position of the log.
43 
44  // Note that we use interval set here to store learned/unlearned
45  // positions in a more compact way. Adjacent positions will be
46  // merged and represented using an interval.
49  };
50 
51  virtual ~Storage() {}
52 
53  virtual Try<State> restore(const std::string& path) = 0;
54  virtual Try<Nothing> persist(const Metadata& metadata) = 0;
55  virtual Try<Nothing> persist(const Action& action) = 0;
56  virtual Try<Action> read(uint64_t position) = 0;
57 };
58 
59 } // namespace log {
60 } // namespace internal {
61 } // namespace mesos {
62 
63 #endif // __LOG_STORAGE_HPP__
Definition: path.hpp:29
virtual ~Storage()
Definition: storage.hpp:51
Definition: check.hpp:33
IntervalSet< uint64_t > learned
Definition: storage.hpp:47
virtual Try< Nothing > persist(const Metadata &metadata)=0
virtual Try< Action > read(uint64_t position)=0
Definition: storage.hpp:38
uint64_t end
Definition: storage.hpp:42
uint64_t begin
Definition: storage.hpp:41
virtual Try< State > restore(const std::string &path)=0
Definition: agent.hpp:25
Definition: storage.hpp:35
Definition: attributes.hpp:24
Metadata metadata
Definition: storage.hpp:40
IntervalSet< uint64_t > unlearned
Definition: storage.hpp:48