Skip to content

Commit

Permalink
ALL: Replace use of XrdSysTimer with std::this_thread::sleep_for
Browse files Browse the repository at this point in the history
  • Loading branch information
esindril committed Jul 4, 2018
1 parent dcc1625 commit 0538c59
Show file tree
Hide file tree
Showing 55 changed files with 1,117 additions and 1,251 deletions.
1 change: 0 additions & 1 deletion common/JeMallocHandler.cc
Expand Up @@ -26,7 +26,6 @@
#include <dlfcn.h>
#include <string>
#include <cstdio>
#include "XrdSys/XrdSysTimer.hh"
#include <XrdOuc/XrdOucString.hh>

EOSCOMMONNAMESPACE_BEGIN
Expand Down
12 changes: 4 additions & 8 deletions common/ShellCmd.cc
Expand Up @@ -33,7 +33,6 @@
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include "XrdSys/XrdSysTimer.hh"

#ifdef __APPLE__
#define EOS_PTRACE_CONTINUE PT_CONTINUE
Expand Down Expand Up @@ -129,8 +128,7 @@ ShellCmd::monitor()
perror("error: failed to attach to forked process");

while (is_active()) {
XrdSysTimer snooze;
snooze.Wait(250);
std::this_thread::sleep_for(std::chrono::milliseconds(250));
}

cmd_stat.exited = false;
Expand Down Expand Up @@ -171,9 +169,8 @@ ShellCmd::monitor()
break;
}

XrdSysTimer snooze;
// prevent tight loops
snooze.Wait(250);
// Prevent tight loops
std::this_thread::sleep_for(std::chrono::milliseconds(250));
}
}

Expand Down Expand Up @@ -210,8 +207,7 @@ ShellCmd::wait(size_t timeout)
break;
}

XrdSysTimer sleeper;
sleeper.Wait(exp_sleep);
std::this_thread::sleep_for(std::chrono::milliseconds(exp_sleep));

