diff options
author | Henning Baldersheim <balder@oath.com> | 2018-02-07 16:14:16 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@oath.com> | 2018-02-07 16:14:39 +0100 |
commit | 18c1a9a17b830f733724116bc384e23452da2d6c (patch) | |
tree | e9e08f1a0e2189895378f1331630a55eafa8f8a7 /searchlib | |
parent | 28e82d7f9abcc2d1b7d9899ee7a53253f617e8b1 (diff) |
Safeguard the tls instance
Diffstat (limited to 'searchlib')
-rw-r--r-- | searchlib/src/vespa/searchlib/transactionlog/translogserverapp.cpp | 23 | ||||
-rw-r--r-- | searchlib/src/vespa/searchlib/transactionlog/translogserverapp.h | 3 |
2 files changed, 19 insertions, 7 deletions
diff --git a/searchlib/src/vespa/searchlib/transactionlog/translogserverapp.cpp b/searchlib/src/vespa/searchlib/transactionlog/translogserverapp.cpp index ff4a402b438..562597e4521 100644 --- a/searchlib/src/vespa/searchlib/transactionlog/translogserverapp.cpp +++ b/searchlib/src/vespa/searchlib/transactionlog/translogserverapp.cpp @@ -12,7 +12,8 @@ namespace search::transactionlog { TransLogServerApp::TransLogServerApp(const config::ConfigUri & tlsConfigUri, const FileHeaderContext & fileHeaderContext) - : _tls(), + : _lock(), + _tls(), _tlsConfig(), _tlsConfigFetcher(tlsConfigUri.getContext()), _fileHeaderContext(fileHeaderContext) @@ -23,7 +24,8 @@ TransLogServerApp::TransLogServerApp(const config::ConfigUri & tlsConfigUri, namespace { -DomainPart::Crc getCrc(searchlib::TranslogserverConfig::Crcmethod crcType) +DomainPart::Crc +getCrc(searchlib::TranslogserverConfig::Crcmethod crcType) { switch (crcType) { case searchlib::TranslogserverConfig::ccitt_crc32: @@ -36,11 +38,13 @@ DomainPart::Crc getCrc(searchlib::TranslogserverConfig::Crcmethod crcType) } -void TransLogServerApp::start() +void +TransLogServerApp::start() { std::shared_ptr<searchlib::TranslogserverConfig> c = _tlsConfig.get(); - _tls.reset(new TransLogServer(c->servername, c->listenport, c->basedir, _fileHeaderContext, - c->filesizemax, c->maxthreads, getCrc(c->crcmethod))); + std::lock_guard<std::mutex> guard(_lock); + _tls = std::make_shared<TransLogServer>(c->servername, c->listenport, c->basedir, _fileHeaderContext, + c->filesizemax, c->maxthreads, getCrc(c->crcmethod)); } TransLogServerApp::~TransLogServerApp() @@ -48,11 +52,18 @@ TransLogServerApp::~TransLogServerApp() _tlsConfigFetcher.close(); } -void TransLogServerApp::configure(std::unique_ptr<searchlib::TranslogserverConfig> cfg) +void +TransLogServerApp::configure(std::unique_ptr<searchlib::TranslogserverConfig> cfg) { LOG(config, "configure Transaction Log Server %s at port %d", cfg->servername.c_str(), cfg->listenport); _tlsConfig.set(cfg.release()); _tlsConfig.latch(); } +TransLogServer::SP +TransLogServerApp::getTransLogServer() const { + std::lock_guard<std::mutex> guard(_lock); + return _tls; +} + } diff --git a/searchlib/src/vespa/searchlib/transactionlog/translogserverapp.h b/searchlib/src/vespa/searchlib/transactionlog/translogserverapp.h index 35fa994d1e4..d46805c105c 100644 --- a/searchlib/src/vespa/searchlib/transactionlog/translogserverapp.h +++ b/searchlib/src/vespa/searchlib/transactionlog/translogserverapp.h @@ -14,6 +14,7 @@ namespace search::transactionlog { class TransLogServerApp : public config::IFetcherCallback<searchlib::TranslogserverConfig> { private: + mutable std::mutex _lock; TransLogServer::SP _tls; vespalib::PtrHolder<searchlib::TranslogserverConfig> _tlsConfig; config::ConfigFetcher _tlsConfigFetcher; @@ -28,7 +29,7 @@ public: const common::FileHeaderContext &fileHeaderContext); ~TransLogServerApp(); - TransLogServer::SP getTransLogServer() const { return _tls; } + TransLogServer::SP getTransLogServer() const; void start(); }; |