Skip to content

Commit

Permalink
Specify connection when creating Allocation/Admin session for Glacier2
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier committed Oct 23, 2024
1 parent d177c1b commit 7728901
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 22 deletions.
20 changes: 13 additions & 7 deletions cpp/src/IceGrid/AdminSessionI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,15 @@ AdminSessionFactory::AdminSessionFactory(
}

Glacier2::SessionPrx
AdminSessionFactory::createGlacier2Session(const string& sessionId, const optional<Glacier2::SessionControlPrx>& ctl)
AdminSessionFactory::createGlacier2Session(
const string& sessionId,
const optional<Glacier2::SessionControlPrx>& ctl,
const Ice::ConnectionPtr& con)
{
assert(_servantManager);

auto session = createSessionServant(sessionId);
auto proxy = session->_register(_servantManager, nullptr);
auto proxy = session->_register(_servantManager, con);

if (ctl)
{
Expand All @@ -489,7 +492,7 @@ AdminSessionFactory::createGlacier2Session(const string& sessionId, const option
// We can't use a non-0 timeout such as the Glacier2 session timeout. As of Ice 3.8, heartbeats may not be sent
// at all on a busy connection. Furthermore, as of Ice 3.8, Glacier2 no longer "converts" heartbeats into
// keepAlive requests.
_reaper->add(make_shared<SessionReapable<AdminSessionI>>(_database->getTraceLevels()->logger, session), 0s);
_reaper->add(make_shared<SessionReapable<AdminSessionI>>(_database->getTraceLevels()->logger, session), 0s, con);
return Ice::uncheckedCast<Glacier2::SessionPrx>(proxy);
}

Expand All @@ -508,15 +511,18 @@ AdminSessionFactory::getTraceLevels() const
AdminSessionManagerI::AdminSessionManagerI(const shared_ptr<AdminSessionFactory>& factory) : _factory(factory) {}

optional<Glacier2::SessionPrx>
AdminSessionManagerI::create(string userId, optional<Glacier2::SessionControlPrx> ctl, const Ice::Current&)
AdminSessionManagerI::create(string userId, optional<Glacier2::SessionControlPrx> ctl, const Ice::Current& current)
{
return _factory->createGlacier2Session(std::move(userId), std::move(ctl));
return _factory->createGlacier2Session(std::move(userId), std::move(ctl), current.con);
}

AdminSSLSessionManagerI::AdminSSLSessionManagerI(const shared_ptr<AdminSessionFactory>& factory) : _factory(factory) {}

optional<Glacier2::SessionPrx>
AdminSSLSessionManagerI::create(Glacier2::SSLInfo info, optional<Glacier2::SessionControlPrx> ctl, const Ice::Current&)
AdminSSLSessionManagerI::create(
Glacier2::SSLInfo info,
optional<Glacier2::SessionControlPrx> ctl,
const Ice::Current& current)
{
string userDN;
if (!info.certs.empty()) // TODO: Require userDN?
Expand All @@ -535,5 +541,5 @@ AdminSSLSessionManagerI::create(Glacier2::SSLInfo info, optional<Glacier2::Sessi
}
}

return _factory->createGlacier2Session(std::move(userDN), std::move(ctl));
return _factory->createGlacier2Session(std::move(userDN), std::move(ctl), current.con);
}
7 changes: 5 additions & 2 deletions cpp/src/IceGrid/AdminSessionI.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ namespace IceGrid
const std::shared_ptr<ReapThread>&,
const std::shared_ptr<RegistryI>&);

Glacier2::SessionPrx
createGlacier2Session(const std::string&, const std::optional<Glacier2::SessionControlPrx>&);
Glacier2::SessionPrx createGlacier2Session(
const std::string& sessionId,
const std::optional<Glacier2::SessionControlPrx>& ctl,
const Ice::ConnectionPtr& con);

std::shared_ptr<AdminSessionI> createSessionServant(const std::string&);

