libfoedus-core
FOEDUS Core Library
mapreduce_base_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_SNAPSHOT_MAPREDUCE_BASE_IMPL_HPP_
19 #define FOEDUS_SNAPSHOT_MAPREDUCE_BASE_IMPL_HPP_
20 #include <stdint.h>
21 
22 #include <atomic>
23 #include <iosfwd>
24 #include <string>
25 #include <thread>
26 
27 #include "foedus/fwd.hpp"
28 #include "foedus/initializable.hpp"
29 #include "foedus/log/fwd.hpp"
30 #include "foedus/log/log_id.hpp"
31 #include "foedus/snapshot/fwd.hpp"
34 #include "foedus/thread/fwd.hpp"
35 
36 namespace foedus {
37 namespace snapshot {
52  public:
53  MapReduceBase(Engine* engine, uint16_t id);
54 
55  MapReduceBase() = delete;
56  MapReduceBase(const MapReduceBase &other) = delete;
57  MapReduceBase& operator=(const MapReduceBase &other) = delete;
58 
60  uint16_t get_id() const { return id_; }
61  uint16_t get_numa_node() const { return numa_node_; }
62 
64  virtual std::string to_string() const = 0;
65 
67  void launch_thread();
68  void join_thread();
69 
70  protected:
71  Engine* const engine_;
74  const uint16_t id_;
75  const uint16_t numa_node_;
77  std::atomic<bool> running_;
78 
79  std::thread thread_;
80 
82  virtual ErrorStack handle_process() = 0;
83 
85  ErrorCode check_cancelled() const;
86 
87  private:
89  void handle();
90 };
91 } // namespace snapshot
92 } // namespace foedus
93 #endif // FOEDUS_SNAPSHOT_MAPREDUCE_BASE_IMPL_HPP_
MapReduceBase & operator=(const MapReduceBase &other)=delete
ErrorCode check_cancelled() const
Derived class's handle_process() should occasionally call this to exit if it's cancelled.
void launch_thread()
Start executing.
Forward declarations of classes in log manager package.
Typedefs of ID types used in snapshot 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
Forward declarations of classes in snapshot manager package.
Typical implementation of Initializable as a skeleton base class.
std::atomic< bool > running_
only for sanity check
Typedefs of ID types used in log package.
Database engine object that holds all resources and provides APIs.
Definition: engine.hpp:109
const uint16_t id_
Unique ID of this mapper or reducer.
A remote view of LogGleaner from all engines.
Base class for LogMapper and LogReducer to share common code.
virtual ErrorStack handle_process()=0
Implements the specific logics in derived class.
Forward declarations of classes in thread package.
ErrorCode
Enum of error codes defined in error_code.xmacro.
Definition: error_code.hpp:85
virtual std::string to_string() const =0
Expects "LogReducer-x", "LogMapper-y" etc.