libfoedus-core
FOEDUS Core Library
meta_logger_impl.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
18 #ifndef FOEDUS_LOG_META_LOGGER_IMPL_HPP_
19 #define FOEDUS_LOG_META_LOGGER_IMPL_HPP_
20 #include <stdint.h>
21 
22 #include <atomic>
23 #include <iosfwd>
24 #include <thread>
25 
26 #include "foedus/epoch.hpp"
27 #include "foedus/fwd.hpp"
28 #include "foedus/initializable.hpp"
29 #include "foedus/fs/fwd.hpp"
30 #include "foedus/log/fwd.hpp"
31 #include "foedus/log/log_id.hpp"
35 
36 namespace foedus {
37 namespace log {
38 
45 class MetaLogger final : public DefaultInitializable {
46  public:
47  explicit MetaLogger(Engine* engine) : engine_(engine), control_block_(nullptr) {}
48  ErrorStack initialize_once() override;
49  ErrorStack uninitialize_once() override;
50 
51  MetaLogger() = delete;
52  MetaLogger(const MetaLogger &other) = delete;
53  MetaLogger& operator=(const MetaLogger &other) = delete;
54 
55  friend std::ostream& operator<<(std::ostream& o, const MetaLogger& v);
56 
57  private:
64  void meta_logger_main();
65 
69  ErrorStack switch_file_if_required();
70 
75  ErrorStack log_epoch_switch(Epoch new_epoch);
76 
84  ErrorStack truncate_non_durable(Epoch saved_durable_epoch);
85 
86  Engine* const engine_;
87  MetaLogControlBlock* control_block_;
88  std::thread logger_thread_;
89  std::atomic<bool> stop_requested_;
93  fs::DirectIoFile* current_file_;
94 };
95 static_assert(
96  sizeof(MetaLogControlBlock) <= soc::GlobalMemoryAnchors::kMetaLoggerSize,
97  "MetaLogControlBlock is too large.");
98 } // namespace log
99 } // namespace foedus
100 #endif // FOEDUS_LOG_META_LOGGER_IMPL_HPP_
Forward declarations of classes in filesystem package.
Forward declarations of classes in log manager package.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
Forward declarations of classes in root package.
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
Represents a time epoch.
Definition: epoch.hpp:61
MetaLogger & operator=(const MetaLogger &other)=delete
Typical implementation of Initializable as a skeleton base class.
Typedefs of ID types used in log package.
A log writer for metadata operation.
Database engine object that holds all resources and provides APIs.
Definition: engine.hpp:109
Represents an I/O stream on one file without filesystem caching.
ErrorStack initialize_once() override
friend std::ostream & operator<<(std::ostream &o, const MetaLogger &v)
ErrorStack uninitialize_once() override
Control block for MetaLogBuffer and MetaLogger.