if (exp_sleep < 512) {
exp_sleep *= 2;
Expand Down
4 changes: 1 addition & 3 deletions common/ZMQ.cc
Expand Up @@ -22,7 +22,6 @@
************************************************************************/

#include "common/ZMQ.hh"
#include "XrdSys/XrdSysTimer.hh"

EOSCOMMONNAMESPACE_BEGIN

Expand Down Expand Up @@ -71,8 +70,7 @@ ZMQ::Listen()
while (1) {
zmq::message_t request;
(void) socket.recv(&request);
XrdSysTimer sleeper;
sleeper.Snooze(1);
std::this::thread::sleep_for(std::chrono::seconds(1));
Process(socket, request);
XrdSysThread::SetCancelOn();
XrdSysThread::CancelPoint();
Expand Down
11 changes: 5 additions & 6 deletions common/dbmaptest/DbMapTestBurn.cc
Expand Up @@ -35,13 +35,12 @@
#include <sstream>
#include <cstdio>
#include <sys/resource.h>
#include "XrdSys/XrdSysAtomics.hh"
using namespace eos::common;

const unsigned long int NNUM_THREADS = 10;
pthread_t threads[NNUM_THREADS];
unsigned long int NUM_THREADS = NNUM_THREADS;
int writecount;
std::atomic<int> writecount;

const char* dbfile = "/tmp/testlog.log";
int total, transacSize;
Expand Down Expand Up @@ -165,9 +164,9 @@ TestWriteGlob(void* threadid)
//unsigned long int thrid= (unsigned long int) pthread_self();

for (int k = 0; k < total; k++) {
AtomicInc(writecount);
++writecount;

if (writecount % transacSize == 0 && writecount > 0) {
if (writecount.load() % transacSize == 0 && writecount.load() > 0) {
globmap->endSetSequence();
globmap->beginSetSequence();
}
Expand Down Expand Up @@ -310,7 +309,7 @@ main()
total = n;
transacSize = transacsize[k];
overwrite = false;
writecount = 0;
writecount.store(0);
RunThreadsGlob();
elapsed = (int)time(NULL) - (int)seconds;
elapsed = (elapsed ? elapsed : 1);
Expand All @@ -334,7 +333,7 @@ main()
total = n;
transacSize = transacsize[k];
overwrite = true;
writecount = 0;
writecount.store(0);
RunThreadsGlob();
elapsed = (int)time(NULL) - (int)seconds;
elapsed = (elapsed ? elapsed : 1);
Expand Down
8 changes: 5 additions & 3 deletions common/http/HttpServer.cc
Expand Up @@ -92,7 +92,7 @@ HttpServer::Run()
std::string thread_model = "threads";
{
// Delay to make sure xrootd is configured before serving
XrdSysTimer::Snooze(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
int nthreads = 16;

if (getenv("EOS_HTTP_THREADPOOL")) {
Expand All @@ -113,7 +113,8 @@ HttpServer::Run()

if (thread_model == "threads") {
eos_static_notice("msg=\"starting http server\" mode=\"thread-per-connection\"");
mDaemon = MHD_start_daemon(MHD_USE_DEBUG | MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DUAL_STACK |
mDaemon = MHD_start_daemon(MHD_USE_DEBUG | MHD_USE_THREAD_PER_CONNECTION |
MHD_USE_DUAL_STACK |
MHD_USE_POLL,
mPort,
NULL,
Expand All @@ -132,7 +133,8 @@ HttpServer::Run()
} else if (thread_model == "epoll") {
eos_static_notice("msg=\"starting http server\" mode=\"epoll\" threads=%d",
nthreads);
mDaemon = MHD_start_daemon(MHD_USE_DEBUG | MHD_USE_SELECT_INTERNALLY | MHD_USE_DUAL_STACK |
mDaemon = MHD_start_daemon(MHD_USE_DEBUG | MHD_USE_SELECT_INTERNALLY |
MHD_USE_DUAL_STACK |
MHD_USE_EPOLL_LINUX_ONLY,
mPort,
NULL,
Expand Down
7 changes: 3 additions & 4 deletions fst/FmdDbMap.cc
Expand Up @@ -204,8 +204,7 @@ FmdDbMapHandler::GetMgmFmd(const char* manager,

if ((status.code >= 100) &&
(status.code <= 300)) {
XrdSysTimer sleeper;
sleeper.Snooze(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
eos_static_info("msg=\"retry query\" query=\"%s\"", fmdquery.c_str());

if (!manager) {
Expand Down Expand Up @@ -1179,7 +1178,7 @@ FmdDbMapHandler::ResyncAllMgm(eos::common::FileSystem::fsid_t fsid,
// Resync all meta data from QuarkdDB
//------------------------------------------------------------------------------
bool
FmdDbMapHandler::ResyncAllFromQdb(const QdbContactDetails &contactDetails,
FmdDbMapHandler::ResyncAllFromQdb(const QdbContactDetails& contactDetails,
eos::common::FileSystem::fsid_t fsid)
{
using namespace std::chrono;
Expand All @@ -1194,7 +1193,7 @@ FmdDbMapHandler::ResyncAllFromQdb(const QdbContactDetails &contactDetails,
long long count = 250000;
std::pair<std::string, std::vector<std::string>> reply;
std::unique_ptr<qclient::QClient> qcl(new
qclient::QClient(contactDetails.members, contactDetails.constructOptions()));
qclient::QClient(contactDetails.members, contactDetails.constructOptions()));
qclient::QSet qset(*qcl.get(), eos::RequestBuilder::keyFilesystemFiles(fsid));
std::unordered_set<eos::IFileMD::id_t> file_ids;

Expand Down
3 changes: 1 addition & 2 deletions fst/Messaging.cc
Expand Up @@ -49,8 +49,7 @@ Messaging::Listen()
XrdSysThread::SetCancelOn();
} else {
XrdSysThread::SetCancelOn();
XrdSysTimer sleeper;
sleeper.Wait(2000);
std::this_thread::sleep_for(std::chrono::seconds(2));
}

XrdSysThread::CancelPoint();
Expand Down
13 changes: 5 additions & 8 deletions fst/ScanDir.cc
Expand Up @@ -672,8 +672,7 @@ ScanDir::ThreadProc(void)
XrdSysThread::CancelPoint();
}

XrdSysTimer sleeper;
sleeper.Wait(1000);
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}

Expand Down Expand Up @@ -739,17 +738,15 @@ ScanDir::ThreadProc(void)
XrdSysThread::CancelPoint();
}

XrdSysTimer sleeper;
sleeper.Wait(1000);
std::this_thread::sleep_for(std::chrono::seconds(1));
}
} else {
// Call the ghost entry clean-up function
if (bgThread) {
eos_notice("Directory: %s fsid=%d - cleaning ghost entries", dirPath.c_str(),
fsId);
gFmdDbMapHandler.RemoveGhostEntries(dirPath.c_str(), fsId);
XrdSysTimer sleeper;
sleeper.Wait(60 * 1000);
std::this_thread::sleep_for(std::chrono::seconds(60));
}
}
}
Expand Down Expand Up @@ -842,8 +839,8 @@ ScanDir::ScanFileLoadAware(const std::unique_ptr<eos::fst::FileIo>& io,
float expecttime = (1.0 * offset / currentRate) / 1000.0;

if (expecttime > scantime) {
XrdSysTimer sleeper;
sleeper.Wait(expecttime - scantime);
std::this_thread::sleep_for
(std::chrono::milliseconds((int)(expecttime - scantime)));
}

//adjust the rate according to the load information
Expand Down
28 changes: 11 additions & 17 deletions fst/XrdFstOfs.cc
Expand Up @@ -46,7 +46,6 @@
#include "XrdOuc/XrdOucHash.hh"
#include "XrdOuc/XrdOucTrace.hh"
#include "XrdSfs/XrdSfsAio.hh"
#include "XrdSys/XrdSysTimer.hh"
#include "XrdSys/XrdSysDNS.hh"
#include "Xrd/XrdScheduler.hh"
#include "XrdCl/XrdClFileSystem.hh"
Expand Down Expand Up @@ -239,8 +238,7 @@ XrdFstOfs::xrdfstofs_shutdown(int sig)
gOFS.Messaging->StopListener(); // stop any communication
}

XrdSysTimer sleeper;
sleeper.Wait(1000);
std::this_thread::sleep_for(std::chrono::seconds(1));
gOFS.Storage->ShutdownThreads();
eos_static_warning("op=shutdown msg=\"stop messaging\"");
eos_static_warning("%s", "op=shutdown msg=\"shutdown fmddbmap handler\"");
Expand Down Expand Up @@ -279,10 +277,9 @@ XrdFstOfs::xrdfstofs_graceful_shutdown(int sig)
std::int64_t wait = (swait ? std::strtol(swait, nullptr, 10) : 390);

if (!(watchdog = fork())) {
XrdSysTimer sleeper;
sleeper.Snooze(wait);
std::this_thread::sleep_for(std::chrono::seconds(wait));
SyncAll::AllandClose();
sleeper.Snooze(15);
std::this_thread::sleep_for(std::chrono::seconds(15));
fprintf(stderr, "@@@@@@ 00:00:00 %s %li seconds\"\n",
"op=shutdown msg=\"shutdown timedout after ", wait);
kill(getppid(), 9);
Expand Down Expand Up @@ -311,8 +308,7 @@ XrdFstOfs::xrdfstofs_graceful_shutdown(int sig)
eos_static_err("op=shutdown msg=\"failed graceful IO shutdown\"");
}

XrdSysTimer sleeper;
sleeper.Wait(1000);
std::this_thread::sleep_for(std::chrono::seconds(1));
gOFS.Storage->ShutdownThreads();
eos_static_warning("op=shutdown msg=\"shutdown fmddbmap handler\"");
gFmdDbMapHandler.Shutdown();
Expand Down Expand Up @@ -490,25 +486,26 @@ XrdFstOfs::Configure(XrdSysError& Eroute, XrdOucEnv* envP)
}
}

if(!strcmp("qdbpassword", var)) {
if (!strcmp("qdbpassword", var)) {
while ((val = Config.GetWord())) {
mQdbContactDetails.password += val;
}

// Trim whitespace at the end
common::PasswordHandler::rightTrimWhitespace(mQdbContactDetails.password);

std::string pwlen = std::to_string(mQdbContactDetails.password.size());
Eroute.Say("=====> fstofs.qdbpassword length : ", pwlen.c_str());
}

if(!strcmp("qdbpassword_file", var)) {
if (!strcmp("qdbpassword_file", var)) {
std::string path;

while ((val = Config.GetWord())) {
path += val;
}

if(!common::PasswordHandler::readPasswordFile(path, mQdbContactDetails.password)) {
if (!common::PasswordHandler::readPasswordFile(path,
mQdbContactDetails.password)) {
Eroute.Emsg("Config", "failed to open path pointed to by qdbpassword_file");
NoGo = 1;
}
Expand Down Expand Up @@ -646,8 +643,7 @@ XrdFstOfs::Configure(XrdSysError& Eroute, XrdOucEnv* envP)
return 1;
}

XrdSysTimer sleeper;
sleeper.Snooze(5);
std::this_thread::sleep_for(std::chrono::seconds(5));
ObjectNotifier.SetShareObjectManager(&ObjectManager);

if (!ObjectNotifier.Start()) {
Expand Down Expand Up @@ -707,7 +703,6 @@ XrdFstOfs::Configure(XrdSysError& Eroute, XrdOucEnv* envP)
XrdOucString dumperfile = eos::fst::Config::gConfig.FstMetaLogDir;
dumperfile += "so.fst.dump.";
dumperfile += eos::fst::Config::gConfig.FstHostPort;

ObjectManager.StartDumper(dumperfile.c_str());
XrdOucString keytabcks = "unaccessible";
// Start the embedded HTTP server
Expand Down Expand Up @@ -945,8 +940,7 @@ XrdFstOfs::CallManager(XrdOucErrInfo* error, const char* path,
if (retry && (status.code >= 100) && (status.code <= 300) && (!timeout)) {
// implement automatic retry - network errors will be cured at some point
delete fs;
XrdSysTimer sleeper;
sleeper.Snooze(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
tried++;
eos_static_info("msg=\"retry query\" query=\"%s\"", opaque.c_str());

Expand Down

0 comments on commit 0538c59

Please sign in to comment.