1#ifndef CAPIO_CL_MONITOR_H
2#define CAPIO_CL_MONITOR_H
10#include <unordered_map>
13#include "configuration.h"
20#define HOST_NAME_MAX 1024
27static const std::string NO_HOME_NODE =
"<NONE>";
33 std::string message{};
46 [[nodiscard]]
const char *
what() const noexcept
override {
return message.c_str(); }
82 mutable std::unordered_map<std::string, std::string>
_home_nodes;
101 virtual bool isCommitted(
const std::filesystem::path &path)
const;
114 virtual void setHomeNode(
const std::filesystem::path &path)
const;
121 virtual const std::string &
getHomeNode(
const std::filesystem::path &path)
const;
136 static constexpr int MESSAGE_SIZE = (2 + PATH_MAX + PATH_MAX);
141 std::thread commit_thread, home_node_thread;
146 std::string MULTICAST_COMMIT_ADDR;
148 std::string MULTICAST_HOME_NODE_ADDR;
151 std::atomic<bool> terminate =
false;
154 static constexpr int MULTICAST_THREAD_POLL_INTERVAL = 250;
159 int MULTICAST_COMMIT_PORT{};
161 int MULTICAST_HOME_NODE_PORT{};
164 int MULTICAST_DELAY_MILLIS{};
169 typedef enum { SET =
'!', GET =
'?' } MESSAGE_COMMANDS;
179 static void _send_message(
const std::string &ip_addr,
int ip_port,
const std::string &path,
180 MESSAGE_COMMANDS action);
195 static void commit_listener(std::vector<std::string> &committed_files, std::mutex &lock,
196 const std::string &ip_addr,
int ip_port,
197 const std::atomic<bool> *terminate);
212 static void home_node_listener(std::unordered_map<std::string, std::string> &home_nodes,
213 std::mutex &lock,
const std::string &ip_addr,
int ip_port,
214 const std::atomic<bool> *terminate);
229 bool isCommitted(
const std::filesystem::path &path)
const override;
231 void setHomeNode(
const std::filesystem::path &path)
const override;
232 const std::string &
getHomeNode(
const std::filesystem::path &path)
const override;
244 typedef enum { COMMIT, HOME_NODE } CAPIO_CL_COMMIT_TOKEN_TYPES;
253 static std::filesystem::path
254 compute_capiocl_token_name(
const std::filesystem::path &path,
255 CAPIO_CL_COMMIT_TOKEN_TYPES type = COMMIT);
264 static void generate_commit_token(
const std::filesystem::path &path);
274 static void generate_home_node_token(
const std::filesystem::path &path,
275 const std::string &home_node);
288 bool isCommitted(
const std::filesystem::path &path)
const override;
290 void setHomeNode(
const std::filesystem::path &path)
const override;
291 const std::string &
getHomeNode(
const std::filesystem::path &path)
const override;
300 friend class MonitorInterface;
302 std::vector<const MonitorInterface *> interfaces;
313 [[nodiscard]]
bool isCommitted(
const std::filesystem::path &path)
const;
334 void setHomeNode(
const std::filesystem::path &path)
const;
341 [[nodiscard]] std::set<std::string>
getHomeNode(
const std::filesystem::path &path)
const;
Load configuration and store it from a CAPIO-CL TOML configuration file.
Definition configuration.h:39
bool isCommitted(const std::filesystem::path &path) const override
Check whether the given file has been committed.
FileSystemMonitor()
Construct a filesystem-based commit monitor.
~FileSystemMonitor() override=default
Destructor for FileSystemMonitor.
void setHomeNode(const std::filesystem::path &path) const override
void setCommitted(const std::filesystem::path &path) const override
Mark the given file as committed.
const std::string & getHomeNode(const std::filesystem::path &path) const override
MonitorException(const std::string &msg)
Construct a new CAPIO-CL Exception.
Definition Monitor.cpp:5
const char * what() const noexcept override
Definition monitor.h:46
Abstract interface for monitoring the commit state of files in CAPIO-CL.
Definition monitor.h:60
virtual bool isCommitted(const std::filesystem::path &path) const
Check whether the given file has been committed.
std::vector< std::string > _committed_files
List of committed file paths stored as strings.
Definition monitor.h:75
virtual void setCommitted(const std::filesystem::path &path) const
Mark the given file as committed.
virtual void setHomeNode(const std::filesystem::path &path) const
std::mutex committed_lock
Mutex protecting access to the committed file list.
Definition monitor.h:65
std::unordered_map< std::string, std::string > _home_nodes
Lookup table to get home node staring from path. Key = file path; Value = hostname of home node.
Definition monitor.h:82
virtual const std::string & getHomeNode(const std::filesystem::path &path) const
std::mutex home_node_lock
Mutex protecting access to the home nodes list.
Definition monitor.h:70
char _hostname[HOST_NAME_MAX]
hostname of the current instance
Definition monitor.h:87
virtual ~MonitorInterface()=default
Virtual destructor for safe polymorphic deletion.
Class to monitor runtime dependent information on CAPIO-CL related paths, such as commitment status a...
Definition monitor.h:298
void setHomeNode(const std::filesystem::path &path) const
Definition Monitor.cpp:22
bool isCommitted(const std::filesystem::path &path) const
Definition Monitor.cpp:9
std::set< std::string > getHomeNode(const std::filesystem::path &path) const
Definition Monitor.cpp:28
void setCommitted(std::filesystem::path path) const
Definition Monitor.cpp:14
void registerMonitorBackend(const MonitorInterface *interface)
Definition Monitor.cpp:19
const std::string & getHomeNode(const std::filesystem::path &path) const override
MulticastMonitor(const capiocl::configuration::CapioClConfiguration &config)
Construct a multicast-based monitor.
void setCommitted(const std::filesystem::path &path) const override
Mark the given file as committed.
void setHomeNode(const std::filesystem::path &path) const override
~MulticastMonitor() override
Destructor; stops listener thread and cleans resources.
bool isCommitted(const std::filesystem::path &path) const override
Check whether the given file has been committed.
Namespace containing the CAPIO-CL Monitor components.
Definition monitor.h:24