diff options
45 files changed, 552 insertions, 523 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/FileDistributionFactory.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/FileDistributionFactory.java index 12cc76afc6b..32602ab70b8 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/FileDistributionFactory.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/FileDistributionFactory.java @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.session; -import com.yahoo.config.provision.ApplicationId; import com.yahoo.jrt.Supervisor; import com.yahoo.jrt.Transport; import com.yahoo.vespa.config.server.filedistribution.FileDistributionProvider; @@ -23,6 +22,7 @@ public class FileDistributionFactory { } @Override + @SuppressWarnings("deprecation") // finalize() is deprecated from Java 9 protected void finalize() throws Throwable { super.finalize(); supervisor.transport().shutdown().join(); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/FileServerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/FileServerTest.java index b0dce359d58..73cda93ccab 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/FileServerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/FileServerTest.java @@ -112,7 +112,9 @@ public class FileServerTest { created.clear(); } + // TODO: Why not use @After instead of finalizer? @Override + @SuppressWarnings("deprecation") // finalize() is deprecated from Java 9 protected void finalize() throws Throwable { super.finalize(); cleanup(); diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/core/ExportPackages.java b/jdisc_core/src/main/java/com/yahoo/jdisc/core/ExportPackages.java index 2e077dd1d6d..f2e9c1a6e53 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/core/ExportPackages.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/core/ExportPackages.java @@ -41,12 +41,19 @@ public class ExportPackages { .append("javax.inject;version=1.0.0,") // Included in guice, but not exported. Needed by container-jersey. .append("org.aopalliance.intercept,") .append("org.aopalliance.aop,") + + // xml-apis:xml-apis:1.4.01 is not a bundle + .append("org.w3c.dom,") + .append("org.w3c.dom.bootstrap,") .append("org.w3c.dom.css,") + .append("org.w3c.dom.events,") .append("org.w3c.dom.html,") + .append("org.w3c.dom.ls,") .append("org.w3c.dom.ranges,") .append("org.w3c.dom.stylesheets,") .append("org.w3c.dom.traversal,") .append("org.w3c.dom.views,") + .append("sun.misc,") .append("sun.net.util,") .append("sun.security.krb5"); diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/SelfCloseableHttpClient.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/SelfCloseableHttpClient.java index cead7816387..38c111bc3ba 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/SelfCloseableHttpClient.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/SelfCloseableHttpClient.java @@ -61,6 +61,7 @@ class SelfCloseableHttpClient implements AutoCloseable { } @Override + @SuppressWarnings("deprecation") // finalize() is deprecated from Java 9 public void finalize() throws Throwable { close(); super.finalize(); diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/NodeRepositoryMaintenance.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/NodeRepositoryMaintenance.java index 32c7a4035d9..4497f55cb85 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/NodeRepositoryMaintenance.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/NodeRepositoryMaintenance.java @@ -157,6 +157,7 @@ public class NodeRepositoryMaintenance extends AbstractComponent { operatorChangeRedeployInterval = Duration.ofMinutes(1); failedExpirerInterval = Duration.ofMinutes(10); provisionedExpiry = Duration.ofHours(4); + reservationExpiry = Duration.ofMinutes(20); // Need to be long enough for deployment to be finished for all config model versions rebootInterval = Duration.ofDays(30); nodeRetirerInterval = Duration.ofMinutes(30); metricsInterval = Duration.ofMinutes(1); @@ -170,12 +171,10 @@ public class NodeRepositoryMaintenance extends AbstractComponent { if (environment.equals(Environment.prod)) { - reservationExpiry = Duration.ofMinutes(20); // same as deployment timeout inactiveExpiry = Duration.ofHours(4); // enough time for the application owner to discover and redeploy retiredInterval = Duration.ofMinutes(29); dirtyExpiry = Duration.ofHours(2); // enough time to clean the node } else { - reservationExpiry = Duration.ofMinutes(10); // Need to be long enough for deployment to be finished for all config model versions inactiveExpiry = Duration.ofSeconds(2); // support interactive wipe start over retiredInterval = Duration.ofMinutes(5); dirtyExpiry = Duration.ofMinutes(30); diff --git a/parent/pom.xml b/parent/pom.xml index 1472c31851d..5db4bf94db3 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -419,11 +419,6 @@ <version>3.4.0</version> </dependency> <dependency> - <groupId>com.googlecode.jmockit</groupId> - <artifactId>jmockit</artifactId> - <version>1.2</version> - </dependency> - <dependency> <groupId>com.goldmansachs</groupId> <artifactId>gs-collections</artifactId> <version>6.1.0</version> diff --git a/searchcore/src/tests/fdispatch/search_path/search_path_test.cpp b/searchcore/src/tests/fdispatch/search_path/search_path_test.cpp index a649dd484b6..b62fb8d14f2 100644 --- a/searchcore/src/tests/fdispatch/search_path/search_path_test.cpp +++ b/searchcore/src/tests/fdispatch/search_path/search_path_test.cpp @@ -116,7 +116,7 @@ TEST("requireThatMultipleElementsWithoutRowsCanBeSpecified") TEST("require that sizeof FastS_FNET_SearchNode is reasonable") { - EXPECT_EQUAL(240u, sizeof(FastS_FNET_SearchNode)); + EXPECT_EQUAL(232u, sizeof(FastS_FNET_SearchNode)); EXPECT_EQUAL(40u, sizeof(search::common::SortDataIterator)); } diff --git a/searchcore/src/vespa/searchcore/fdispatch/common/search.cpp b/searchcore/src/vespa/searchcore/fdispatch/common/search.cpp index 7b060e793f6..3694fad7882 100644 --- a/searchcore/src/vespa/searchcore/fdispatch/common/search.cpp +++ b/searchcore/src/vespa/searchcore/fdispatch/common/search.cpp @@ -37,10 +37,9 @@ FastS_SearchAdapter::GetSearchInfo() FastS_ISearch::RetCode -FastS_SearchAdapter::SetAsyncArgs(FastS_ISearchOwner *owner, - FastS_SearchContext context) +FastS_SearchAdapter::SetAsyncArgs(FastS_ISearchOwner *owner) { - return _search->SetAsyncArgs(owner, context); + return _search->SetAsyncArgs(owner); } @@ -138,32 +137,12 @@ FastS_SyncSearchAdapter::FastS_SyncSearchAdapter(FastS_ISearch *search) _queryDone(false), _waitDocsums(false), _docsumsDone(false) -{ -} - - -FastS_SyncSearchAdapter::~FastS_SyncSearchAdapter() -{ -} - - - -FastS_ISearch * -FastS_SyncSearchAdapter::Adapt(FastS_ISearch *search) -{ - if (!search->IsAsync()) - return search; - - FastS_SyncSearchAdapter *ret = new FastS_SyncSearchAdapter(search); - search->SetAsyncArgs(ret, FastS_SearchContext()); - return ret; -} - +{} +FastS_SyncSearchAdapter::~FastS_SyncSearchAdapter() = default; void -FastS_SyncSearchAdapter::DoneQuery(FastS_ISearch *, - FastS_SearchContext) +FastS_SyncSearchAdapter::DoneQuery(FastS_ISearch *) { std::lock_guard<std::mutex> guard(_lock); _queryDone = true; @@ -174,8 +153,7 @@ FastS_SyncSearchAdapter::DoneQuery(FastS_ISearch *, void -FastS_SyncSearchAdapter::DoneDocsums(FastS_ISearch *, - FastS_SearchContext) +FastS_SyncSearchAdapter::DoneDocsums(FastS_ISearch *) { std::lock_guard<std::mutex> guard(_lock); _docsumsDone = true; @@ -215,16 +193,14 @@ FastS_SyncSearchAdapter::IsAsync() FastS_ISearch::RetCode -FastS_SyncSearchAdapter::SetAsyncArgs(FastS_ISearchOwner *, - FastS_SearchContext) +FastS_SyncSearchAdapter::SetAsyncArgs(FastS_ISearchOwner *) { return RET_ERROR; } FastS_ISearch::RetCode -FastS_SyncSearchAdapter::Search(uint32_t searchOffset, - uint32_t maxhits, uint32_t minhits) +FastS_SyncSearchAdapter::Search(uint32_t searchOffset, uint32_t maxhits, uint32_t minhits) { RetCode res = _search->Search(searchOffset, maxhits, minhits); if (res == RET_INPROGRESS) { diff --git a/searchcore/src/vespa/searchcore/fdispatch/common/search.h b/searchcore/src/vespa/searchcore/fdispatch/common/search.h index a1a8eb9f0ba..2639896cccc 100644 --- a/searchcore/src/vespa/searchcore/fdispatch/common/search.h +++ b/searchcore/src/vespa/searchcore/fdispatch/common/search.h @@ -14,32 +14,6 @@ class FastS_ISearch; -//---------------------------------------------------------------- - -class FastS_SearchContext -{ -public: - union { - uint32_t INT; - void *VOIDP; - } _value; - - FastS_SearchContext() - : _value() - { - _value.VOIDP = NULL; - } - explicit FastS_SearchContext(void *value) - : _value() - { - _value.VOIDP = value; - } - explicit FastS_SearchContext(uint32_t value) - : _value() - { - _value.INT = value; - } -}; //---------------------------------------------------------------- @@ -51,11 +25,8 @@ public: */ virtual ~FastS_ISearchOwner() { } - virtual void DoneQuery(FastS_ISearch *search, - FastS_SearchContext context) = 0; - - virtual void DoneDocsums(FastS_ISearch *search, - FastS_SearchContext context) = 0; + virtual void DoneQuery(FastS_ISearch *search) = 0; + virtual void DoneDocsums(FastS_ISearch *search) = 0; }; //---------------------------------------------------------------- @@ -196,7 +167,7 @@ public: // SET PARAMETERS - virtual RetCode SetAsyncArgs(FastS_ISearchOwner *owner, FastS_SearchContext context) = 0; + virtual RetCode SetAsyncArgs(FastS_ISearchOwner *owner) = 0; virtual RetCode setSearchRequest(const search::engine::SearchRequest * request) = 0; virtual RetCode SetGetDocsumArgs(search::docsummary::GetDocsumArgs *docsumArgs) = 0; @@ -231,10 +202,6 @@ public: class FastS_SearchBase : public FastS_ISearch { -private: - FastS_SearchBase(const FastS_SearchBase &); - FastS_SearchBase& operator=(const FastS_SearchBase &); - protected: uint32_t _dataSetID; search::engine::ErrorCode _errorCode; @@ -246,6 +213,8 @@ protected: FastS_DocsumsResult _docsumsResult; public: + FastS_SearchBase(const FastS_SearchBase &) = delete; + FastS_SearchBase& operator=(const FastS_SearchBase &) = delete; FastS_SearchBase(uint32_t dataSetID) : _dataSetID(dataSetID), _errorCode(search::engine::ECODE_NO_ERROR), @@ -258,14 +227,10 @@ public: { } - virtual ~FastS_SearchBase() - { + ~FastS_SearchBase() override { free(_errorMessage); } - const search::engine::SearchRequest * GetQueryArgs() { return _queryArgs; } - search::docsummary::GetDocsumArgs * GetGetDocsumArgs() { return _docsumArgs; } - void SetError(search::engine::ErrorCode errorCode, const char *errorMessage) { _errorCode = errorCode; @@ -276,84 +241,47 @@ public: } - virtual uint32_t GetDataSetID() override - { - return _dataSetID; - } - - virtual FastS_SearchInfo *GetSearchInfo() override - { - return &_searchInfo; - } + uint32_t GetDataSetID() override { return _dataSetID; } + FastS_SearchInfo *GetSearchInfo() override { return &_searchInfo; } - virtual RetCode setSearchRequest(const search::engine::SearchRequest * request) override - { + RetCode setSearchRequest(const search::engine::SearchRequest * request) override { _queryArgs = request; return RET_OK; } - virtual RetCode SetGetDocsumArgs(search::docsummary::GetDocsumArgs *docsumArgs) override - { + RetCode SetGetDocsumArgs(search::docsummary::GetDocsumArgs *docsumArgs) override { _docsumArgs = docsumArgs; return RET_OK; } - virtual RetCode Search(uint32_t searchOffset, - uint32_t maxhits, uint32_t minhits = 0) override - { + RetCode Search(uint32_t searchOffset, uint32_t maxhits, uint32_t minhits = 0) override { (void) minhits; _searchInfo._searchOffset = searchOffset; _searchInfo._maxHits = maxhits; return RET_OK; } - virtual RetCode ProcessQueryDone() override - { - return RET_OK; - } - - virtual FastS_QueryResult *GetQueryResult() override - { - return &_queryResult; - } + RetCode ProcessQueryDone() override { return RET_OK; } + FastS_QueryResult *GetQueryResult() override { return &_queryResult; } - virtual RetCode GetDocsums(const FastS_hitresult *hits, uint32_t hitcnt) override - { + RetCode GetDocsums(const FastS_hitresult *hits, uint32_t hitcnt) override { (void) hits; (void) hitcnt; return RET_OK; } - virtual RetCode ProcessDocsumsDone() override - { - return RET_OK; - } - - virtual FastS_DocsumsResult *GetDocsumsResult() override - { - return &_docsumsResult; - } + RetCode ProcessDocsumsDone() override { return RET_OK; } + FastS_DocsumsResult *GetDocsumsResult() override { return &_docsumsResult; } + search::engine::ErrorCode GetErrorCode() override { return _errorCode; } - virtual search::engine::ErrorCode GetErrorCode() override - { - return _errorCode; - } - - virtual const char *GetErrorMessage() override - { + const char *GetErrorMessage() override { if (_errorMessage != NULL) return _errorMessage; return search::engine::getStringFromErrorCode(_errorCode); } - virtual void Interrupt() override - { - } - - virtual void Free() override - { - delete this; - } + void Interrupt() override {} + void Free() override { delete this; } }; //---------------------------------------------------------------- @@ -364,70 +292,40 @@ private: bool _async; public: - FastS_FailedSearch(uint32_t dataSetID, - bool async, - search::engine::ErrorCode errorCode, - const char *errorMessage) + FastS_FailedSearch(uint32_t dataSetID, bool async, search::engine::ErrorCode errorCode, const char *errorMessage) : FastS_SearchBase(dataSetID), _async(async) { SetError(errorCode, errorMessage); } - virtual ~FastS_FailedSearch() {} - virtual bool IsAsync() override { return _async; } + bool IsAsync() override { return _async; } - virtual RetCode SetAsyncArgs(FastS_ISearchOwner *owner, - FastS_SearchContext context) override - { + RetCode SetAsyncArgs(FastS_ISearchOwner *owner) override { (void) owner; - (void) context; return (_async) ? RET_OK : RET_ERROR; } }; //---------------------------------------------------------------- -class FastS_SyncSearch : public FastS_SearchBase -{ -public: - FastS_SyncSearch(uint32_t dataSetID) - : FastS_SearchBase(dataSetID) {} - - bool IsAsync() override { return false; } - - virtual RetCode SetAsyncArgs(FastS_ISearchOwner *, - FastS_SearchContext) override - { - return RET_ERROR; - } -}; - -//---------------------------------------------------------------- - class FastS_AsyncSearch : public FastS_SearchBase { -private: - FastS_AsyncSearch(const FastS_AsyncSearch &); - FastS_AsyncSearch& operator=(const FastS_AsyncSearch &); - protected: FastS_ISearchOwner *_searchOwner; - FastS_SearchContext _searchContext; public: + FastS_AsyncSearch(const FastS_AsyncSearch &) = delete; + FastS_AsyncSearch& operator=(const FastS_AsyncSearch &) = delete; FastS_AsyncSearch(uint32_t dataSetID) : FastS_SearchBase(dataSetID), - _searchOwner(NULL), - _searchContext(FastS_SearchContext()) {} + _searchOwner(NULL) + {} bool IsAsync() override { return true; } - virtual RetCode SetAsyncArgs(FastS_ISearchOwner *owner, - FastS_SearchContext context) override - { + RetCode SetAsyncArgs(FastS_ISearchOwner *owner) override { _searchOwner = owner; - _searchContext = context; return RET_OK; } }; @@ -436,35 +334,31 @@ public: class FastS_SearchAdapter : public FastS_ISearch { -private: - FastS_SearchAdapter(const FastS_SearchAdapter &); - FastS_SearchAdapter& operator=(const FastS_SearchAdapter &); - protected: FastS_ISearch *_search; public: explicit FastS_SearchAdapter(FastS_ISearch *search); - virtual ~FastS_SearchAdapter(); - - virtual bool IsAsync() override; - virtual uint32_t GetDataSetID() override; - virtual FastS_SearchInfo *GetSearchInfo() override; - virtual RetCode SetAsyncArgs(FastS_ISearchOwner *owner, - FastS_SearchContext context) override; - virtual RetCode setSearchRequest(const search::engine::SearchRequest * request) override; - virtual RetCode SetGetDocsumArgs(search::docsummary::GetDocsumArgs *docsumArgs) override; - virtual RetCode Search(uint32_t searchOffset, - uint32_t maxhits, uint32_t minhits = 0) override; - virtual RetCode ProcessQueryDone() override; - virtual FastS_QueryResult *GetQueryResult() override; - virtual RetCode GetDocsums(const FastS_hitresult *hits, uint32_t hitcnt) override; - virtual RetCode ProcessDocsumsDone() override; - virtual FastS_DocsumsResult *GetDocsumsResult() override; - virtual search::engine::ErrorCode GetErrorCode() override; - virtual const char *GetErrorMessage() override; - virtual void Interrupt() override; - virtual void Free() override; + FastS_SearchAdapter(const FastS_SearchAdapter &) = delete; + FastS_SearchAdapter& operator=(const FastS_SearchAdapter &) = delete; + ~FastS_SearchAdapter() override; + + bool IsAsync() override; + uint32_t GetDataSetID() override; + FastS_SearchInfo *GetSearchInfo() override; + RetCode SetAsyncArgs(FastS_ISearchOwner *owner) override; + RetCode setSearchRequest(const search::engine::SearchRequest * request) override; + RetCode SetGetDocsumArgs(search::docsummary::GetDocsumArgs *docsumArgs) override; + RetCode Search(uint32_t searchOffset, uint32_t maxhits, uint32_t minhits = 0) override; + RetCode ProcessQueryDone() override; + FastS_QueryResult *GetQueryResult() override; + RetCode GetDocsums(const FastS_hitresult *hits, uint32_t hitcnt) override; + RetCode ProcessDocsumsDone() override; + FastS_DocsumsResult *GetDocsumsResult() override; + search::engine::ErrorCode GetErrorCode() override; + const char *GetErrorMessage() override; + void Interrupt() override; + void Free() override; }; //---------------------------------------------------------------- @@ -484,22 +378,19 @@ protected: explicit FastS_SyncSearchAdapter(FastS_ISearch *search); public: - virtual ~FastS_SyncSearchAdapter(); + ~FastS_SyncSearchAdapter() override; - static FastS_ISearch *Adapt(FastS_ISearch *search); - virtual void DoneQuery(FastS_ISearch *, FastS_SearchContext) override; - virtual void DoneDocsums(FastS_ISearch *, FastS_SearchContext) override; + void DoneQuery(FastS_ISearch *) override; + void DoneDocsums(FastS_ISearch *) override; void WaitQueryDone(); void WaitDocsumsDone(); - virtual bool IsAsync() override; - virtual RetCode SetAsyncArgs(FastS_ISearchOwner *owner, - FastS_SearchContext context) override; - virtual RetCode Search(uint32_t searchOffset, - uint32_t maxhits, uint32_t minhits = 0) override; - virtual RetCode GetDocsums(const FastS_hitresult *hits, uint32_t hitcnt) override; + bool IsAsync() override; + RetCode SetAsyncArgs(FastS_ISearchOwner *owner) override; + RetCode Search(uint32_t searchOffset, uint32_t maxhits, uint32_t minhits = 0) override; + RetCode GetDocsums(const FastS_hitresult *hits, uint32_t hitcnt) override; }; //---------------------------------------------------------------- diff --git a/searchcore/src/vespa/searchcore/fdispatch/search/fnet_dataset.cpp b/searchcore/src/vespa/searchcore/fdispatch/search/fnet_dataset.cpp index f6fb46a67ca..ecb68d3e63c 100644 --- a/searchcore/src/vespa/searchcore/fdispatch/search/fnet_dataset.cpp +++ b/searchcore/src/vespa/searchcore/fdispatch/search/fnet_dataset.cpp @@ -31,18 +31,12 @@ FastS_FNET_DataSet::FastS_FNET_DataSet(FNET_Transport *transport, } -FastS_FNET_DataSet::~FastS_FNET_DataSet() -{ -} - +FastS_FNET_DataSet::~FastS_FNET_DataSet() = default; bool FastS_FNET_DataSet::AddEngine(FastS_EngineDesc *desc) { - FastS_FNET_Engine *engine; - - engine = new FastS_FNET_Engine(desc, this); - FastS_assert(engine != NULL); + FastS_FNET_Engine *engine = new FastS_FNET_Engine(desc, this); InsertEngine(engine); @@ -57,7 +51,7 @@ namespace { struct ConnectFNETEngine { void operator()(FastS_EngineBase* engine) { FastS_FNET_Engine* fnet_engine = engine->GetFNETEngine(); - FastS_assert(fnet_engine != NULL); + FastS_assert(fnet_engine != nullptr); fnet_engine->ScheduleConnect(0.0); fnet_engine->StartWarnTimer(); } @@ -96,9 +90,9 @@ FastS_FNET_DataSet::Free() _pingTask.Kill(); for (FastS_EngineBase *engine = ExtractEngine(); - engine != NULL; engine = ExtractEngine()) + engine != nullptr; engine = ExtractEngine()) { - FastS_assert(engine->GetFNETEngine() != NULL); + FastS_assert(engine->GetFNETEngine() != nullptr); delete engine; } diff --git a/searchcore/src/vespa/searchcore/fdispatch/search/fnet_search.cpp b/searchcore/src/vespa/searchcore/fdispatch/search/fnet_search.cpp index b2082826fe6..fee7a4bf2ee 100644 --- a/searchcore/src/vespa/searchcore/fdispatch/search/fnet_search.cpp +++ b/searchcore/src/vespa/searchcore/fdispatch/search/fnet_search.cpp @@ -30,7 +30,6 @@ FastS_FNET_SearchNode::FastS_FNET_SearchNode(FastS_FNET_Search *search, uint32_t : _search(search), _engine(nullptr), _channel(nullptr), - _subds(0), _partid(partid), _rowid(0), _stamp(0), @@ -240,13 +239,13 @@ FastS_FNET_Search::Timeout::PerformTask() //--------------------------------------------------------------------- void -FastS_FNET_Search::AllocNodes() +FastS_FNET_Search::reallocNodes(size_t numParts) { - FastS_assert(_nodes.empty()); + _nodes.clear(); - _nodes.reserve(_dataset->GetPartitions()); + _nodes.reserve(numParts); - for (uint32_t i = 0; i < _nodes.capacity(); i++) { + for (uint32_t i = 0; i < numParts; i++) { _nodes.emplace_back(this, i); } } @@ -332,6 +331,10 @@ FastS_FNET_Search::ConnectQueryNodes() if (_dataset->useFixedRowDistribution()) { fixedRow = (_queryArgs->sessionId.empty()) ? getNextFixedRow() : getHashedRow(); _fixedRow = fixedRow; + size_t numParts = _dataset->getNumPartitions(fixedRow); + if (_nodes.size() > numParts) { + reallocNodes(numParts); + } } EngineNodeMap engines; engines.reserve(_nodes.size()); @@ -545,11 +548,9 @@ FastS_FNET_Search::FastS_FNET_Search(FastS_DataSetCollection *dsc, _estPartCutoff(dataset->GetEstimatePartCutoff()), _FNET_mode(FNET_NONE), _pendingQueries(0), - _goodQueries(0), _pendingDocsums(0), _pendingDocsumNodes(0), _requestedDocsums(0), - _goodDocsums(0), _queryNodes(0), _queryNodesTimedOut(0), _docsumNodes(0), @@ -569,7 +570,7 @@ FastS_FNET_Search::FastS_FNET_Search(FastS_DataSetCollection *dsc, { _util.GetQuery().SetDataSet(dataset->GetID()); _util.SetStartTime(GetTimeKeeper()->GetTime()); - AllocNodes(); + reallocNodes(_dataset->GetPartitions()); } @@ -613,7 +614,6 @@ FastS_FNET_Search::GotQueryResult(FastS_FNET_SearchNode *node, LOG(spam, "Got result from row(%d), part(%d) = hits(%d), numDocs(%" PRIu64 ")", node->GetRowID(), node->getPartID(), qrx->_numDocs, qrx->_totNumDocs); node->_flags._pendingQuery = false; _pendingQueries--; - _goodQueries++; double tnow = GetTimeKeeper()->GetTime(); node->_queryTime = tnow - _startTime; node->GetEngine()->UpdateSearchTime(tnow, node->_queryTime, false); @@ -642,8 +642,6 @@ FastS_FNET_Search::GotDocsum(FastS_FNET_SearchNode *node, docsum->swapBuf(_resbuf[offset]._buf); node->_pendingDocsums--; _pendingDocsums--; - if ( ! _resbuf[offset]._buf.empty()) - _goodDocsums++; // Only nonempty docsum is considered good if (node->_pendingDocsums == 0) { node->_docsumTime = (GetTimeKeeper()->GetTime() - _startTime - node->_queryTime); _pendingDocsumNodes--; @@ -820,11 +818,11 @@ FastS_FNET_Search::EndFNETWork(std::unique_lock<std::mutex> searchGuard) if (_FNET_mode == FNET_QUERY && _pendingQueries == 0) { _FNET_mode = FNET_NONE; searchGuard.unlock(); - _searchOwner->DoneQuery(this, _searchContext); + _searchOwner->DoneQuery(this); } else if (_FNET_mode == FNET_DOCSUMS && _pendingDocsums == 0) { _FNET_mode = FNET_NONE; searchGuard.unlock(); - _searchOwner->DoneDocsums(this, _searchContext); + _searchOwner->DoneDocsums(this); } } @@ -872,29 +870,25 @@ FastS_FNET_Search::CheckCoverage() uint16_t nodesQueried = 0; uint16_t nodesReplied = 0; size_t cntNone(0); - size_t configuredNodes(0); for (const FastS_FNET_SearchNode & node : _nodes) { - if (node.GetEngine() != nullptr) { - configuredNodes++; - if (node._qresult != nullptr) { - covDocs += node._qresult->_coverageDocs; - activeDocs += node._qresult->_activeDocs; - soonActiveDocs += node._qresult->_soonActiveDocs; - degradedReason |= node._qresult->_coverageDegradeReason; - nodesQueried += node._qresult->getNodesQueried(); - nodesReplied += node._qresult->getNodesReplied(); - } else { - nodesQueried++; - cntNone++; - } + if (node._qresult != nullptr) { + covDocs += node._qresult->_coverageDocs; + activeDocs += node._qresult->_activeDocs; + soonActiveDocs += node._qresult->_soonActiveDocs; + degradedReason |= node._qresult->_coverageDegradeReason; + nodesQueried += node._qresult->getNodesQueried(); + nodesReplied += node._qresult->getNodesReplied(); + } else { + nodesQueried++; + cntNone++; } } const ssize_t missingParts = cntNone - (_dataset->getSearchableCopies() - 1); - if ((missingParts > 0) && (cntNone != configuredNodes)) { + if ((missingParts > 0) && (cntNone != _nodes.size())) { // TODO This is a dirty way of anticipating missing coverage. // It should be done differently - activeDocs += missingParts * activeDocs/(configuredNodes - cntNone); + activeDocs += missingParts * activeDocs/(_nodes.size() - cntNone); } _util.SetCoverage(covDocs, activeDocs, soonActiveDocs, degradedReason, nodesQueried, nodesReplied); } diff --git a/searchcore/src/vespa/searchcore/fdispatch/search/fnet_search.h b/searchcore/src/vespa/searchcore/fdispatch/search/fnet_search.h index 755e1a0bca4..0ad9a7f0067 100644 --- a/searchcore/src/vespa/searchcore/fdispatch/search/fnet_search.h +++ b/searchcore/src/vespa/searchcore/fdispatch/search/fnet_search.h @@ -32,7 +32,6 @@ private: FastS_FNET_Search *_search; // we are part of this search FastS_FNET_Engine *_engine; // we use this search engine FNET_Channel *_channel; // connection with search engine - uint32_t _subds; // engine sub dataset uint32_t _partid; // engine partition id uint32_t _rowid; // engine row id uint32_t _stamp; // engine timestamp @@ -62,7 +61,6 @@ public: uint32_t _docidCnt; uint32_t _pendingDocsums; // how many docsums pending ? uint32_t _docsumRow; - uint32_t _docsumStamp; uint32_t _docsum_offsets_idx; double _docsumTime; @@ -89,7 +87,7 @@ public: FastS_FNET_SearchNode(const FastS_FNET_SearchNode &) = delete; FastS_FNET_SearchNode& operator=(const FastS_FNET_SearchNode &) = delete; - virtual ~FastS_FNET_SearchNode(); + ~FastS_FNET_SearchNode() override; // Methods needed by mergehits bool NT_InitMerge(uint32_t *numDocs, uint64_t *totalHits, search::HitRank *maxRank, uint32_t *sortDataDocs); @@ -103,7 +101,6 @@ public: uint32_t getPartID() const { return _partid; } uint32_t GetRowID() const { return _rowid; } - uint32_t GetTimeStamp() const { return _stamp; } FastS_FNET_SearchNode * allocExtraDocsumNode(bool mld, uint32_t rowid, uint32_t rowbits); @@ -117,13 +114,6 @@ public: void postGDX(uint32_t *pendingDocsums, uint32_t *pendingDocsumNodes); vespalib::string toString() const; - const char *getHostName() const { - return (_engine == nullptr ? "localhost" : _engine->getHostName()); - } - int getPortNumber() const { - return (_engine == nullptr ? 0 : _engine->getPortNumber()); - } - void dropCost() { if (_engine != nullptr && _flags._needSubCost) { _engine->SubCost(); @@ -152,7 +142,7 @@ public: return (_channel == nullptr) ? packet->Free(), false : _channel->Send(packet); } - virtual HP_RetCode HandlePacket(FNET_Packet *packet, FNET_Context context) override; + HP_RetCode HandlePacket(FNET_Packet *packet, FNET_Context context) override; }; @@ -222,7 +212,7 @@ private: std::unique_ptr<search::grouping::MergingManager> _groupMerger; FastS_DataSetCollection *_dsc; // owner keeps this alive FastS_FNET_DataSet *_dataset; - bool _datasetActiveCostRef; + bool _datasetActiveCostRef; std::vector<FastS_FNET_SearchNode> _nodes; bool _nodesConnected; @@ -232,11 +222,9 @@ private: FNETMode _FNET_mode; uint32_t _pendingQueries; // # nodes with query left - uint32_t _goodQueries; // # queries good uint32_t _pendingDocsums; // # docsums left uint32_t _pendingDocsumNodes; // # nodes with docsums left uint32_t _requestedDocsums; // # docsums requested - uint32_t _goodDocsums; // # docsums good uint32_t _queryNodes; // #nodes with query uint32_t _queryNodesTimedOut; // #nodes with query timeout uint32_t _docsumNodes; // #nodes with docsums @@ -260,13 +248,12 @@ private: typedef std::vector<std::pair<FastS_EngineBase *, FastS_FNET_SearchNode *>> EngineNodeMap; void connectNodes(const EngineNodeMap & engines); - void AllocNodes(); + void reallocNodes(size_t numParts); void ConnectQueryNodes(); void ConnectEstimateNodes(); void connectSearchPath(const vespalib::string &spec); void connectSearchPath(const fdispatch::SearchPath::Element &elem, - const vespalib::string &spec, - uint32_t dispatchLevel); + const vespalib::string &spec, uint32_t dispatchLevel); void ConnectDocsumNodes(bool ignoreRow); uint32_t getNextFixedRow(); uint32_t getFixedRowCandidate(); @@ -283,9 +270,7 @@ private: FastS_FNET_SearchNode * getNode(size_t i) { return &_nodes[i]; } public: - FastS_FNET_Search(FastS_DataSetCollection *dsc, - FastS_FNET_DataSet *dataset, - FastS_TimeKeeper *timeKeeper); + FastS_FNET_Search(FastS_DataSetCollection *dsc, FastS_FNET_DataSet *dataset, FastS_TimeKeeper *timeKeeper); virtual ~FastS_FNET_Search(); void GotQueryResult(FastS_FNET_SearchNode *node, FS4Packet_QUERYRESULTX *qrx); @@ -306,12 +291,12 @@ public: // *** API methods -- BEGIN *** - virtual FastS_SearchInfo *GetSearchInfo() override { return _util.GetSearchInfo(); } + FastS_SearchInfo *GetSearchInfo() override { return _util.GetSearchInfo(); } - virtual RetCode Search(uint32_t searchOffset, uint32_t maxhits, uint32_t minhits = 0) override; - virtual RetCode ProcessQueryDone() override; - virtual RetCode GetDocsums(const FastS_hitresult *hits, uint32_t hitcnt) override; - virtual RetCode ProcessDocsumsDone() override; + RetCode Search(uint32_t searchOffset, uint32_t maxhits, uint32_t minhits = 0) override; + RetCode ProcessQueryDone() override; + RetCode GetDocsums(const FastS_hitresult *hits, uint32_t hitcnt) override; + RetCode ProcessDocsumsDone() override; // *** API methods -- END *** @@ -345,24 +330,16 @@ public: void adjustQueryTimeout(); void adjustDocsumTimeout(); - uint32_t getGoodQueries() const { return _goodQueries; } uint32_t getRequestedQueries() const { return _queryNodes; } uint32_t getPendingQueries() const { return _pendingQueries; } uint32_t getDoneQueries() const { return getRequestedQueries() - getPendingQueries(); } - uint32_t getBadQueries() const { - return getDoneQueries() - getGoodQueries(); - } - uint32_t getGoodDocsums() const { return _goodDocsums; } uint32_t getRequestedDocsums() const { return _requestedDocsums; } uint32_t getPendingDocsums() const { return _pendingDocsums; } uint32_t getDoneDocsums() const { return getRequestedDocsums() - getPendingDocsums(); } - uint32_t getBadDocsums() const { - return getDoneDocsums() - getGoodDocsums(); - } FNET_Packet::UP setupQueryPacket(uint32_t hitsPerNode, uint32_t qflags, @@ -377,16 +354,14 @@ private: FastS_FNET_Search _search; public: - FastS_Sync_FNET_Search(FastS_DataSetCollection *dsc, - FastS_FNET_DataSet *dataset, - FastS_TimeKeeper *timeKeeper) : + FastS_Sync_FNET_Search(FastS_DataSetCollection *dsc, FastS_FNET_DataSet *dataset, FastS_TimeKeeper *timeKeeper) : FastS_SyncSearchAdapter(&_search), _search(dsc, dataset, timeKeeper) { - _search.SetAsyncArgs(this, FastS_SearchContext()); + _search.SetAsyncArgs(this); } - virtual ~FastS_Sync_FNET_Search(); - virtual void Free() override { delete this; } + ~FastS_Sync_FNET_Search() override; + void Free() override { delete this; } }; //----------------------------------------------------------------- diff --git a/searchcore/src/vespa/searchcore/fdispatch/search/plain_dataset.cpp b/searchcore/src/vespa/searchcore/fdispatch/search/plain_dataset.cpp index aa1a783a7be..b48f1abfb51 100644 --- a/searchcore/src/vespa/searchcore/fdispatch/search/plain_dataset.cpp +++ b/searchcore/src/vespa/searchcore/fdispatch/search/plain_dataset.cpp @@ -18,7 +18,7 @@ static inline int imax(int a, int b) { return (a > b) ? a : b; } //-------------------------------------------------------------------------- FastS_PartitionMap::Partition::Partition() - : _engines(NULL), + : _engines(nullptr), _maxnodesNow(0), _maxnodesSinceReload(0), _nodes(0), @@ -31,7 +31,7 @@ FastS_PartitionMap::Partition::Partition() FastS_PartitionMap::Partition::~Partition() { - FastS_assert(_engines == NULL); + FastS_assert(_engines == nullptr); FastS_assert(_nodes == 0); FastS_assert(_parts == 0); } @@ -39,7 +39,7 @@ FastS_PartitionMap::Partition::~Partition() //-------------------------------------------------------------------------- FastS_PartitionMap::FastS_PartitionMap(FastS_DataSetDesc *desc) - : _partitions(NULL), + : _partitions(nullptr), _partBits(desc->GetPartBits()), _rowBits(desc->GetRowBits()), _num_partitions(desc->GetNumParts()), @@ -64,13 +64,13 @@ FastS_PartitionMap::FastS_PartitionMap(FastS_DataSetDesc *desc) if (_num_partitions > 0) { _partitions = new Partition[_num_partitions]; - FastS_assert(_partitions != NULL); + FastS_assert(_partitions != nullptr); } - for (FastS_EngineDesc *curr = desc->GetEngineList(); curr != NULL; curr = curr->GetNext()) { + for (FastS_EngineDesc *curr = desc->GetEngineList(); curr != nullptr; curr = curr->GetNext()) { _maxRows = std::max(_maxRows, curr->GetConfRowID()); } _numPartitions = std::vector<uint32_t>(getNumRows(), 0); - for (FastS_EngineDesc *curr = desc->GetEngineList(); curr != NULL; curr = curr->GetNext()) { + for (FastS_EngineDesc *curr = desc->GetEngineList(); curr != nullptr; curr = curr->GetNext()) { size_t rowId(curr->GetConfRowID()); _numPartitions[rowId] = std::max(_numPartitions[rowId], curr->GetConfPartID()+1); } @@ -89,7 +89,7 @@ FastS_PartitionMap::RecalcPartCnt(uint32_t partid) uint32_t maxparts = 0; uint32_t parts = 0; for (FastS_EngineBase * engine = _partitions[partid]._engines; - engine != NULL; engine = engine->_nextpart) { + engine != nullptr; engine = engine->_nextpart) { maxparts = imax(engine->_reported._maxParts, maxparts); parts = imax(engine->_reported._actParts, parts); } @@ -112,11 +112,11 @@ FastS_PartitionMap::LinkIn(FastS_EngineBase *engine) uint32_t partid = engine->_partid - _first_partition; FastS_assert(partid < GetSize()); - FastS_assert(engine->_nextpart == NULL); - FastS_assert(engine->_prevpart == NULL); + FastS_assert(engine->_nextpart == nullptr); + FastS_assert(engine->_prevpart == nullptr); FastS_PartitionMap::Partition & part = _partitions[partid]; engine->_nextpart = part._engines; - if (engine->_nextpart != NULL) + if (engine->_nextpart != nullptr) engine->_nextpart->_prevpart = engine; part._engines = engine; part._maxnodesNow += engine->_reported._maxNodes; @@ -144,9 +144,9 @@ FastS_PartitionMap::LinkOut(FastS_EngineBase *engine) uint32_t partid = engine->_partid - _first_partition; FastS_assert(partid < GetSize()); - if (engine->_nextpart != NULL) + if (engine->_nextpart != nullptr) engine->_nextpart->_prevpart = engine->_prevpart; - if (engine->_prevpart != NULL) + if (engine->_prevpart != nullptr) engine->_prevpart->_nextpart = engine->_nextpart; if (_partitions[partid]._engines == engine) _partitions[partid]._engines = engine->_nextpart; @@ -159,8 +159,8 @@ FastS_PartitionMap::LinkOut(FastS_EngineBase *engine) _partitions[partid]._parts <= engine->_reported._actParts) RecalcPartCnt(partid); - engine->_nextpart = NULL; - engine->_prevpart = NULL; + engine->_nextpart = nullptr; + engine->_prevpart = nullptr; } //-------------------------------------------------------------------------- @@ -188,7 +188,7 @@ FastS_PlainDataSet::ExtractEngine() _enginesArray.pop_back(); return ret; } else { - return NULL; + return nullptr; } } @@ -221,7 +221,7 @@ FastS_PlainDataSet::FastS_PlainDataSet(FastS_AppContext *appCtx, const char *hostname = vespalib::HostName::get().c_str(); unsigned const char *p = reinterpret_cast<unsigned const char *>(hostname); - if (p != NULL) { + if (p != nullptr) { while (*p != '\0') { seed = (seed << 7) + *p + (seed >> 25); p++; @@ -233,10 +233,7 @@ FastS_PlainDataSet::FastS_PlainDataSet(FastS_AppContext *appCtx, } -FastS_PlainDataSet::~FastS_PlainDataSet() -{ -} - +FastS_PlainDataSet::~FastS_PlainDataSet() = default; void FastS_PlainDataSet::UpdateMaxHitsPerNodeLog(bool incomplete, bool fuzzy) @@ -317,11 +314,11 @@ FastS_EngineBase * FastS_PlainDataSet::getPartition(const std::unique_lock<std::mutex> &dsGuard, uint32_t partindex, uint32_t rowid) { (void) dsGuard; - FastS_EngineBase* ret = NULL; + FastS_EngineBase* ret = nullptr; if (IsValidPartIndex_HasLock(partindex)) { for (FastS_EngineBase* iter = _partMap._partitions[partindex]._engines; - iter != NULL && ret == NULL; + iter != nullptr && ret == nullptr; iter = iter->_nextpart) { // NB: cost race condition @@ -334,7 +331,7 @@ FastS_PlainDataSet::getPartition(const std::unique_lock<std::mutex> &dsGuard, ui } } - if (ret != NULL) { + if (ret != nullptr) { ret->AddCost(); } return ret; @@ -347,7 +344,7 @@ FastS_PlainDataSet::countNodesUpInRow_HasLock(uint32_t rowid) const size_t numParts = _partMap.GetSize(); for (size_t partindex = 0; partindex < numParts; ++partindex) { for (FastS_EngineBase* iter = _partMap._partitions[partindex]._engines; - iter != NULL; + iter != nullptr; iter = iter->_nextpart) { if (!iter->IsRealBad() && @@ -366,13 +363,13 @@ FastS_EngineBase * FastS_PlainDataSet::getPartition(const std::unique_lock<std::mutex> &dsGuard, uint32_t partindex) { (void) dsGuard; - FastS_EngineBase* ret = NULL; + FastS_EngineBase* ret = nullptr; unsigned int oldCount = 1; unsigned int engineCount = 0; if (IsValidPartIndex_HasLock(partindex)) { for (FastS_EngineBase* iter = _partMap._partitions[partindex]._engines; - iter != NULL; + iter != nullptr; iter = iter->_nextpart) { // NB: cost race condition @@ -382,16 +379,16 @@ FastS_PlainDataSet::getPartition(const std::unique_lock<std::mutex> &dsGuard, ui EngineDocStampOK(iter->_reported._docstamp)) { engineCount++; - if (ret == NULL || UseNewEngine(ret, iter, &oldCount)) + if (ret == nullptr || UseNewEngine(ret, iter, &oldCount)) ret = iter; } } } if (engineCount < getMPP()) { - ret = NULL; + ret = nullptr; } - if (ret != NULL) { + if (ret != nullptr) { ret->AddCost(); } return ret; @@ -401,18 +398,18 @@ FastS_EngineBase * FastS_PlainDataSet::getPartitionMLD(const std::unique_lock<std::mutex> &dsGuard, uint32_t partindex, bool mld) { (void) dsGuard; - FastS_EngineBase* ret = NULL; + FastS_EngineBase* ret = nullptr; unsigned int oldCount = 1; if (partindex < _partMap._num_partitions) { FastS_EngineBase* iter; - for (iter = _partMap._partitions[partindex]._engines; iter != NULL; iter = iter->_nextpart) { + for (iter = _partMap._partitions[partindex]._engines; iter != nullptr; iter = iter->_nextpart) { // NB: cost race condition if (!iter->IsRealBad() && iter->_reported._mld == mld && (iter->_config._unitrefcost > 0) && EngineDocStampOK(iter->_reported._docstamp) && - (ret == NULL || UseNewEngine(ret, iter, &oldCount))) + (ret == nullptr || UseNewEngine(ret, iter, &oldCount))) { ret = iter; } @@ -420,7 +417,7 @@ FastS_PlainDataSet::getPartitionMLD(const std::unique_lock<std::mutex> &dsGuard, } else { LOG(error, "Couldn't fetch partition data: Partition ID too big, partindex=%x _partMap._num_partitions=%x", partindex, _partMap._num_partitions); } - if (ret != NULL) { + if (ret != nullptr) { ret->AddCost(); } return ret; @@ -430,18 +427,18 @@ FastS_EngineBase * FastS_PlainDataSet::getPartitionMLD(const std::unique_lock<std::mutex> &dsGuard, uint32_t partindex, bool mld, uint32_t rowid) { (void) dsGuard; - FastS_EngineBase* ret = NULL; + FastS_EngineBase* ret = nullptr; unsigned int oldCount = 1; if (partindex < _partMap._num_partitions) { FastS_EngineBase* iter; - for (iter = _partMap._partitions[partindex]._engines; iter != NULL; iter = iter->_nextpart) { + for (iter = _partMap._partitions[partindex]._engines; iter != nullptr; iter = iter->_nextpart) { // NB: cost race condition if (!iter->IsRealBad() && (iter->_reported._mld == mld) && (iter->_config._confRowID == rowid) && EngineDocStampOK(iter->_reported._docstamp) && - (ret == NULL || UseNewEngine(ret, iter, &oldCount))) + (ret == nullptr || UseNewEngine(ret, iter, &oldCount))) { ret = iter; } @@ -449,29 +446,12 @@ FastS_PlainDataSet::getPartitionMLD(const std::unique_lock<std::mutex> &dsGuard, } else { LOG(error, "Couldn't fetch partition data: Partition ID too big, partindex=%x _partMap._num_partitions=%x", partindex, _partMap._num_partitions); } - if (ret != NULL) { + if (ret != nullptr) { ret->AddCost(); } return ret; } - -std::vector<FastS_EngineBase *> -FastS_PlainDataSet::getPartEngines(uint32_t partition) -{ - typedef FastS_EngineBase EB; - typedef std::vector<EB *> EBV; - EBV partEngines; - { - auto dsGuard(getDsGuard()); - for (FastS_EngineBase *iter = _partMap._partitions[partition]._engines; iter != NULL; iter = iter->_nextpart) { - partEngines.push_back(iter); - } - } - return partEngines; -} - - void FastS_PlainDataSet::LinkInPart_HasLock(FastS_EngineBase *engine) { @@ -506,12 +486,12 @@ FastS_PlainDataSet::CalculateQueueLens_HasLock(uint32_t &dispatchnodes) dispatchnodes = 1; for (partindex = 0; partindex < _partMap._num_partitions ; partindex++) { eng = _partMap._partitions[partindex]._engines; - if (eng != NULL) { + if (eng != nullptr) { pqueueLen = eng->GetQueueLen(); pdispatchnodes = eng->GetDispatchers(); dupnodes = 1; eng = eng->_nextpart; - while (eng != NULL) { + while (eng != nullptr) { equeueLen = eng->GetQueueLen(); if (equeueLen < pqueueLen) pqueueLen = equeueLen; diff --git a/searchcore/src/vespa/searchcore/fdispatch/search/plain_dataset.h b/searchcore/src/vespa/searchcore/fdispatch/search/plain_dataset.h index ab50efeb40c..8ce6b3adb75 100644 --- a/searchcore/src/vespa/searchcore/fdispatch/search/plain_dataset.h +++ b/searchcore/src/vespa/searchcore/fdispatch/search/plain_dataset.h @@ -138,7 +138,7 @@ protected: bool IsValidPartIndex_HasLock(uint32_t partindex); public: FastS_PlainDataSet(FastS_AppContext *appCtx, FastS_DataSetDesc *desc); - virtual ~FastS_PlainDataSet(); + ~FastS_PlainDataSet() override; bool useFixedRowDistribution() const { return _queryDistributionMode == FastS_DataSetDesc::QueryDistributionMode::FIXEDROW; @@ -179,18 +179,15 @@ public: FastS_EngineBase * getPartitionMLD(const std::unique_lock<std::mutex> &dsGuard, uint32_t partid, bool mld); FastS_EngineBase * getPartitionMLD(const std::unique_lock<std::mutex> &dsGuard, uint32_t partid, bool mld, uint32_t rowid); - std::vector<FastS_EngineBase *> getPartEngines(uint32_t partition); - void LinkInPart_HasLock(FastS_EngineBase *engine); void LinkOutPart_HasLock(FastS_EngineBase *engine); - virtual ChildInfo getChildInfo() const override; + ChildInfo getChildInfo() const override; uint32_t getMPP() const { return _partMap._mpp; } double getMonitorInterval() const { return _monitorInterval; } double getHigherCoverageMaxSearchWait() const { return _higherCoverageMaxSearchWait; } double getHigherCoverageMinSearchWait() const { return _higherCoverageMinSearchWait; } - double getHigherCoverageBaseSearchWait() const { return _higherCoverageBaseSearchWait; } double getMinimalSearchCoverage() const { return _minimalSearchCoverage; } double getHigherCoverageMaxDocSumWait() const { return _higherCoverageMaxDocSumWait; } double getHigherCoverageMinDocSumWait() const { return _higherCoverageMinDocSumWait; } @@ -199,13 +196,13 @@ public: // API //---- - virtual uint32_t CalculateQueueLens_HasLock(uint32_t &dispatchnodes) override; - virtual bool AreEnginesReady() override; + uint32_t CalculateQueueLens_HasLock(uint32_t &dispatchnodes) override; + bool AreEnginesReady() override; virtual void Ping(); // Downcast //--------- - virtual FastS_PlainDataSet * GetPlainDataSet() override { return this; } + FastS_PlainDataSet * GetPlainDataSet() override { return this; } template <class FUN> FUN ForEachEngine(FUN fun) { @@ -216,6 +213,4 @@ public: } static bool EngineDocStampOK(time_t haveDocStamp) { return (haveDocStamp != 0); } - - void UseDeterministicQueryDistribution(bool); }; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.cpp index 2feca5fc0c7..198f2525244 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.cpp @@ -6,7 +6,9 @@ #include <vespa/searchlib/attribute/stringbase.h> #include <vespa/searchlib/attribute/integerbase.h> #include <vespa/searchlib/attribute/floatbase.h> +#include <vespa/searchlib/attribute/iattributemanager.h> #include <vespa/searchlib/tensor/i_tensor_attribute.h> +#include <vespa/searchcommon/attribute/iattributecontext.h> #include <vespa/eval/tensor/tensor.h> #include <vespa/eval/tensor/serialization/typed_binary_format.h> #include <vespa/vespalib/objects/nbostream.h> @@ -20,8 +22,7 @@ using search::attribute::IAttributeContext; using search::attribute::IAttributeVector; using search::attribute::BasicType; -namespace search { -namespace docsummary { +namespace search::docsummary { ResType inferType(const IAttributeVector & vec) { ResType retval; @@ -155,13 +156,13 @@ SingleAttrDFW::insertField(uint32_t docid, case RES_FEATUREDATA: case RES_LONG_STRING: case RES_STRING: { - s = v.getString(docid, NULL, 0); // no need to pass in a buffer, this attribute has a string storage. + s = v.getString(docid, nullptr, 0); // no need to pass in a buffer, this attribute has a string storage. target.insertString(vespalib::Memory(s)); break; } case RES_LONG_DATA: case RES_DATA: { - s = v.getString(docid, NULL, 0); // no need to pass in a buffer, this attribute has a string storage. + s = v.getString(docid, nullptr, 0); // no need to pass in a buffer, this attribute has a string storage. target.insertData(vespalib::Memory(s)); break; } @@ -265,9 +266,9 @@ AttributeDFWFactory::create(IAttributeManager & vecMan, const char *vecName) { IAttributeContext::UP ctx = vecMan.createContext(); const IAttributeVector * vec = ctx->getAttribute(vecName); - if (vec == NULL) { + if (vec == nullptr) { LOG(warning, "No valid attribute vector found: %s", vecName); - return NULL; + return nullptr; } if (vec->hasMultiValue()) { return new MultiAttrDFW(vec->getName()); @@ -277,4 +278,3 @@ AttributeDFWFactory::create(IAttributeManager & vecMan, const char *vecName) } } -} diff --git a/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.h b/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.h index c661be635c8..643170663b8 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.h @@ -2,11 +2,11 @@ #pragma once -#include <vespa/searchlib/attribute/iattributemanager.h> #include "docsumfieldwriter.h" -namespace search { -namespace docsummary { +namespace search::attribute { class IAttributeVector; } + +namespace search::docsummary { class AttrDFW : public IDocsumFieldWriter { @@ -14,12 +14,11 @@ private: vespalib::string _attrName; protected: const attribute::IAttributeVector & vec(const GetDocsumsState & s) const; - virtual const vespalib::string & getAttributeName() const override { return _attrName; } + const vespalib::string & getAttributeName() const override { return _attrName; } public: AttrDFW(const vespalib::string & attrName); - virtual bool IsGenerated() const override { return true; } + bool IsGenerated() const override { return true; } }; } -} diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp index d8b059b31ac..83637bfc7cc 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp @@ -11,8 +11,7 @@ #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/util/exceptions.h> -namespace search { -namespace docsummary { +namespace search::docsummary { using vespalib::IllegalArgumentException; using vespalib::make_string; @@ -119,6 +118,4 @@ DynamicDocsumConfig::configure(const vespa::config::search::SummarymapConfig &cf } } - -} } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.h b/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.h index 57c82c97a93..21015e21459 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.h @@ -4,8 +4,7 @@ #include <vespa/config-summarymap.h> -namespace search { -namespace docsummary { +namespace search::docsummary { class IDocsumEnvironment; class DynamicDocsumWriter; @@ -36,5 +35,4 @@ private: }; } -} diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.h b/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.h index 5e01d698fb6..4ffed79043e 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumstate.h @@ -13,13 +13,12 @@ namespace juniper { class Result; } -namespace search { -namespace common { class Location; } -namespace attribute { +namespace search::common { class Location; } +namespace search::attribute { class IAttributeContext; class IAttributeVector; } -namespace docsummary { +namespace search::docsummary { class GetDocsumsState; class IDocsumEnvironment; @@ -90,5 +89,4 @@ public: }; } -} diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.cpp index 5798636b1a8..bf660b1319b 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.cpp @@ -44,7 +44,7 @@ DynamicDocsumWriter::resolveOutputClass(vespalib::stringref summaryClass) const if (id != ResultConfig::NoClassID()) { const ResultClass *oC = _resultConfig->LookupResultClass(id); - if (oC == NULL) { + if (oC == nullptr) { LOG(warning, "Illegal docsum class requested: %d, using empty docsum for documents", id); result.mustSkip = true; } else { @@ -65,11 +65,11 @@ void DynamicDocsumWriter::resolveInputClass(ResolveClassInfo &rci, uint32_t id) const { rci.inputClass = _resultConfig->LookupResultClass(id); - if (rci.inputClass == NULL) { + if (rci.inputClass == nullptr) { rci.mustSkip = true; return; } - if (rci.outputClass == NULL) { + if (rci.outputClass == nullptr) { LOG_ASSERT(rci.outputClassId == ResultConfig::NoClassID()); rci.outputClassId = id; rci.outputClass = rci.inputClass; @@ -147,7 +147,7 @@ DynamicDocsumWriter::insertDocsum(const ResolveClassInfo & rci, const Memory field_name(resCfg->_bindname.data(), resCfg->_bindname.size()); ObjectInserter inserter(docsum, field_name); - writer->insertField(docid, NULL, state, resCfg->_type, inserter); + writer->insertField(docid, nullptr, state, resCfg->_type, inserter); } } } else { @@ -166,18 +166,20 @@ DynamicDocsumWriter::insertDocsum(const ResolveClassInfo & rci, IDocsumFieldWriter *writer = _overrideTable[outCfg->_enumValue]; const Memory field_name(outCfg->_bindname.data(), outCfg->_bindname.size()); ObjectInserter inserter(docsum, field_name); - if (writer != NULL) { + if (writer != nullptr) { + //TODO: Vespa 7 Need to add test for writer->isDefaultValue writer->insertField(docid, &gres, state, outCfg->_type, inserter); } else { + //TODO: Vespa 7 Need to add similar test as writer->isDefaultValue if (rci.inputClass == rci.outputClass) { convertEntry(state, outCfg, gres.GetEntry(i), inserter, slime); } else { int inIdx = rci.inputClass->GetIndexFromEnumValue(outCfg->_enumValue); const ResConfigEntry *inCfg = rci.inputClass->GetEntry(inIdx); - if (inCfg != NULL && inCfg->_type == outCfg->_type) { + if (inCfg != nullptr && inCfg->_type == outCfg->_type) { // copy field const ResEntry *entry = gres.GetEntry(inIdx); - LOG_ASSERT(entry != NULL); + LOG_ASSERT(entry != nullptr); convertEntry(state, outCfg, entry, inserter, slime); } } @@ -186,17 +188,16 @@ DynamicDocsumWriter::insertDocsum(const ResolveClassInfo & rci, } } - DynamicDocsumWriter::DynamicDocsumWriter( ResultConfig *config, KeywordExtractor *extractor) : _resultConfig(config), _keywordExtractor(extractor), _defaultOutputClass(ResultConfig::NoClassID()), _numClasses(config->GetNumResultClasses()), _numEnumValues(config->GetFieldNameEnum().GetNumEntries()), - _classInfoTable(NULL), - _overrideTable(NULL) + _classInfoTable(nullptr), + _overrideTable(nullptr) { - LOG_ASSERT(config != NULL); + LOG_ASSERT(config != nullptr); _classInfoTable = new ResultClass::DynamicInfo[_numClasses]; _overrideTable = new IDocsumFieldWriter*[_numEnumValues]; @@ -209,7 +210,7 @@ DynamicDocsumWriter::DynamicDocsumWriter( ResultConfig *config, KeywordExtractor LOG_ASSERT(i == _numClasses); for (i = 0; i < _numEnumValues; i++) - _overrideTable[i] = NULL; + _overrideTable[i] = nullptr; } @@ -231,10 +232,10 @@ DynamicDocsumWriter::SetDefaultOutputClass(uint32_t classID) { const ResultClass *resClass = _resultConfig->LookupResultClass(classID); - if (resClass == NULL || + if (resClass == nullptr || _defaultOutputClass != ResultConfig::NoClassID()) { - if (resClass == NULL) { + if (resClass == nullptr) { LOG(warning, "cannot set default output docsum class to %d; class not defined", classID); } else if (_defaultOutputClass != ResultConfig::NoClassID()) { LOG(warning, "cannot set default output docsum class to %d; value already set", classID); @@ -252,12 +253,12 @@ DynamicDocsumWriter::Override(const char *fieldName, IDocsumFieldWriter *writer) uint32_t fieldEnumValue = _resultConfig->GetFieldNameEnum().Lookup(fieldName); if (fieldEnumValue >= _numEnumValues || - _overrideTable[fieldEnumValue] != NULL) + _overrideTable[fieldEnumValue] != nullptr) { if (fieldEnumValue >= _numEnumValues) { LOG(warning, "cannot override docsum field '%s'; undefined field name", fieldName); - } else if (_overrideTable[fieldEnumValue] != NULL) { + } else if (_overrideTable[fieldEnumValue] != nullptr) { LOG(warning, "cannot override docsum field '%s'; already overridden", fieldName); } delete writer; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.h b/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.h index 46caa26e60b..6ef21a71e74 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumwriter.h @@ -29,22 +29,16 @@ public: ResolveClassInfo() : mustSkip(false), allGenerated(false), outputClassId(ResultConfig::NoClassID()), - outputClass(NULL), outputClassInfo(NULL), inputClass(NULL) + outputClass(nullptr), outputClassInfo(nullptr), inputClass(nullptr) { } }; virtual ~IDocsumWriter() {} virtual void InitState(IAttributeManager & attrMan, GetDocsumsState *state) = 0; - virtual uint32_t WriteDocsum(uint32_t docid, - GetDocsumsState *state, - IDocsumStore *docinfos, - search::RawBuf *target) = 0; - virtual void insertDocsum(const ResolveClassInfo & rci, - uint32_t docid, - GetDocsumsState *state, - IDocsumStore *docinfos, - vespalib::Slime & slime, - vespalib::slime::Inserter & target) = 0; + virtual uint32_t WriteDocsum(uint32_t docid, GetDocsumsState *state, + IDocsumStore *docinfos, search::RawBuf *target) = 0; + virtual void insertDocsum(const ResolveClassInfo & rci, uint32_t docid, GetDocsumsState *state, + IDocsumStore *docinfos, vespalib::Slime & slime, vespalib::slime::Inserter & target) = 0; virtual ResolveClassInfo resolveClassInfo(vespalib::stringref outputClassName, uint32_t inputClassId) const = 0; static uint32_t slime2RawBuf(const vespalib::Slime & slime, RawBuf & buf); @@ -55,11 +49,6 @@ public: class DynamicDocsumWriter : public IDocsumWriter { private: - DynamicDocsumWriter(const DynamicDocsumWriter &); - DynamicDocsumWriter& operator=(const DynamicDocsumWriter &); - - -private: ResultConfig *_resultConfig; KeywordExtractor *_keywordExtractor; uint32_t _defaultOutputClass; @@ -68,42 +57,26 @@ private: ResultClass::DynamicInfo *_classInfoTable; IDocsumFieldWriter **_overrideTable; - uint32_t WriteClassID(uint32_t classID, search::RawBuf *target); - - uint32_t GenerateDocsum(uint32_t docid, - GetDocsumsState *state, - const ResultClass *outputClass, - search::RawBuf *target); - - uint32_t RepackDocsum(GeneralResult *gres, - GetDocsumsState *state, - const ResultClass *outputClass, - search::RawBuf *target); - void resolveInputClass(ResolveClassInfo &rci, uint32_t id) const; ResolveClassInfo resolveOutputClass(vespalib::stringref outputClassName) const; public: DynamicDocsumWriter(ResultConfig *config, KeywordExtractor *extractor); - virtual ~DynamicDocsumWriter(); + DynamicDocsumWriter(const DynamicDocsumWriter &) = delete; + DynamicDocsumWriter& operator=(const DynamicDocsumWriter &) = delete; + ~DynamicDocsumWriter() override; ResultConfig *GetResultConfig() { return _resultConfig; } bool SetDefaultOutputClass(uint32_t classID); bool Override(const char *fieldName, IDocsumFieldWriter *writer); void InitState(IAttributeManager & attrMan, GetDocsumsState *state) override; - uint32_t WriteDocsum(uint32_t docid, - GetDocsumsState *state, - IDocsumStore *docinfos, - search::RawBuf *target) override; - - void insertDocsum(const ResolveClassInfo & outputClassInfo, - uint32_t docid, - GetDocsumsState *state, - IDocsumStore *docinfos, - vespalib::Slime & slime, - vespalib::slime::Inserter & target) override; + uint32_t WriteDocsum(uint32_t docid, GetDocsumsState *state, + IDocsumStore *docinfos, search::RawBuf *target) override; + + void insertDocsum(const ResolveClassInfo & outputClassInfo, uint32_t docid, GetDocsumsState *state, + IDocsumStore *docinfos, vespalib::Slime & slime, vespalib::slime::Inserter & target) override; ResolveClassInfo resolveClassInfo(vespalib::stringref outputClassName, uint32_t inputClassId) const override; }; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/geoposdfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/geoposdfw.cpp index fdb5d436a73..bf010172fa9 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/geoposdfw.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/geoposdfw.cpp @@ -2,6 +2,7 @@ #include "geoposdfw.h" #include <vespa/searchlib/common/documentlocations.h> +#include <vespa/searchlib/attribute/iattributemanager.h> #include <vespa/searchlib/common/location.h> #include <vespa/vespalib/util/jsonwriter.h> #include <vespa/vespalib/data/slime/cursor.h> @@ -88,7 +89,7 @@ GeoPositionDFW::create(const char *attribute_name, IAttributeManager *attribute_manager) { GeoPositionDFW::UP ret; - if (attribute_manager != NULL) { + if (attribute_manager != nullptr) { if (!attribute_name) { LOG(warning, "create: missing attribute name '%p'", attribute_name); return ret; @@ -108,5 +109,4 @@ GeoPositionDFW::create(const char *attribute_name, return ret; } - } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/geoposdfw.h b/searchsummary/src/vespa/searchsummary/docsummary/geoposdfw.h index b85f916e384..8f630cde3af 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/geoposdfw.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/geoposdfw.h @@ -2,10 +2,9 @@ #pragma once -#include <vespa/searchsummary/docsummary/attributedfw.h> +#include "attributedfw.h" -namespace search { -namespace docsummary { +namespace search::docsummary { /** * This is the docsum field writer used to extract the position (as a string) from a zcurve attribute @@ -21,5 +20,4 @@ public: }; } -} diff --git a/searchsummary/src/vespa/searchsummary/docsummary/itokenizer.h b/searchsummary/src/vespa/searchsummary/docsummary/itokenizer.h index 33004093025..62f2510c17b 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/itokenizer.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/itokenizer.h @@ -4,8 +4,7 @@ #include <vespa/vespalib/stllike/string.h> -namespace search { -namespace docsummary { +namespace search::docsummary { /** * Interface for a tokenizer. @@ -66,4 +65,4 @@ public: }; } -} + diff --git a/searchsummary/src/vespa/searchsummary/docsummary/juniperdfw.h b/searchsummary/src/vespa/searchsummary/docsummary/juniperdfw.h index 3c08132b02a..f6218d563ed 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/juniperdfw.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/juniperdfw.h @@ -2,15 +2,14 @@ #pragma once +#include "urlresult.h" +#include "resultconfig.h" +#include "docsumfieldwriter.h" #include <vespa/searchlib/util/rawbuf.h> -#include <vespa/searchsummary/docsummary/urlresult.h> -#include <vespa/searchsummary/docsummary/resultconfig.h> #include <vespa/vespalib/data/slime/inserter.h> -#include "docsumfieldwriter.h" #include <vespa/juniper/rpinterface.h> -namespace search { -namespace docsummary { +namespace search::docsummary { class JuniperDFW : public IDocsumFieldWriter { @@ -29,7 +28,7 @@ protected: uint32_t _langFieldEnumValue; juniper::Juniper *_juniper; private: - virtual bool IsGenerated() const override { return false; } + bool IsGenerated() const override { return false; } JuniperDFW(const JuniperDFW &); JuniperDFW & operator=(const JuniperDFW &); }; @@ -38,11 +37,8 @@ private: class JuniperTeaserDFW : public JuniperDFW { public: - virtual bool Init( - const char *fieldName, - const char *langFieldName, - const ResultConfig & config, - const char *inputField) override; + bool Init(const char *fieldName, const char *langFieldName, + const ResultConfig & config, const char *inputField) override; protected: JuniperTeaserDFW(juniper::Juniper * juniper) : JuniperDFW(juniper) { } }; @@ -57,13 +53,9 @@ public: GeneralResult *gres, GetDocsumsState *state); - virtual void insertField(uint32_t docid, - GeneralResult *gres, - GetDocsumsState *state, - ResType type, - vespalib::slime::Inserter &target) override; + void insertField(uint32_t docid, GeneralResult *gres, GetDocsumsState *state, + ResType type, vespalib::slime::Inserter &target) override; }; -} // namespace docsummary -} // namespace search +} diff --git a/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp index c3352830fd6..48e79a5e34c 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.cpp @@ -2,6 +2,7 @@ #include "positionsdfw.h" #include "docsumstate.h" +#include <vespa/searchlib/attribute/iattributemanager.h> #include <vespa/searchlib/common/location.h> #include <vespa/vespalib/stllike/asciistream.h> #include <cmath> @@ -72,11 +73,11 @@ AbsDistanceDFW::insertField(uint32_t docid, GeneralResult *, GetDocsumsState *st const vespalib::string &locationStr = state->_args.getLocation(); if (locationStr.size() > 0) { - if (state->_parsedLocation.get() == NULL) { + if (!state->_parsedLocation) { state->_callback.ParseLocation(state); } - assert(state->_parsedLocation.get() != NULL); - if (state->_parsedLocation->getParseError() == NULL) { + assert(state->_parsedLocation); + if (state->_parsedLocation->getParseError() == nullptr) { forceEmpty = false; } } @@ -178,7 +179,7 @@ PositionsDFW::UP createPositionsDFW(const char *attribute_name, IAttributeManager *attribute_manager) { PositionsDFW::UP ret; - if (attribute_manager != NULL) { + if (attribute_manager != nullptr) { if (!attribute_name) { LOG(debug, "createPositionsDFW: missing attribute name '%p'", attribute_name); return ret; @@ -202,7 +203,7 @@ AbsDistanceDFW::UP createAbsDistanceDFW(const char *attribute_name, IAttributeManager *attribute_manager) { AbsDistanceDFW::UP ret; - if (attribute_manager != NULL) { + if (attribute_manager != nullptr) { if (!attribute_name) { LOG(debug, "createAbsDistanceDFW: missing attribute name '%p'", attribute_name); return ret; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.h b/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.h index b26eb139686..69a7ba3f58f 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/positionsdfw.h @@ -2,10 +2,9 @@ #pragma once -#include <vespa/searchsummary/docsummary/attributedfw.h> +#include "attributedfw.h" -namespace search { -namespace docsummary { +namespace search::docsummary { class AbsDistanceDFW : public AttrDFW { @@ -36,6 +35,4 @@ public: PositionsDFW::UP createPositionsDFW(const char *attribute_name, IAttributeManager *index_man); AbsDistanceDFW::UP createAbsDistanceDFW(const char *attribute_name, IAttributeManager *index_man); -} // namespace docsummary -} // namespace search - +} diff --git a/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.h b/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.h index c406a9f9dee..5229e26475b 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/summaryfeaturesdfw.h @@ -26,7 +26,7 @@ private: public: SummaryFeaturesDFW(); - ~SummaryFeaturesDFW(); + ~SummaryFeaturesDFW() override; void init(IDocsumEnvironment * env); bool IsGenerated() const override { return true; } void insertField(uint32_t docid, GeneralResult *gres, GetDocsumsState *state, diff --git a/searchsummary/src/vespa/searchsummary/docsummary/summaryfieldconverter.h b/searchsummary/src/vespa/searchsummary/docsummary/summaryfieldconverter.h index fdb4d3cc2e7..96db6026e88 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/summaryfieldconverter.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/summaryfieldconverter.h @@ -4,8 +4,7 @@ #include <vespa/document/fieldvalue/fieldvalue.h> -namespace search { -namespace docsummary { +namespace search::docsummary { /** * This class converts a summary field for docsum fetching. @@ -17,5 +16,5 @@ public: convertSummaryField(bool markup, const document::FieldValue &value); }; -} // namespace search::docsummary -} // namespace search +} + diff --git a/searchsummary/src/vespa/searchsummary/docsummary/tokenizer.h b/searchsummary/src/vespa/searchsummary/docsummary/tokenizer.h index e7d6916d452..cd18c503058 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/tokenizer.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/tokenizer.h @@ -34,11 +34,10 @@ public: */ Tokenizer(const char * buf, size_t len); - // Inherit doc - virtual void reset(const char * buf, size_t len) override; - virtual size_t getBufferSize() const override { return _end - _begin; } - virtual bool hasMoreTokens() override; - virtual Token getNextToken() override; + void reset(const char * buf, size_t len) override; + size_t getBufferSize() const override { return _end - _begin; } + bool hasMoreTokens() override; + Token getNextToken() override; }; } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/urlresult.h b/searchsummary/src/vespa/searchsummary/docsummary/urlresult.h index 97e31e47996..4d1fca0992d 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/urlresult.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/urlresult.h @@ -31,9 +31,9 @@ class badurlresult : public urlresult public: badurlresult(); badurlresult(uint32_t partition, uint32_t docid, HitRank metric); - virtual ~badurlresult(); + ~badurlresult() override; - virtual int unpack(const char *buf, const size_t buflen) override; + int unpack(const char *buf, const size_t buflen) override; }; @@ -49,8 +49,7 @@ private: char *_buf; // allocated in same chunk as _entries char *_bufEnd; // first byte after _buf - bool InBuf(void *pt) - { + bool InBuf(void *pt) { return ((char *)pt >= _buf && (char *)pt < _bufEnd); } @@ -69,8 +68,8 @@ public: ResEntry *GetEntry(uint32_t idx); ResEntry *GetEntry(const char *name); ResEntry *GetEntryFromEnumValue(uint32_t val); - virtual bool IsGeneral() const override { return true; } - virtual int unpack(const char *buf, const size_t buflen) override; + bool IsGeneral() const override { return true; } + int unpack(const char *buf, const size_t buflen) override; bool inplaceUnpack(const DocsumStoreValue &value) { if (value.valid()) { @@ -82,3 +81,4 @@ public: }; } + diff --git a/staging_vespalib/src/tests/util/process_memory_stats/process_memory_stats_test.cpp b/staging_vespalib/src/tests/util/process_memory_stats/process_memory_stats_test.cpp index c8a9590eb96..45e75547fb2 100644 --- a/staging_vespalib/src/tests/util/process_memory_stats/process_memory_stats_test.cpp +++ b/staging_vespalib/src/tests/util/process_memory_stats/process_memory_stats_test.cpp @@ -13,6 +13,8 @@ using namespace vespalib; namespace { +constexpr uint64_t SIZE_EPSILON = 4095; + std::string toString(const ProcessMemoryStats &stats) { std::ostringstream os; @@ -27,7 +29,7 @@ std::string toString(const ProcessMemoryStats &stats) TEST("Simple stats") { - ProcessMemoryStats stats(ProcessMemoryStats::create()); + ProcessMemoryStats stats(ProcessMemoryStats::create(SIZE_EPSILON)); std::cout << toString(stats) << std::endl; EXPECT_LESS(0u, stats.getMappedVirt()); EXPECT_LESS(0u, stats.getMappedRss()); @@ -37,7 +39,7 @@ TEST("Simple stats") TEST("grow anonymous memory") { - ProcessMemoryStats stats1(ProcessMemoryStats::create()); + ProcessMemoryStats stats1(ProcessMemoryStats::create(SIZE_EPSILON)); std::cout << toString(stats1) << std::endl; size_t mapLen = 64 * 1024; void *mapAddr = mmap(nullptr, mapLen, PROT_READ | PROT_WRITE, @@ -48,7 +50,7 @@ TEST("grow anonymous memory") EXPECT_LESS_EQUAL(stats1.getAnonymousVirt() + mapLen, stats2.getAnonymousVirt()); memset(mapAddr, 1, mapLen); - ProcessMemoryStats stats3(ProcessMemoryStats::create()); + ProcessMemoryStats stats3(ProcessMemoryStats::create(SIZE_EPSILON)); std::cout << toString(stats3) << std::endl; // Cannot check that resident grows if swap is enabled and system loaded munmap(mapAddr, mapLen); @@ -63,16 +65,16 @@ TEST("grow mapped memory") of.close(); int mapfileFileDescriptor = open("mapfile", O_RDONLY, 0666); EXPECT_LESS_EQUAL(0, mapfileFileDescriptor); - ProcessMemoryStats stats1(ProcessMemoryStats::create()); + ProcessMemoryStats stats1(ProcessMemoryStats::create(SIZE_EPSILON)); std::cout << toString(stats1) << std::endl; void *mapAddr = mmap(nullptr, mapLen, PROT_READ, MAP_SHARED, mapfileFileDescriptor, 0); EXPECT_NOT_EQUAL(reinterpret_cast<void *>(-1), mapAddr); - ProcessMemoryStats stats2(ProcessMemoryStats::create()); + ProcessMemoryStats stats2(ProcessMemoryStats::create(SIZE_EPSILON)); std::cout << toString(stats2) << std::endl; EXPECT_LESS_EQUAL(stats1.getMappedVirt() + mapLen, stats2.getMappedVirt()); EXPECT_EQUAL(0, memcmp(mapAddr, &buf[0], mapLen)); - ProcessMemoryStats stats3(ProcessMemoryStats::create()); + ProcessMemoryStats stats3(ProcessMemoryStats::create(SIZE_EPSILON)); std::cout << toString(stats3) << std::endl; // Cannot check that resident grows if swap is enabled and system loaded munmap(mapAddr, mapLen); diff --git a/staging_vespalib/src/vespa/vespalib/util/process_memory_stats.cpp b/staging_vespalib/src/vespa/vespalib/util/process_memory_stats.cpp index 849ebf6d4fa..b94e35407a1 100644 --- a/staging_vespalib/src/vespa/vespalib/util/process_memory_stats.cpp +++ b/staging_vespalib/src/vespa/vespalib/util/process_memory_stats.cpp @@ -1,11 +1,15 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "process_memory_stats.h" +#include <vespa/vespalib/stllike/asciistream.h> #include <fstream> #include <sstream> -namespace vespalib -{ +#include <vespa/log/log.h> + +LOG_SETUP(".vespalib.util.process_memory_stats"); + +namespace vespalib { namespace { @@ -84,31 +88,8 @@ std::string getLineHeader(const std::string &line) } - -ProcessMemoryStats::ProcessMemoryStats() - : _mapped_virt(0), - _mapped_rss(0), - _anonymous_virt(0), - _anonymous_rss(0), - _mappings_count(0) -{ -} - -ProcessMemoryStats::ProcessMemoryStats(uint64_t mapped_virt, - uint64_t mapped_rss, - uint64_t anonymous_virt, - uint64_t anonymous_rss, - uint64_t mappings_cnt) - : _mapped_virt(mapped_virt), - _mapped_rss(mapped_rss), - _anonymous_virt(anonymous_virt), - _anonymous_rss(anonymous_rss), - _mappings_count(mappings_cnt) -{ -} - ProcessMemoryStats -ProcessMemoryStats::create() +ProcessMemoryStats::createStatsFromSmaps() { ProcessMemoryStats ret; std::ifstream smaps("/proc/self/smaps"); @@ -143,4 +124,76 @@ ProcessMemoryStats::create() return ret; } -} // namespace vespalib + +ProcessMemoryStats::ProcessMemoryStats() + : _mapped_virt(0), + _mapped_rss(0), + _anonymous_virt(0), + _anonymous_rss(0), + _mappings_count(0) +{ +} + +ProcessMemoryStats::ProcessMemoryStats(uint64_t mapped_virt, + uint64_t mapped_rss, + uint64_t anonymous_virt, + uint64_t anonymous_rss, + uint64_t mappings_cnt) + : _mapped_virt(mapped_virt), + _mapped_rss(mapped_rss), + _anonymous_virt(anonymous_virt), + _anonymous_rss(anonymous_rss), + _mappings_count(mappings_cnt) +{ +} + +namespace { + +bool +similar(uint64_t lhs, uint64_t rhs, uint64_t epsilon) +{ + return (lhs < rhs) ? ((rhs - lhs) <= epsilon) : ((lhs - rhs) <= epsilon); +} + +} + +bool +ProcessMemoryStats::similarTo(const ProcessMemoryStats &rhs, uint64_t sizeEpsilon) const +{ + return similar(_mapped_virt, rhs._mapped_virt, sizeEpsilon) && + similar(_mapped_rss, rhs._mapped_rss, sizeEpsilon) && + similar(_anonymous_virt, rhs._anonymous_virt, sizeEpsilon) && + similar(_anonymous_rss, rhs._anonymous_rss, sizeEpsilon) && + (_mappings_count == rhs._mappings_count); +} + +vespalib::string +ProcessMemoryStats::toString() const +{ + vespalib::asciistream stream; + stream << "_mapped_virt=" << _mapped_virt << ", " + << "_mapped_rss=" << _mapped_rss << ", " + << "_anonymous_virt=" << _anonymous_virt << ", " + << "_anonymous_rss=" << _anonymous_rss << ", " + << "_mappings_count=" << _mappings_count; + return stream.str(); +} + +ProcessMemoryStats +ProcessMemoryStats::create(uint64_t sizeEpsilon) +{ + ProcessMemoryStats prevStats = createStatsFromSmaps(); + const size_t NUM_TRIES = 10; + for (size_t i = 0; i < NUM_TRIES; ++i) { + ProcessMemoryStats currStats = createStatsFromSmaps(); + if (prevStats.similarTo(currStats, sizeEpsilon)) { + return prevStats; + } + LOG(info, "create(): Memory stats have changed, trying to read smaps file again: i=%zu, prevStats={%s}, currStats={%s}", + i, prevStats.toString().c_str(), currStats.toString().c_str()); + prevStats = currStats; + } + return prevStats; +} + +} diff --git a/staging_vespalib/src/vespa/vespalib/util/process_memory_stats.h b/staging_vespalib/src/vespa/vespalib/util/process_memory_stats.h index b864a509eaa..fe5062f75cd 100644 --- a/staging_vespalib/src/vespa/vespalib/util/process_memory_stats.h +++ b/staging_vespalib/src/vespa/vespalib/util/process_memory_stats.h @@ -3,6 +3,7 @@ #pragma once #include <cstdint> +#include <vespa/vespalib/stllike/string.h> namespace vespalib { @@ -18,17 +19,27 @@ class ProcessMemoryStats uint64_t _mappings_count; // number of mappings // (limited by sysctl vm.max_map_count) + static ProcessMemoryStats createStatsFromSmaps(); + public: ProcessMemoryStats(); - static ProcessMemoryStats create(); // based on /proc/self/smaps + /** + * Sample memory stats for the current process based on reading the file /proc/self/smaps. + * + * Samples are taken until two consecutive memory stats are similar given the size epsilon. + * This ensures a somewhat consistent memory stats snapshot. + */ + static ProcessMemoryStats create(uint64_t sizeEpsilon = 1 * 1024 * 1024); uint64_t getMappedVirt() const { return _mapped_virt; } uint64_t getMappedRss() const { return _mapped_rss; } uint64_t getAnonymousVirt() const { return _anonymous_virt; } uint64_t getAnonymousRss() const { return _anonymous_rss; } uint64_t getMappingsCount() const { return _mappings_count; } + bool similarTo(const ProcessMemoryStats &rhs, uint64_t sizeEpsilon) const; + vespalib::string toString() const; /** for unit tests only */ ProcessMemoryStats(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t); }; -} // namespace vespalib +} diff --git a/standalone-container/src/main/scala/com/yahoo/container/standalone/StandaloneSubscriberFactory.scala b/standalone-container/src/main/scala/com/yahoo/container/standalone/StandaloneSubscriberFactory.scala index 47219d2893a..99cc8259ab3 100644 --- a/standalone-container/src/main/scala/com/yahoo/container/standalone/StandaloneSubscriberFactory.scala +++ b/standalone-container/src/main/scala/com/yahoo/container/standalone/StandaloneSubscriberFactory.scala @@ -59,7 +59,7 @@ class StandaloneSubscriberFactory(root: VespaModel) extends SubscriberFactory { object StandaloneSubscriberFactory { private def newBuilderInstance(key: ConfigKeyT) = - builderClass(key).newInstance() + builderClass(key).getDeclaredConstructor().newInstance() private def builderClass(key: ConfigKeyT) = { val nestedClasses = key.getConfigClass.getClasses diff --git a/standalone-container/src/test/scala/com/yahoo/container/standalone/StandaloneSubscriberTest.scala b/standalone-container/src/test/scala/com/yahoo/container/standalone/StandaloneSubscriberTest.scala index 8fd2427185b..ab6f486c748 100644 --- a/standalone-container/src/test/scala/com/yahoo/container/standalone/StandaloneSubscriberTest.scala +++ b/standalone-container/src/test/scala/com/yahoo/container/standalone/StandaloneSubscriberTest.scala @@ -21,7 +21,7 @@ class StandaloneSubscriberTest { def key(name: String) = new ConfigKey(name, "container", "container").asInstanceOf[ConfigKey[ConfigInstance]] - def box(i: Int) = new java.lang.Integer(i) + def box(i: Int) = java.lang.Integer.valueOf(i) @Test @Ignore diff --git a/vespalib/CMakeLists.txt b/vespalib/CMakeLists.txt index 40d0c539c86..33553da9422 100644 --- a/vespalib/CMakeLists.txt +++ b/vespalib/CMakeLists.txt @@ -10,6 +10,8 @@ vespa_define_module( APPS src/apps/make_fixture_macros + src/apps/vespa-detect-hostname + src/apps/vespa-validate-hostname TESTS src/tests/alignedmemory diff --git a/vespalib/src/apps/vespa-detect-hostname/.gitignore b/vespalib/src/apps/vespa-detect-hostname/.gitignore new file mode 100644 index 00000000000..d1570fb3d89 --- /dev/null +++ b/vespalib/src/apps/vespa-detect-hostname/.gitignore @@ -0,0 +1 @@ +/vespa-detect-hostname diff --git a/vespalib/src/apps/vespa-detect-hostname/CMakeLists.txt b/vespalib/src/apps/vespa-detect-hostname/CMakeLists.txt new file mode 100644 index 00000000000..51d2ba3b0b0 --- /dev/null +++ b/vespalib/src/apps/vespa-detect-hostname/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(vespalib_vespa-detect-hostname_app + SOURCES + detect_hostname.cpp + OUTPUT_NAME vespa-detect-hostname + INSTALL bin + DEPENDS + vespalib +) diff --git a/vespalib/src/apps/vespa-detect-hostname/detect_hostname.cpp b/vespalib/src/apps/vespa-detect-hostname/detect_hostname.cpp new file mode 100644 index 00000000000..a1387c6519d --- /dev/null +++ b/vespalib/src/apps/vespa-detect-hostname/detect_hostname.cpp @@ -0,0 +1,50 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include <stdio.h> +#include <stdlib.h> +#include <vespa/vespalib/net/socket_address.h> +#include <vespa/vespalib/stllike/string.h> +#include <set> + +using vespalib::SocketAddress; + +std::set<vespalib::string> make_ip_set() { + std::set<vespalib::string> result; + for (const auto &addr: SocketAddress::get_interfaces()) { + result.insert(addr.ip_address()); + } + return result; +} + +vespalib::string get_hostname() { + std::vector<char> result(4096, '\0'); + gethostname(&result[0], 4000); + return SocketAddress::normalize(&result[0]); +} + +bool check(const vespalib::string &name, const std::set<vespalib::string> &ip_set) { + auto addr_list = SocketAddress::resolve(80, name.c_str()); + if (addr_list.empty()) { + return false; + } + for (const SocketAddress &addr: addr_list) { + vespalib::string ip_addr = addr.ip_address(); + if (ip_set.count(ip_addr) == 0) { + return false; + } + } + return true; +} + +int main(int, char **) { + auto my_ip_set = make_ip_set(); + std::vector<vespalib::string> list({get_hostname(), "localhost", "127.0.0.1", "::1"}); + for (const vespalib::string &name: list) { + if (check(name, my_ip_set)) { + fprintf(stdout, "%s\n", name.c_str()); + return 0; + } + } + fprintf(stderr, "ERROR: failed to detect hostname\n"); + return 1; +} diff --git a/vespalib/src/apps/vespa-validate-hostname/.gitignore b/vespalib/src/apps/vespa-validate-hostname/.gitignore new file mode 100644 index 00000000000..9d95e867f73 --- /dev/null +++ b/vespalib/src/apps/vespa-validate-hostname/.gitignore @@ -0,0 +1 @@ +/vespa-validate-hostname diff --git a/vespalib/src/apps/vespa-validate-hostname/CMakeLists.txt b/vespalib/src/apps/vespa-validate-hostname/CMakeLists.txt new file mode 100644 index 00000000000..7ffa7d763ec --- /dev/null +++ b/vespalib/src/apps/vespa-validate-hostname/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(vespalib_vespa-validate-hostname_app + SOURCES + validate_hostname.cpp + OUTPUT_NAME vespa-validate-hostname + INSTALL bin + DEPENDS + vespalib +) diff --git a/vespalib/src/apps/vespa-validate-hostname/validate_hostname.cpp b/vespalib/src/apps/vespa-validate-hostname/validate_hostname.cpp new file mode 100644 index 00000000000..da4907d4c91 --- /dev/null +++ b/vespalib/src/apps/vespa-validate-hostname/validate_hostname.cpp @@ -0,0 +1,70 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include <stdio.h> +#include <stdlib.h> +#include <vespa/vespalib/net/socket_address.h> +#include <vespa/vespalib/stllike/string.h> +#include <set> + +using vespalib::SocketAddress; + +std::set<vespalib::string> make_ip_set() { + std::set<vespalib::string> result; + for (const auto &addr: SocketAddress::get_interfaces()) { + result.insert(addr.ip_address()); + } + return result; +} + +vespalib::string normalize(const vespalib::string &hostname) { + vespalib::string canon_name = SocketAddress::normalize(hostname); + if (canon_name != hostname) { + fprintf(stderr, "warning: host name (%s) is not canonical (canonical host name: %s)\n", + hostname.c_str(), canon_name.c_str()); + } + return canon_name; +} + +void check_reverse(const vespalib::string &hostname, const SocketAddress &addr) { + std::set<vespalib::string> seen({hostname}); + vespalib::string reverse = addr.reverse_lookup(); + for (size_t i = 0; !reverse.empty() && (i < 10); ++i) { + if (seen.count(reverse) == 0) { + seen.insert(reverse); + fprintf(stderr, "warning: conflicting reverse lookup: %s->%s->%s\n", + hostname.c_str(), addr.ip_address().c_str(), reverse.c_str()); + } + reverse = addr.reverse_lookup(); + } +} + +int usage(const char *self) { + fprintf(stderr, "usage: %s <hostname>\n", self); + return 1; +} + +int main(int argc, char **argv) { + if (argc != 2) { + return usage(argv[0]); + } + bool valid = true; + auto my_ip_set = make_ip_set(); + vespalib::string hostname = normalize(argv[1]); + auto addr_list = SocketAddress::resolve(80, hostname.c_str()); + if (addr_list.empty()) { + valid = false; + fprintf(stderr, "ERROR: host name (%s) could not be resolved\n", + hostname.c_str()); + } + for (const SocketAddress &addr: addr_list) { + vespalib::string ip_addr = addr.ip_address(); + if (my_ip_set.count(ip_addr) == 0) { + valid = false; + fprintf(stderr, "ERROR: host name (%s) resolves to ip address not owned by this host (%s)\n", + hostname.c_str(), ip_addr.c_str()); + } else { + check_reverse(hostname, addr); + } + } + return valid ? 0 : 1; +} diff --git a/vespalib/src/vespa/vespalib/net/socket_address.cpp b/vespalib/src/vespa/vespalib/net/socket_address.cpp index 8f1d903daa6..d71441b0989 100644 --- a/vespalib/src/vespa/vespalib/net/socket_address.cpp +++ b/vespalib/src/vespa/vespalib/net/socket_address.cpp @@ -5,6 +5,7 @@ #include <sys/types.h> #include <sys/un.h> #include <arpa/inet.h> +#include <ifaddrs.h> #include <netdb.h> #include <cassert> @@ -14,6 +15,18 @@ namespace { const in6_addr ipv6_wildcard = IN6ADDR_ANY_INIT; +socklen_t get_ip_addr_size(const sockaddr *addr) { + if (addr != nullptr) { + if (addr->sa_family == AF_INET) { + return sizeof(sockaddr_in); + } + if (addr->sa_family == AF_INET6) { + return sizeof(sockaddr_in6); + } + } + return 0; +} + } // namespace vespalib::<unnamed> bool @@ -55,6 +68,14 @@ SocketAddress::ip_address() const } vespalib::string +SocketAddress::reverse_lookup() const +{ + std::vector<char> result(4096, '\0'); + getnameinfo(addr(), _size, &result[0], 4000, nullptr, 0, NI_NAMEREQD); + return &result[0]; +} + +vespalib::string SocketAddress::path() const { vespalib::string result; @@ -250,4 +271,41 @@ SocketAddress::from_name(const vespalib::string &name) return result; } +std::vector<SocketAddress> +SocketAddress::get_interfaces() +{ + std::vector<SocketAddress> result; + ifaddrs *list = nullptr; + if (getifaddrs(&list) == 0) { + for (const ifaddrs *entry = list; entry != nullptr; entry = entry->ifa_next) { + socklen_t size = get_ip_addr_size(entry->ifa_addr); + if (size > 0) { + result.push_back(SocketAddress(entry->ifa_addr, size)); + } + } + freeifaddrs(list); + } + return result; +} + +vespalib::string +SocketAddress::normalize(const vespalib::string &host_name) +{ + vespalib::string result = host_name; + addrinfo hints; + memset(&hints, 0, sizeof(addrinfo)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = 0; + hints.ai_flags = (AI_CANONNAME); + addrinfo *list = nullptr; + if (getaddrinfo(host_name.c_str(), nullptr, &hints, &list) == 0) { + if ((list != nullptr) && (list->ai_canonname != nullptr)) { + result = list->ai_canonname; + } + freeaddrinfo(list); + } + return result; +} + } // namespace vespalib diff --git a/vespalib/src/vespa/vespalib/net/socket_address.h b/vespalib/src/vespa/vespalib/net/socket_address.h index cc0958e7c63..5e706742e1f 100644 --- a/vespalib/src/vespa/vespalib/net/socket_address.h +++ b/vespalib/src/vespa/vespalib/net/socket_address.h @@ -43,6 +43,7 @@ public: bool is_abstract() const; int port() const; vespalib::string ip_address() const; + vespalib::string reverse_lookup() const; vespalib::string path() const; vespalib::string name() const; vespalib::string spec() const; @@ -73,6 +74,8 @@ public: } static SocketAddress from_path(const vespalib::string &path); static SocketAddress from_name(const vespalib::string &name); + static std::vector<SocketAddress> get_interfaces(); + static vespalib::string normalize(const vespalib::string &host_name); }; } // namespace vespalib |