Commit 9d3c3e1e by Elvin Sindrilaru

COMMON/MGM: Change interface of RWMutex and update code

Conflicts:
	mgm/GeoBalancer.cc
	mgm/Quota.cc
parent dcfaa617
......@@ -61,9 +61,9 @@ public:
//!
//! @param timeout_ns nano seconds timeout
//!
//! @return 0 if succcessful, otherwise error code
//! @return true if lock acquired successfully, otherwise false
//----------------------------------------------------------------------------
virtual int TimedRdLock(uint64_t timeout_ns) = 0;
virtual bool TimedRdLock(uint64_t timeout_ns) = 0;
//----------------------------------------------------------------------------
//! Lock for write
......@@ -80,9 +80,9 @@ public:
//!
//! @param timeout_ns nano seconds timeout
//!
//! @return 0 if succcessful, otherwise error code
//! @return true if lock acquired successfully, otherwise false
//----------------------------------------------------------------------------
virtual int TimedWrLock(uint64_t timeout_ns) = 0;
virtual bool TimedWrLock(uint64_t timeout_ns) = 0;
//----------------------------------------------------------------------------
//! Get read lock counter
......
......@@ -217,7 +217,7 @@ PthreadRWMutex::~PthreadRWMutex()
//------------------------------------------------------------------------------
// Try to read lock the mutex within the timout value
//------------------------------------------------------------------------------
int
bool
PthreadRWMutex::TimedRdLock(uint64_t timeout_ns)
{
EOS_RWMUTEX_CHECKORDER_LOCK;
......@@ -259,7 +259,7 @@ PthreadRWMutex::TimedRdLock(uint64_t timeout_ns)
#endif
EOS_RWMUTEX_TIMER_STOP_AND_UPDATE(mRd);
return retc;
return (retc == 0);
}
//----------------------------------------------------------------------------
......@@ -462,7 +462,7 @@ PthreadRWMutex::UnLockWrite()
//------------------------------------------------------------------------------
// Lock for write but give up after wlocktime
//------------------------------------------------------------------------------
int
bool
PthreadRWMutex::TimedWrLock(uint64_t timeout_ns)
{
EOS_RWMUTEX_CHECKORDER_LOCK;
......@@ -501,7 +501,7 @@ PthreadRWMutex::TimedWrLock(uint64_t timeout_ns)
}
#endif
return retc;
return (retc == 0);
}
#ifdef EOS_INSTRUMENTED_RWMUTEX
......
......@@ -123,9 +123,9 @@ public:
//!
//! @param timeout_ns nano seconds timeout
//!
//! @return 0 if succcessful, otherwise error code
//! @return true if lock acquired successfully, otherwise false
//----------------------------------------------------------------------------
int TimedRdLock(uint64_t timeout_ns) override;
bool TimedRdLock(uint64_t timeout_ns) override;
//----------------------------------------------------------------------------
//! Lock for write
......@@ -142,9 +142,9 @@ public:
//!
//! @param timeout_ns nano seconds timeout
//!
//! @return 0 if succcessful, otherwise error code
//! @return true if lock acquired successfully, otherwise false
//----------------------------------------------------------------------------
int TimedWrLock(uint64_t timeout_ns) override;
bool TimedWrLock(uint64_t timeout_ns) override;
//----------------------------------------------------------------------------
//! Get Readlock Counter
......
......@@ -46,7 +46,7 @@ SharedMutex::UnLockRead()
//------------------------------------------------------------------------------
// Try to read lock the mutex within the timeout
//------------------------------------------------------------------------------
int
bool
SharedMutex::TimedRdLock(uint64_t timeout_ns)
{
std::chrono::nanoseconds ns(timeout_ns);
......@@ -76,7 +76,7 @@ SharedMutex::UnLockWrite()
//------------------------------------------------------------------------------
// Try to write lock the mutex within the timeout
//------------------------------------------------------------------------------
int
bool
SharedMutex::TimedWrLock(uint64_t timeout_ns)
{
std::chrono::nanoseconds ns(timeout_ns);
......
......@@ -79,9 +79,9 @@ public:
//!
//! @param timeout_ns nano seconds timeout
//!
//! @return 0 if succcessful, otherwise error code
//! @return true if lock acquired successfully, otherwise false
//----------------------------------------------------------------------------
int TimedRdLock(uint64_t timeout_ns) override;
bool TimedRdLock(uint64_t timeout_ns) override;
//----------------------------------------------------------------------------
//! Lock for write
......@@ -98,9 +98,9 @@ public:
//!
//! @param timeout_ns nano seconds timeout
//!
//! @return 0 if succcessful, otherwise error code
//! @return true if lock acquired successfully, otherwise false
//----------------------------------------------------------------------------
int TimedWrLock(uint64_t timeout_ns) override;
bool TimedWrLock(uint64_t timeout_ns) override;
//----------------------------------------------------------------------------
//! Get Readlock Counter
......
......@@ -103,11 +103,11 @@ Balancer::Balance(void)
std::string SpaceNodeTransfers = "";
std::string SpaceNodeTransferRate = "";
std::string SpaceNodeThreshold = "";
uint64_t timeout_ms = 100;
uint64_t timeout_ns = 100 * 1e6; // 100ms
eos_static_info("Looping in balancer");
// Try to read lock the mutex
while (FsView::gFsView.ViewMutex.TimedRdLock(timeout_ms)) {
while (!FsView::gFsView.ViewMutex.TimedRdLock(timeout_ns)) {
XrdSysThread::CancelPoint();
}
......
......@@ -398,10 +398,10 @@ Converter::Convert(void)
{
// Extract the current settings if conversion enabled and how many
// conversion jobs should run.
uint64_t timeout_ms = 100;
uint64_t timeout_ns = 100 * 1e6; // 100ms
// Try to read lock the mutex
while (FsView::gFsView.ViewMutex.TimedRdLock(timeout_ms)) {
while (!FsView::gFsView.ViewMutex.TimedRdLock(timeout_ns)) {
XrdSysThread::CancelPoint();
}
......
......@@ -75,7 +75,7 @@ GeoBalancer::Stop()
*/
/*----------------------------------------------------------------------------*/
{
if(mThread) {
if (mThread) {
XrdSysThread::Cancel(mThread);
}
}
......@@ -89,7 +89,7 @@ GeoBalancer::Join()
*/
/*----------------------------------------------------------------------------*/
{
if(mThread) {
if (mThread) {
XrdSysThread::Cancel(mThread);
XrdSysThread::Join(mThread, nullptr);
mThread = 0;
......@@ -490,19 +490,11 @@ GeoBalancer::chooseFidFromGeotag(const std::string& geotag)
int attempts = 10;
while (attempts-- > 0) {
rndIndex = getRandom(fsid_size - 1);
for (auto it_fid = gOFS->eosFsView->getFileList(fsid);
(it_fid && it_fid->valid()); it_fid->next()) {
// Jump to random location
if (rndIndex > 0) {
--rndIndex;
continue;
}
eos::IFileMD::id_t randomPick;
if (mTransfers.count(it_fid->getElement()) == 0) {
return it_fid->getElement();
}
if (gOFS->eosFsView->getApproximatelyRandomFileInFs(fsid, randomPick) &&
mTransfers.count(randomPick) == 0) {
return randomPick;
}
}
......@@ -631,10 +623,10 @@ GeoBalancer::GeoBalance()
{
// Extract the current settings if conversion enabled and how many
// conversion jobs should run
uint64_t timeout_ms = 100;
uint64_t timeout_ns = 100 * 1e6; // 100ms
// Try to read lock the mutex
while (FsView::gFsView.ViewMutex.TimedRdLock(timeout_ms)) {
while (!FsView::gFsView.ViewMutex.TimedRdLock(timeout_ns)) {
XrdSysThread::CancelPoint();
}
......
......@@ -71,7 +71,7 @@ GroupBalancer::GroupBalancer(const char* spacename)
void
GroupBalancer::Stop()
{
if(mThread) {
if (mThread) {
XrdSysThread::Cancel(mThread);
}
}
......@@ -84,7 +84,7 @@ GroupBalancer::Stop()
void
GroupBalancer::Join()
{
if(mThread) {
if (mThread) {
XrdSysThread::Cancel(mThread);
XrdSysThread::Join(mThread, nullptr);
mThread = 0;
......@@ -493,10 +493,10 @@ GroupBalancer::chooseFidFromGroup(FsGroup* group)
int attempts = 10;
while (attempts-- > 0) {
eos::IFileMD::id_t randomPick;
if(gOFS->eosFsView->getApproximatelyRandomFileInFs(fsid, randomPick) &&
mTransfers.count(randomPick) == 0) {
if (gOFS->eosFsView->getApproximatelyRandomFileInFs(fsid, randomPick) &&
mTransfers.count(randomPick) == 0) {
return randomPick;
}
}
......@@ -649,10 +649,10 @@ GroupBalancer::GroupBalance()
{
// Extract the current settings if conversion enabled and how many
// conversion jobs should run
uint64_t timeout_ms = 100;
uint64_t timeout_ns = 100 * 1e6; // 100 ms
// Try to read lock the mutex
while (FsView::gFsView.ViewMutex.TimedRdLock(timeout_ms)) {
while (!FsView::gFsView.ViewMutex.TimedRdLock(timeout_ns)) {
XrdSysThread::CancelPoint();
}
......
......@@ -155,7 +155,7 @@ SpaceQuota::UpdateQuotaNodeAddress()
return false;
}
} catch (eos::MDException& e) {
mQuotaNode = (eos::IQuotaNode*)0;
mQuotaNode = nullptr;
return false;
}
......
......@@ -119,7 +119,7 @@ xrdmgmofs_shutdown(int sig)
eos_static_warning("Shutdown:: grab write mutex");
uint64_t timeout_ns = 3 * 1e9;
while (gOFS->eosViewRWMutex.TimedWrLock(timeout_ns)) {
while (!gOFS->eosViewRWMutex.TimedWrLock(timeout_ns)) {
eos_static_warning("Trying to get the wr lock on eosViewRWMutex");
}
......@@ -154,7 +154,7 @@ xrdmgmofs_shutdown(int sig)
delete gOFS->eosContainerAccounting;
}
while (gOFS->eosViewRWMutex.TimedWrLock(timeout_ns)) {
while (!gOFS->eosViewRWMutex.TimedWrLock(timeout_ns)) {
eos_static_warning("Trying to get the wr lock on eosViewRWMutex");
}
......
......@@ -318,9 +318,9 @@ Drainer::Drain()
}
while (true) {
uint64_t timeout_ms = 100;
uint64_t timeout_ns = 100 * 1e6; // 100ms
while (FsView::gFsView.ViewMutex.TimedRdLock(timeout_ms)) {
while (!FsView::gFsView.ViewMutex.TimedRdLock(timeout_ns)) {
XrdSysThread::CancelPoint();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment