Skip to content

Commit

Permalink
MGM: add possibility to run a script after the slave to master transi…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
gmgigi96 authored and Elvin Alin Sindrilaru committed Jan 30, 2025
1 parent 074b19e commit a50759c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 7 deletions.
34 changes: 31 additions & 3 deletions mgm/QdbMaster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "common/plugin_manager/PluginManager.hh"
#include "common/IntervalStopwatch.hh"
#include <qclient/QClient.hh>
#include "common/ShellCmd.hh"

EOSMGMNAMESPACE_BEGIN

Expand Down Expand Up @@ -110,6 +111,7 @@ QdbMaster::BootNamespace()
namespaceConfig["qdb_password"] = gOFS->mQdbPassword;
namespaceConfig["qdb_flusher_md"] = SSTR(instance_id << "_md");
namespaceConfig["qdb_flusher_quota"] = SSTR(instance_id << "_quota");

if (!gOFS->mQClientFlusherType.empty()) {
namespaceConfig["qclient_flusher_type"] = gOFS->mQClientFlusherType;
}
Expand All @@ -118,7 +120,6 @@ QdbMaster::BootNamespace()
namespaceConfig["qclient_rocksdb_options"] = gOFS->mQClientRocksDBOptions;
}


FillNsCacheConfig(gOFS->ConfEngine, namespaceConfig);

if (!gOFS->namespaceGroup->initialize(&gOFS->eosViewRWMutex, namespaceConfig,
Expand Down Expand Up @@ -319,6 +320,7 @@ QdbMaster::Supervisor(ThreadAssistant& assistant) noexcept

MasterLog(eos_log(LOG_ERR, "%s", "msg=\"acquired the master lease\""));
SlaveToMaster();
PostSlaveToMaster(old_master_id, GetMasterId());
}
} else {
std::string new_master_id = GetMasterId();
Expand All @@ -337,8 +339,7 @@ QdbMaster::Supervisor(ThreadAssistant& assistant) noexcept
eos_static_info("%s", "msg=\"follow up master-to-slave transition\"");
Access::SetMasterToSlaveRules(new_master_id);
gOFS->mTracker.SetAcceptingRequests(true);
}
else {
} else {
if (new_master_id == mIdentity) {
if (mDoMasterDelay) {
if (mMasterDelayDeadline < std::chrono::system_clock::now()) {
Expand Down Expand Up @@ -367,6 +368,33 @@ QdbMaster::Supervisor(ThreadAssistant& assistant) noexcept
RemoveStatusFile(EOSMGMMASTER_SUBSYS_RW_LOCKFILE);
}

//------------------------------------------------------------------------------
// PostSlaveToMaster runs a custom hook. It is invoked after the SlaveToMaster
// transition. It only runs if configured in the mgmofs.postslavetomaster option.
//------------------------------------------------------------------------------
void QdbMaster::PostSlaveToMaster(std::string old_master,
std::string new_master)
{
if (gOFS->mPostSlaveToMaster.length() == 0) {
return;
}

eos_static_info("msg=\"running post slave to master script\" path=\"%s\"",
gOFS->mPostSlaveToMaster.c_str());
std::string script = std::string(gOFS->mPostSlaveToMaster.c_str())
+ " '" + old_master + "'"
+ " '" + new_master + "'";
eos::common::ShellCmd cmd(script);
auto status = cmd.wait(POST_SLAVE_TO_MASTER_TIMEOUT);

if (status.exit_code) {
eos_static_warning("msg=\"post slave to master script failed\" script=\"%s\" retcode=%d",
script, status.exit_code);
} else {
eos_static_info("msg=\"post slave to master script run successfully\"");
}
}

//------------------------------------------------------------------------------
// Slave to master transition
//------------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions mgm/QdbMaster.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class QClient;

EOSMGMNAMESPACE_BEGIN

#define POST_SLAVE_TO_MASTER_TIMEOUT 60

//------------------------------------------------------------------------------
//! Class IMaster
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -214,6 +216,11 @@ private:
//----------------------------------------------------------------------------
void SlaveToMaster();

//----------------------------------------------------------------------------
//! Run a post slave to master hook, if configured
//----------------------------------------------------------------------------
void PostSlaveToMaster(std::string old_master, std::string new_master);

//----------------------------------------------------------------------------
//! Master to slave transition
//----------------------------------------------------------------------------
Expand Down
12 changes: 8 additions & 4 deletions mgm/XrdMgmOfs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -830,8 +830,8 @@ public:
//! container and the file individually before checking their access with the
//! AccessChecker.
//----------------------------------------------------------------------------
int _access(const char*, int mode, XrdOucErrInfo&,
eos::common::VirtualIdentity& vid, const char*);
int _access(const char*, int mode, XrdOucErrInfo&,
eos::common::VirtualIdentity& vid, const char*);

//----------------------------------------------------------------------------
//! @brief define access permissions for files/directories
Expand Down Expand Up @@ -1759,6 +1759,8 @@ public:
XrdOucString MgmAuthDir; ///< Directory containing exported authentication token
XrdOucString ManagerId; ///< manager id in <host>:<port> format
XrdOucString ManagerIp; ///< manager ip in <xxx.yyy.zzz.vvv> format
XrdOucString
mPostSlaveToMaster; ///< Path of the script running after the Slave to Master transition
int ManagerPort; ///< manager port as number e.g. 1094
uint16_t XrdHttpPort; ///< The port on which the XrdHttp server is running
std::string
Expand Down Expand Up @@ -1795,8 +1797,10 @@ public:
bool mAuthorize; ///< Determine if the authorization should be applied or not
std::string mAuthLib; ///< Path to authorization library
bool mTapeEnabled; ///< True if support for tape is enabled
std::string mPrepareDestSpace; ///< Space to be used when retrieving files from tape
unsigned int mReqIdMax; ///< Maximum number of request IDs on a single retrieving file
std::string
mPrepareDestSpace; ///< Space to be used when retrieving files from tape
unsigned int
mReqIdMax; ///< Maximum number of request IDs on a single retrieving file
//! Acts only as a redirector, disables many components in the MGM
bool MgmRedirector;
//! Writes error log with cluster wide collected errors in
Expand Down
10 changes: 10 additions & 0 deletions mgm/XrdMgmOfsConfigure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,16 @@ XrdMgmOfs::Configure(XrdSysError& Eroute)
}
}

if (!strcmp("postslavetomaster", var)) {
if (!(val = Config.GetWord())) {
Eroute.Emsg("Config", "argument for postslavetomaster invalid.");
NoGo = 1;
} else {
Eroute.Say("=====> mgmofs.postslavetomaster: ", val, "");
mPostSlaveToMaster = val;
}
}

if (!strcmp("protowfendpoint", var)) {
val = Config.GetWord();

Expand Down
3 changes: 3 additions & 0 deletions misc/etc/eos/config/mgm/mgm
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ mgmofs.autoloadconfig default
# QoS configuration file
mgmofs.qoscfg /var/eos/qos/qos.conf

# Post slave to master transition script
# mgmofs.postslavetomaster /usr/bin/true

#-------------------------------------------------------------------------------
# Configuration for the authentication plugin EosAuth
#-------------------------------------------------------------------------------
Expand Down

0 comments on commit a50759c

Please sign in to comment.