const std::shared_ptr<TraceLevels>& getTraceLevels() const;
Expand Down
10 changes: 8 additions & 2 deletions cpp/src/IceGrid/InternalRegistryI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ InternalRegistryI::registerNode(
try
{
auto session = NodeSessionI::create(_database, std::move(*node), info, _nodeSessionTimeout, load);
_reaper->add(make_shared<SessionReapable<NodeSessionI>>(logger, session), _nodeSessionTimeout);

// nullptr for the connection parameter, meaning the reaper won't destroy the session if the connection is
// closed.
_reaper->add(make_shared<SessionReapable<NodeSessionI>>(logger, session), _nodeSessionTimeout, nullptr);
return session->getProxy();
}
catch (const Ice::ObjectAdapterDestroyedException&)
Expand Down Expand Up @@ -93,7 +96,10 @@ InternalRegistryI::registerReplica(
try
{
auto s = ReplicaSessionI::create(_database, _wellKnownObjects, info, std::move(*prx), _replicaSessionTimeout);
_reaper->add(make_shared<SessionReapable<ReplicaSessionI>>(logger, s), _replicaSessionTimeout);

// nullptr for the connection parameter, meaning the reaper won't destroy the session if the connection is
// closed.
_reaper->add(make_shared<SessionReapable<ReplicaSessionI>>(logger, s), _replicaSessionTimeout, nullptr);
return s->getProxy();
}
catch (const Ice::ObjectAdapterDestroyedException&)
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/IceGrid/ReapThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ ReapThread::add(const shared_ptr<Reapable>& reapable, chrono::seconds timeout, c
}

// NOTE: registering a reapable with a 0s timeout is allowed. The reapable is reaped only when the reaper thread is
// shutdown or the connection is closed.
// shutdown or the connection is closed (when connection is not null).

//
// 10 seconds is the minimum permissable timeout (for non-zero timeouts).
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/IceGrid/ReapThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace IceGrid

void terminate();
void join();
void add(const std::shared_ptr<Reapable>&, std::chrono::seconds, const Ice::ConnectionPtr& = nullptr);
void add(const std::shared_ptr<Reapable>&, std::chrono::seconds, const Ice::ConnectionPtr&);

void connectionClosed(const Ice::ConnectionPtr&);

Expand Down
17 changes: 10 additions & 7 deletions cpp/src/IceGrid/SessionI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,15 @@ ClientSessionFactory::ClientSessionFactory(
}

Glacier2::SessionPrx
ClientSessionFactory::createGlacier2Session(const string& sessionId, const optional<Glacier2::SessionControlPrx>& ctl)
ClientSessionFactory::createGlacier2Session(
const string& sessionId,
const optional<Glacier2::SessionControlPrx>& ctl,
const Ice::ConnectionPtr& con)
{
assert(_servantManager);

auto session = createSessionServant(sessionId);
auto proxy = session->_register(_servantManager, nullptr);
auto proxy = session->_register(_servantManager, con);

if (ctl)
{
Expand All @@ -308,7 +311,7 @@ ClientSessionFactory::createGlacier2Session(const string& sessionId, const optio
// We can't use a non-0 timeout such as the Glacier2 session timeout. As of Ice 3.8, heartbeats may not be sent
// at all on a busy connection. Furthermore, as of Ice 3.8, Glacier2 no longer "converts" heartbeats into
// keepAlive requests.
_reaper->add(make_shared<SessionReapable<SessionI>>(_database->getTraceLevels()->logger, session), 0s);
_reaper->add(make_shared<SessionReapable<SessionI>>(_database->getTraceLevels()->logger, session), 0s, con);
return Ice::uncheckedCast<Glacier2::SessionPrx>(proxy);
}

Expand All @@ -327,9 +330,9 @@ ClientSessionFactory::getTraceLevels() const
ClientSessionManagerI::ClientSessionManagerI(const shared_ptr<ClientSessionFactory>& factory) : _factory(factory) {}

std::optional<Glacier2::SessionPrx>
ClientSessionManagerI::create(string user, std::optional<Glacier2::SessionControlPrx> ctl, const Ice::Current&)
ClientSessionManagerI::create(string user, std::optional<Glacier2::SessionControlPrx> ctl, const Ice::Current& current)
{
return _factory->createGlacier2Session(std::move(user), std::move(ctl));
return _factory->createGlacier2Session(std::move(user), std::move(ctl), current.con);
}

ClientSSLSessionManagerI::ClientSSLSessionManagerI(const shared_ptr<ClientSessionFactory>& factory) : _factory(factory)
Expand All @@ -340,7 +343,7 @@ std::optional<Glacier2::SessionPrx>
ClientSSLSessionManagerI::create(
Glacier2::SSLInfo info,
std::optional<Glacier2::SessionControlPrx> ctl,
const Ice::Current&)
const Ice::Current& current)
{
string userDN;
if (!info.certs.empty()) // TODO: Require userDN?
Expand All @@ -360,5 +363,5 @@ ClientSSLSessionManagerI::create(
}
}

return _factory->createGlacier2Session(userDN, ctl);
return _factory->createGlacier2Session(userDN, ctl, current.con);
}
6 changes: 4 additions & 2 deletions cpp/src/IceGrid/SessionI.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ namespace IceGrid
const IceInternal::TimerPtr&,
const std::shared_ptr<ReapThread>&);

Glacier2::SessionPrx
createGlacier2Session(const std::string&, const std::optional<Glacier2::SessionControlPrx>&);
Glacier2::SessionPrx createGlacier2Session(
const std::string& sessionId,
const std::optional<Glacier2::SessionControlPrx>& ctl,
const Ice::ConnectionPtr& con);

std::shared_ptr<SessionI> createSessionServant(const std::string&);

Expand Down

0 comments on commit 7728901

Please sign in to comment.