mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 08:41:16 +00:00
shm: make shmId also available as uint64_t
This commit is contained in:
parent
0fd2fcadc2
commit
edbdc57332
|
@ -11,6 +11,7 @@
|
||||||
#include <picosha2.h>
|
#include <picosha2.h>
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <functional> // std::equal_to
|
#include <functional> // std::equal_to
|
||||||
|
|
||||||
|
@ -194,15 +195,25 @@ struct RegionBlock
|
||||||
|
|
||||||
// find id for unique shmem name:
|
// find id for unique shmem name:
|
||||||
// a hash of user id + session id, truncated to 8 characters (to accommodate for name size limit on some systems (MacOS)).
|
// a hash of user id + session id, truncated to 8 characters (to accommodate for name size limit on some systems (MacOS)).
|
||||||
inline std::string buildShmIdFromSessionIdAndUserId(const std::string& sessionId)
|
inline std::string makeShmIdStr(const std::string& sessionId)
|
||||||
{
|
{
|
||||||
std::string seed((std::to_string(geteuid()) + sessionId));
|
std::string seed((std::to_string(geteuid()) + sessionId));
|
||||||
// generate a 8-digit hex value out of sha256 hash
|
// generate a 8-digit hex value out of sha256 hash
|
||||||
std::vector<unsigned char> hash(4);
|
std::vector<unsigned char> hash(4);
|
||||||
picosha2::hash256(seed.begin(), seed.end(), hash.begin(), hash.end());
|
picosha2::hash256(seed.begin(), seed.end(), hash.begin(), hash.end());
|
||||||
std::string shmId = picosha2::bytes_to_hex_string(hash.begin(), hash.end());
|
|
||||||
|
|
||||||
return shmId;
|
return picosha2::bytes_to_hex_string(hash.begin(), hash.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline uint64_t makeShmIdUint64(const std::string& sessionId)
|
||||||
|
{
|
||||||
|
std::string shmId = makeShmIdStr(sessionId);
|
||||||
|
uint64_t id = 0;
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << std::hex << shmId;
|
||||||
|
ss >> id;
|
||||||
|
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SegmentSize : public boost::static_visitor<size_t>
|
struct SegmentSize : public boost::static_visitor<size_t>
|
||||||
|
|
|
@ -393,7 +393,7 @@ void Monitor::PrintDebugInfo(const ShmId& shmId __attribute__((unused)))
|
||||||
|
|
||||||
void Monitor::PrintDebugInfo(const SessionId& sessionId)
|
void Monitor::PrintDebugInfo(const SessionId& sessionId)
|
||||||
{
|
{
|
||||||
ShmId shmId{buildShmIdFromSessionIdAndUserId(sessionId.sessionId)};
|
ShmId shmId{makeShmIdStr(sessionId.sessionId)};
|
||||||
PrintDebugInfo(shmId);
|
PrintDebugInfo(shmId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,7 +429,7 @@ unordered_map<uint16_t, std::vector<BufferDebugInfo>> Monitor::GetDebugInfo(cons
|
||||||
}
|
}
|
||||||
unordered_map<uint16_t, std::vector<BufferDebugInfo>> Monitor::GetDebugInfo(const SessionId& sessionId)
|
unordered_map<uint16_t, std::vector<BufferDebugInfo>> Monitor::GetDebugInfo(const SessionId& sessionId)
|
||||||
{
|
{
|
||||||
ShmId shmId{buildShmIdFromSessionIdAndUserId(sessionId.sessionId)};
|
ShmId shmId{makeShmIdStr(sessionId.sessionId)};
|
||||||
return GetDebugInfo(shmId);
|
return GetDebugInfo(shmId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,7 +536,7 @@ std::vector<std::pair<std::string, bool>> Monitor::Cleanup(const ShmId& shmId, b
|
||||||
|
|
||||||
std::vector<std::pair<std::string, bool>> Monitor::Cleanup(const SessionId& sessionId, bool verbose /* = true */)
|
std::vector<std::pair<std::string, bool>> Monitor::Cleanup(const SessionId& sessionId, bool verbose /* = true */)
|
||||||
{
|
{
|
||||||
ShmId shmId{buildShmIdFromSessionIdAndUserId(sessionId.sessionId)};
|
ShmId shmId{makeShmIdStr(sessionId.sessionId)};
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
cout << "Cleanup called with session id '" << sessionId.sessionId << "', translating to shared memory id '" << shmId.shmId << "'" << endl;
|
cout << "Cleanup called with session id '" << sessionId.sessionId << "', translating to shared memory id '" << shmId.shmId << "'" << endl;
|
||||||
}
|
}
|
||||||
|
@ -553,7 +553,7 @@ std::vector<std::pair<std::string, bool>> Monitor::CleanupFull(const ShmId& shmI
|
||||||
|
|
||||||
std::vector<std::pair<std::string, bool>> Monitor::CleanupFull(const SessionId& sessionId, bool verbose /* = true */)
|
std::vector<std::pair<std::string, bool>> Monitor::CleanupFull(const SessionId& sessionId, bool verbose /* = true */)
|
||||||
{
|
{
|
||||||
ShmId shmId{buildShmIdFromSessionIdAndUserId(sessionId.sessionId)};
|
ShmId shmId{makeShmIdStr(sessionId.sessionId)};
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
cout << "Cleanup called with session id '" << sessionId.sessionId << "', translating to shared memory id '" << shmId.shmId << "'" << endl;
|
cout << "Cleanup called with session id '" << sessionId.sessionId << "', translating to shared memory id '" << shmId.shmId << "'" << endl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,10 +35,8 @@ namespace fair::mq::shmem
|
||||||
class TransportFactory final : public fair::mq::TransportFactory
|
class TransportFactory final : public fair::mq::TransportFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TransportFactory(const std::string& id = "", const ProgOptions* config = nullptr)
|
TransportFactory(const std::string& deviceId = "", const ProgOptions* config = nullptr)
|
||||||
: fair::mq::TransportFactory(id)
|
: fair::mq::TransportFactory(deviceId)
|
||||||
, fDeviceId(id)
|
|
||||||
, fShmId()
|
|
||||||
, fZmqCtx(zmq_ctx_new())
|
, fZmqCtx(zmq_ctx_new())
|
||||||
, fManager(nullptr)
|
, fManager(nullptr)
|
||||||
{
|
{
|
||||||
|
@ -69,8 +67,8 @@ class TransportFactory final : public fair::mq::TransportFactory
|
||||||
throw SharedMemoryError(tools::ToString("Provided shared memory allocation algorithm '", allocationAlgorithm, "' is not supported. Supported are 'rbtree_best_fit'/'simple_seq_fit'"));
|
throw SharedMemoryError(tools::ToString("Provided shared memory allocation algorithm '", allocationAlgorithm, "' is not supported. Supported are 'rbtree_best_fit'/'simple_seq_fit'"));
|
||||||
}
|
}
|
||||||
|
|
||||||
fShmId = buildShmIdFromSessionIdAndUserId(sessionName);
|
std::string shmId = makeShmIdStr(sessionName);
|
||||||
LOG(debug) << "Generated shmid '" << fShmId << "' out of session id '" << sessionName << "'.";
|
LOG(debug) << "Generated shmid '" << shmId << "' out of session id '" << sessionName << "'.";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (zmq_ctx_set(fZmqCtx, ZMQ_IO_THREADS, numIoThreads) != 0) {
|
if (zmq_ctx_set(fZmqCtx, ZMQ_IO_THREADS, numIoThreads) != 0) {
|
||||||
|
@ -82,7 +80,7 @@ class TransportFactory final : public fair::mq::TransportFactory
|
||||||
LOG(error) << "failed configuring context, reason: " << zmq_strerror(errno);
|
LOG(error) << "failed configuring context, reason: " << zmq_strerror(errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
fManager = std::make_unique<Manager>(fShmId, fDeviceId, segmentSize, config);
|
fManager = std::make_unique<Manager>(shmId, deviceId, segmentSize, config);
|
||||||
} catch (boost::interprocess::interprocess_exception& e) {
|
} catch (boost::interprocess::interprocess_exception& e) {
|
||||||
LOG(error) << "Could not initialize shared memory transport: " << e.what();
|
LOG(error) << "Could not initialize shared memory transport: " << e.what();
|
||||||
throw std::runtime_error(tools::ToString("Could not initialize shared memory transport: ", e.what()));
|
throw std::runtime_error(tools::ToString("Could not initialize shared memory transport: ", e.what()));
|
||||||
|
@ -200,8 +198,6 @@ class TransportFactory final : public fair::mq::TransportFactory
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string fDeviceId;
|
|
||||||
std::string fShmId;
|
|
||||||
void* fZmqCtx;
|
void* fZmqCtx;
|
||||||
std::unique_ptr<Manager> fManager;
|
std::unique_ptr<Manager> fManager;
|
||||||
};
|
};
|
||||||
|
|
|
@ -111,7 +111,7 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shmId == "") {
|
if (shmId == "") {
|
||||||
shmId = buildShmIdFromSessionIdAndUserId(sessionName);
|
shmId = makeShmIdStr(sessionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cleanup) {
|
if (cleanup) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user