diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-02-22 21:51:16 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-02-22 21:51:16 +0000 |
commit | 6b51f51682ccc516180528e58ebf68fcd186d921 (patch) | |
tree | 7985a02583e9b7f6437c810231e81299ae2642d9 /config | |
parent | 1d21b938ab838d8e0138d19dd4bd0f60f374eaf0 (diff) |
Ensure that the transport thread has longer lifetime than the FRTConnectionPool.
Diffstat (limited to 'config')
-rw-r--r-- | config/src/vespa/config/frt/frtconnectionpool.cpp | 40 | ||||
-rw-r--r-- | config/src/vespa/config/frt/frtconnectionpool.h | 32 |
2 files changed, 31 insertions, 41 deletions
diff --git a/config/src/vespa/config/frt/frtconnectionpool.cpp b/config/src/vespa/config/frt/frtconnectionpool.cpp index 15ba8472af0..f416b0e1a57 100644 --- a/config/src/vespa/config/frt/frtconnectionpool.cpp +++ b/config/src/vespa/config/frt/frtconnectionpool.cpp @@ -76,6 +76,27 @@ FRTConnectionPool::getNextRoundRobin() return nextFRTConnection; } +namespace { +/** + * Implementation of the Java hashCode function for the String class. + * + * Ensures that the same hostname maps to the same configserver/proxy + * for both language implementations. + * + * @param s the string to compute the hash from + * @return the hash value + */ +int hashCode(const vespalib::string & s) { + int hashval = 0; + + for (int i = 0; i < (int) s.length(); i++) { + hashval = 31 * hashval + s[i]; + } + return hashval; +} + +} + FRTConnection * FRTConnectionPool::getNextHashBased() { @@ -123,20 +144,10 @@ FRTConnectionPool::getSuspendedSources() const return suspendedSources; } -int FRTConnectionPool::hashCode(const vespalib::string & s) -{ - int hashval = 0; - - for (int i = 0; i < (int)s.length(); i++) { - hashval = 31 * hashval + s[i]; - } - return hashval; -} - void FRTConnectionPool::setHostname() { - _hostname = vespalib::HostName::get(); + setHostname(vespalib::HostName::get()); } FNET_Scheduler * @@ -147,15 +158,16 @@ FRTConnectionPool::getScheduler() { FRTConnectionPoolWithTransport::FRTConnectionPoolWithTransport(std::unique_ptr<FastOS_ThreadPool> threadPool, std::unique_ptr<FNET_Transport> transport, const ServerSpec & spec, const TimingValues & timingValues) - : FRTConnectionPool(*transport, spec, timingValues), - _threadPool(std::move(threadPool)), - _transport(std::move(transport)) + : _threadPool(std::move(threadPool)), + _transport(std::move(transport)), + _connectionPool(std::make_unique<FRTConnectionPool>(*_transport, spec, timingValues)) { _transport->Start(_threadPool.get()); } FRTConnectionPoolWithTransport::~FRTConnectionPoolWithTransport() { + syncTransport(); _transport->ShutDown(true); } diff --git a/config/src/vespa/config/frt/frtconnectionpool.h b/config/src/vespa/config/frt/frtconnectionpool.h index b7530f8536e..564c6506159 100644 --- a/config/src/vespa/config/frt/frtconnectionpool.h +++ b/config/src/vespa/config/frt/frtconnectionpool.h @@ -60,21 +60,6 @@ public: FNET_Scheduler * getScheduler() override; /** - * Gets the hostname. - * - * @return the hostname - */ - vespalib::string & getHostname() { return _hostname; } - - /** - * Trim away leading and trailing spaces. - * - * @param s the string to trim away spaces from - * @return string without leading or trailing spaces - */ - vespalib::string trim(vespalib::string s); - - /** * Returns the current FRTConnection instance, taken from the list of error-free sources. * If no sources are error-free, an instance from the list of sources with errors * is returned. @@ -114,20 +99,9 @@ public: * @param suspendedSources is list of FRTConnection pointers */ std::vector<FRTConnection*> getSuspendedSources() const; - - /** - * Implementation of the Java hashCode function for the String class. - * - * Ensures that the same hostname maps to the same configserver/proxy - * for both language implementations. - * - * @param s the string to compute the hash from - * @return the hash value - */ - static int hashCode(const vespalib::string & s); }; -class FRTConnectionPoolWithTransport : public FRTConnectionPool { +class FRTConnectionPoolWithTransport : public ConnectionFactory { public: FRTConnectionPoolWithTransport(std::unique_ptr<FastOS_ThreadPool> threadPool, std::unique_ptr<FNET_Transport> transport, @@ -135,9 +109,13 @@ public: FRTConnectionPoolWithTransport(const FRTConnectionPoolWithTransport&) = delete; FRTConnectionPoolWithTransport& operator=(const FRTConnectionPoolWithTransport&) = delete; ~FRTConnectionPoolWithTransport() override; + FNET_Scheduler * getScheduler() override { return _connectionPool->getScheduler(); } + void syncTransport() override { _connectionPool->syncTransport(); } + Connection* getCurrent() override { return _connectionPool->getCurrent(); } private: std::unique_ptr<FastOS_ThreadPool> _threadPool; std::unique_ptr<FNET_Transport> _transport; + std::unique_ptr<FRTConnectionPool> _connectionPool; }; } // namespace config |