diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-12-20 06:37:17 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-12-20 09:56:44 +0000 |
commit | 553ae81bbfb5b69ca94561f0a31d11619c0f46e7 (patch) | |
tree | 6d879d4c29c4d05b497e917d3fa22fea5dc78e40 | |
parent | 4782899c5fe63298c0bb371bb1298b137a62208c (diff) |
- Allow the FRTSource to handle multiple concurrent requests by using a guarded map.
- Also wait for all requests to finish and avoid transportSync().
-rw-r--r-- | config/src/vespa/config/frt/frtsource.cpp | 39 | ||||
-rw-r--r-- | config/src/vespa/config/frt/frtsource.h | 7 |
2 files changed, 32 insertions, 14 deletions
diff --git a/config/src/vespa/config/frt/frtsource.cpp b/config/src/vespa/config/frt/frtsource.cpp index 1cb514dcd4d..11839ac0b50 100644 --- a/config/src/vespa/config/frt/frtsource.cpp +++ b/config/src/vespa/config/frt/frtsource.cpp @@ -35,9 +35,9 @@ FRTSource::FRTSource(std::shared_ptr<ConnectionFactory> connectionFactory, const : _connectionFactory(std::move(connectionFactory)), _requestFactory(requestFactory), _agent(std::move(agent)), - _currentRequest(), _key(key), _lock(), + _inflight(), _task(std::make_unique<GetConfigTask>(_connectionFactory->getScheduler(), this)), _closed(false) { @@ -66,8 +66,10 @@ FRTSource::getConfig() std::unique_ptr<FRTConfigRequest> request = _requestFactory.createConfigRequest(_key, connection, state, serverTimeout); FRT_RPCRequest * req = request->getRequest(); - - _currentRequest = std::move(request); + { + std::lock_guard guard(_lock); + _inflight[req] = std::move(request); + } connection->invoke(req, clientTimeout, this); } @@ -79,13 +81,24 @@ FRTSource::RequestDone(FRT_RPCRequest * request) LOG(debug, "request aborted, stopping"); return; } - assert(_currentRequest); + std::shared_ptr<FRTConfigRequest> configRequest; + { + std::lock_guard guard(_lock); + auto found = _inflight.find(request); + assert(found != _inflight.end()); + configRequest = found->second; + } // If this was error from FRT side and nothing to do with config, notify // connection about the error. if (request->IsError()) { - _currentRequest->setError(request->GetErrorCode()); + configRequest->setError(request->GetErrorCode()); + } + _agent->handleResponse(*configRequest, configRequest->createResponse(request)); + { + std::lock_guard guard(_lock); + _inflight.erase(request); + _cond.notify_all(); } - _agent->handleResponse(*_currentRequest, _currentRequest->createResponse(request)); LOG(spam, "Calling schedule"); scheduleNextGetConfig(); } @@ -93,19 +106,23 @@ FRTSource::RequestDone(FRT_RPCRequest * request) void FRTSource::close() { + RequestMap inflight; { std::lock_guard guard(_lock); if (_closed) return; LOG(spam, "Killing task"); _task->Kill(); + inflight = _inflight; } LOG(spam, "Aborting"); - if (_currentRequest.get() != NULL) - _currentRequest->abort(); - LOG(spam, "Syncing"); - _connectionFactory->syncTransport(); - _currentRequest.reset(0); + for (auto & request : inflight) { + std::move(request.second)->abort(); + } + inflight.clear(); + LOG(spam, "Waiting"); + std::unique_lock guard(_lock); + while (!_inflight.empty()) _cond.wait(guard); LOG(spam, "closed"); } diff --git a/config/src/vespa/config/frt/frtsource.h b/config/src/vespa/config/frt/frtsource.h index 1885aa7e534..104b7318d8d 100644 --- a/config/src/vespa/config/frt/frtsource.h +++ b/config/src/vespa/config/frt/frtsource.h @@ -29,13 +29,14 @@ public: private: void scheduleNextGetConfig(); + using RequestMap = std::map<FRT_RPCRequest *, std::shared_ptr<FRTConfigRequest>>; std::shared_ptr<ConnectionFactory> _connectionFactory; const FRTConfigRequestFactory & _requestFactory; std::unique_ptr<ConfigAgent> _agent; - std::unique_ptr<FRTConfigRequest> _currentRequest; const ConfigKey _key; - - std::mutex _lock; // Protects _task and _closed + std::mutex _lock; // Protects _inflight, _task and _closed + std::condition_variable _cond; + RequestMap _inflight; std::unique_ptr<FNET_Task> _task; bool _closed; }; |