1#ifndef CAPIO_CL_MONITOR_H
2#define CAPIO_CL_MONITOR_H
11#include <unordered_map>
14#include "configuration.h"
26static const std::string NO_HOME_NODE =
"<NONE>";
32 std::string message{};
45 [[nodiscard]]
const char *
what() const noexcept
override {
return message.c_str(); }
81 mutable std::unordered_map<std::string, std::string>
_home_nodes;
100 virtual bool isCommitted(
const std::filesystem::path &path)
const;
113 virtual void setHomeNode(
const std::filesystem::path &path)
const;
120 virtual std::string
getHomeNode(
const std::filesystem::path &path)
const;
140 std::thread commit_thread, home_node_thread;
145 std::string MULTICAST_COMMIT_ADDR;
147 std::string MULTICAST_HOME_NODE_ADDR;
150 std::atomic<bool> terminate =
false;
153 static constexpr int MULTICAST_THREAD_POLL_INTERVAL = 250;
158 int MULTICAST_COMMIT_PORT{};
160 int MULTICAST_HOME_NODE_PORT{};
163 int MULTICAST_DELAY_MILLIS{};
168 typedef enum { SET =
'!', GET =
'?' } MESSAGE_COMMANDS;
178 static void _send_message(
const std::string &ip_addr,
int ip_port,
const std::string &path,
179 MESSAGE_COMMANDS action);
194 static void commit_listener(std::vector<std::string> &committed_files, std::mutex &lock,
195 const std::string &ip_addr,
int ip_port,
196 const std::atomic<bool> *terminate);
211 static void home_node_listener(std::unordered_map<std::string, std::string> &home_nodes,
212 std::mutex &lock,
const std::string &ip_addr,
int ip_port,
213 const std::atomic<bool> *terminate);
228 bool isCommitted(
const std::filesystem::path &path)
const override;
230 void setHomeNode(
const std::filesystem::path &path)
const override;
231 std::string
getHomeNode(
const std::filesystem::path &path)
const override;
243 typedef enum { COMMIT, HOME_NODE } CAPIO_CL_COMMIT_TOKEN_TYPES;
252 static std::filesystem::path
253 compute_capiocl_token_name(
const std::filesystem::path &path,
254 CAPIO_CL_COMMIT_TOKEN_TYPES type = COMMIT);
263 static void generate_commit_token(
const std::filesystem::path &path);
273 static void generate_home_node_token(
const std::filesystem::path &path,
274 const std::string &home_node);
287 bool isCommitted(
const std::filesystem::path &path)
const override;
289 void setHomeNode(
const std::filesystem::path &path)
const override;
290 std::string
getHomeNode(
const std::filesystem::path &path)
const override;
299 friend class MonitorInterface;
301 std::vector<const MonitorInterface *> interfaces;
312 [[nodiscard]]
bool isCommitted(
const std::filesystem::path &path)
const;
333 void setHomeNode(
const std::filesystem::path &path)
const;
340 [[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.
std::string getHomeNode(const std::filesystem::path &path) const override
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.
MonitorException(const std::string &msg)
Construct a new CAPIO-CL Exception.
Definition Monitor.cpp:5
const char * what() const noexcept override
Definition monitor.h:45
Abstract interface for monitoring the commit state of files in CAPIO-CL.
Definition monitor.h:59
virtual bool isCommitted(const std::filesystem::path &path) const
Check whether the given file has been committed.
char _hostname[HOSTNAME_BUFFER_SIZE]
hostname of the current instance
Definition monitor.h:86
std::vector< std::string > _committed_files
List of committed file paths stored as strings.
Definition monitor.h:74
virtual void setCommitted(const std::filesystem::path &path) const
Mark the given file as committed.
virtual void setHomeNode(const std::filesystem::path &path) const
virtual std::string getHomeNode(const std::filesystem::path &path) const
std::mutex committed_lock
Mutex protecting access to the committed file list.
Definition monitor.h:64
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:81
std::mutex home_node_lock
Mutex protecting access to the home nodes list.
Definition monitor.h:69
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:297
void setHomeNode(const std::filesystem::path &path) const
Definition Monitor.cpp:30
bool isCommitted(const std::filesystem::path &path) const
Definition Monitor.cpp:11
std::set< std::string > getHomeNode(const std::filesystem::path &path) const
Definition Monitor.cpp:38
void setCommitted(std::filesystem::path path) const
Definition Monitor.cpp:17
void registerMonitorBackend(const MonitorInterface *interface)
Definition Monitor.cpp:24
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.
std::string getHomeNode(const std::filesystem::path &path) const override
Namespace containing the CAPIO-CL Monitor components.
Definition monitor.h:17
constexpr std::size_t PATH_BUFFER_SIZE
Maximum path storage used in multicast monitor messages.
Definition monitor.h:23
constexpr std::size_t HOSTNAME_BUFFER_SIZE
Buffer size used to store a null-terminated host name.
Definition monitor.h:20