Skip to content
Snippets Groups Projects
Commit feab755e authored by Eric Cano's avatar Eric Cano
Browse files

Added sequence number to agent name in AgentReference::AgentReference()

This ensures the uniqueness of the agent name even if a process creates an agent several times in the same second.
parent 37f768eb
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,8 @@
namespace cta { namespace objectstore {
std::atomic <uint64_t> AgentReference::g_nextAgentId(0);
AgentReference::AgentReference(const std::string & clientType, log::Logger &logger):
m_logger(logger) {
m_nextId=0;
......@@ -41,6 +43,7 @@ m_logger(logger) {
cta::exception::Errnum::throwOnMinusOne(::gethostname(host, sizeof(host)),
"In AgentId::AgentId: failed to gethostname");
// gettid is a safe system call (never fails)
uint64_t id=g_nextAgentId++;
aid << clientType << "-" << host << "-" << syscall(SYS_gettid) << "-"
<< 1900 + localNow.tm_year
<< std::setfill('0') << std::setw(2)
......@@ -48,7 +51,8 @@ m_logger(logger) {
<< std::setw(2) << localNow.tm_mday << "-"
<< std::setw(2) << localNow.tm_hour << ":"
<< std::setw(2) << localNow.tm_min << ":"
<< std::setw(2) << localNow.tm_sec;
<< std::setw(2) << localNow.tm_sec << "-"
<< id;
m_agentAddress = aid.str();
// Initialize the serialization token for queued actions (lock will make helgrind
// happy, but not really needed
......
......@@ -99,6 +99,7 @@ public:
*/
std::string getAgentAddress();
private:
static std::atomic<uint64_t> g_nextAgentId;
std::atomic<uint64_t> m_nextId;
std::string m_agentAddress;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment