aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@broadpark.no>2017-10-26 20:25:15 +0200
committerTor Egge <Tor.Egge@oath.com>2017-10-27 08:50:12 +0000
commita0e0adddadbbd556c620ac8efa2b6c3db9b48818 (patch)
treec75dce450125c73c4978c8ef3992c690a4deebac
parent41e8d2a568bce389469dbfcf4668d0f0bc72cc59 (diff)
Use std::unique_lock<std::mutex> to guard data set.
-rw-r--r--searchcore/src/vespa/searchcore/fdispatch/search/dataset_base.cpp12
-rw-r--r--searchcore/src/vespa/searchcore/fdispatch/search/dataset_base.h7
-rw-r--r--searchcore/src/vespa/searchcore/fdispatch/search/datasetcollection.cpp13
-rw-r--r--searchcore/src/vespa/searchcore/fdispatch/search/engine_base.cpp54
-rw-r--r--searchcore/src/vespa/searchcore/fdispatch/search/fnet_dataset.cpp3
-rw-r--r--searchcore/src/vespa/searchcore/fdispatch/search/fnet_engine.cpp23
-rw-r--r--searchcore/src/vespa/searchcore/fdispatch/search/fnet_engine.h3
-rw-r--r--searchcore/src/vespa/searchcore/fdispatch/search/fnet_search.cpp129
-rw-r--r--searchcore/src/vespa/searchcore/fdispatch/search/fnet_search.h2
-rw-r--r--searchcore/src/vespa/searchcore/fdispatch/search/plain_dataset.cpp31
-rw-r--r--searchcore/src/vespa/searchcore/fdispatch/search/plain_dataset.h8
11 files changed, 140 insertions, 145 deletions
diff --git a/searchcore/src/vespa/searchcore/fdispatch/search/dataset_base.cpp b/searchcore/src/vespa/searchcore/fdispatch/search/dataset_base.cpp
index 0374ac52b65..b4907627894 100644
--- a/searchcore/src/vespa/searchcore/fdispatch/search/dataset_base.cpp
+++ b/searchcore/src/vespa/searchcore/fdispatch/search/dataset_base.cpp
@@ -141,9 +141,8 @@ FastS_DataSetBase::SetActiveQuery_HasLock()
void
FastS_DataSetBase::SetActiveQuery()
{
- LockDataset();
+ auto dsGuard(getDsGuard());
SetActiveQuery_HasLock();
- UnlockDataset();
}
@@ -160,9 +159,8 @@ FastS_DataSetBase::ClearActiveQuery_HasLock(FastS_TimeKeeper *timeKeeper)
void
FastS_DataSetBase::ClearActiveQuery(FastS_TimeKeeper *timeKeeper)
{
- LockDataset();
+ auto dsGuard(getDsGuard());
ClearActiveQuery_HasLock(timeKeeper);
- UnlockDataset();
}
@@ -272,7 +270,7 @@ FastS_DataSetBase::UpdateSearchTime(double tnow,
double elapsed, bool timedout)
{
int slot;
- LockDataset();
+ auto dsGuard(getDsGuard());
slot = (int) (elapsed * 10);
if (slot >= _total._timestatslots)
slot = _total._timestatslots - 1;
@@ -280,7 +278,6 @@ FastS_DataSetBase::UpdateSearchTime(double tnow,
slot = 0;
_total._timestats[slot]++;
_total._normalTimeStat.Update(tnow, elapsed, timedout);
- UnlockDataset();
}
@@ -302,7 +299,7 @@ void
FastS_DataSetBase::addPerformance(FastS_QueryPerf &qp)
{
FastS_TimeStatTotals totals;
- LockDataset();
+ auto dsGuard(getDsGuard());
_total._normalTimeStat.AddTotal(&totals);
qp.queueLen += _queryQueue.GetQueueLen();
qp.activeCnt += _queryQueue.GetActiveQueries();
@@ -310,7 +307,6 @@ FastS_DataSetBase::addPerformance(FastS_QueryPerf &qp)
qp.queryTime += totals._totalAccTime;
qp.dropCnt += _total._nOverload;
qp.timeoutCnt += _total._nTimedOut;
- UnlockDataset();
}
diff --git a/searchcore/src/vespa/searchcore/fdispatch/search/dataset_base.h b/searchcore/src/vespa/searchcore/fdispatch/search/dataset_base.h
index 75c47fffc27..a757d92fdeb 100644
--- a/searchcore/src/vespa/searchcore/fdispatch/search/dataset_base.h
+++ b/searchcore/src/vespa/searchcore/fdispatch/search/dataset_base.h
@@ -8,6 +8,7 @@
#include <atomic>
#include <vespa/fastos/time.h>
#include <vespa/fastos/cond.h>
+#include <mutex>
class FastS_TimeKeeper;
@@ -164,7 +165,7 @@ public:
protected:
FastS_AppContext *_appCtx;
- FastOS_Mutex _lock;
+ std::mutex _lock;
FastOS_Time _createtime;
queryQueue_t _queryQueue;
total_t _total;
@@ -182,9 +183,7 @@ public:
// locking stuff
//--------------
- void LockDataset() { _lock.Lock(); }
- void UnlockDataset() { _lock.Unlock(); }
- FastOS_Mutex & getMutex() { return _lock; }
+ std::unique_lock<std::mutex> getDsGuard() { return std::unique_lock<std::mutex>(_lock); }
// query queue related methods
//----------------------------
diff --git a/searchcore/src/vespa/searchcore/fdispatch/search/datasetcollection.cpp b/searchcore/src/vespa/searchcore/fdispatch/search/datasetcollection.cpp
index 95ef4899646..cf7cd21d9b9 100644
--- a/searchcore/src/vespa/searchcore/fdispatch/search/datasetcollection.cpp
+++ b/searchcore/src/vespa/searchcore/fdispatch/search/datasetcollection.cpp
@@ -229,9 +229,10 @@ FastS_DataSetCollection::CreateSearch(uint32_t dataSetID,
ret = new FastS_FailedSearch(dataSetID, false,
search::engine::ECODE_ILLEGAL_DATASET, NULL);
} else {
- dataset->LockDataset();
- dataset->SetActiveQuery_HasLock();
- dataset->UnlockDataset();
+ {
+ auto dsGuard(dataset->getDsGuard());
+ dataset->SetActiveQuery_HasLock();
+ }
/* XXX: Semantic change: precounted as active in dataset */
ret = dataset->CreateSearch(this, timeKeeper, /* async = */ false);
}
@@ -247,9 +248,8 @@ FastS_DataSetCollection::CheckQueryQueues(FastS_TimeKeeper *timeKeeper)
FastS_DataSetBase *dataset = PeekDataSet(datasetidx);
if (dataset != NULL) {
- dataset->LockDataset();
+ auto dsGuard(dataset->getDsGuard());
dataset->CheckQueryQueue_HasLock(timeKeeper);
- dataset->UnlockDataset();
}
}
}
@@ -262,9 +262,8 @@ FastS_DataSetCollection::AbortQueryQueues()
FastS_DataSetBase *dataset = PeekDataSet(datasetidx);
if (dataset != NULL) {
- dataset->LockDataset();
+ auto dsGuard(dataset->getDsGuard());
dataset->AbortQueryQueue_HasLock();
- dataset->UnlockDataset();
}
}
}
diff --git a/searchcore/src/vespa/searchcore/fdispatch/search/engine_base.cpp b/searchcore/src/vespa/searchcore/fdispatch/search/engine_base.cpp
index 83ec3d73b11..1863b2f20e5 100644
--- a/searchcore/src/vespa/searchcore/fdispatch/search/engine_base.cpp
+++ b/searchcore/src/vespa/searchcore/fdispatch/search/engine_base.cpp
@@ -337,28 +337,29 @@ FastS_EngineBase::HandlePingResponse(uint32_t partid,
}
}
- _dataset->LockDataset();
- if (changed)
- _dataset->LinkOutPart_HasLock(this);
+ {
+ auto dsGuard(_dataset->getDsGuard());
+ if (changed)
+ _dataset->LinkOutPart_HasLock(this);
- _partid = partid;
- if (docstamp != _reported._docstamp) {
- _reported._docstamp = docstamp;
- }
- _reported._mld = mld;
- _reported._maxNodes = maxnodes;
- _reported._actNodes = nodes;
- _reported._maxParts = maxparts;
- _reported._actParts = parts;
- if (_reported._activeDocs != activeDocs) {
- _dataset->updateActiveDocs_HasLock(GetConfRowID(), activeDocs, _reported._activeDocs);
- _reported._activeDocs = activeDocs;
- }
- _isUp = true;
+ _partid = partid;
+ if (docstamp != _reported._docstamp) {
+ _reported._docstamp = docstamp;
+ }
+ _reported._mld = mld;
+ _reported._maxNodes = maxnodes;
+ _reported._actNodes = nodes;
+ _reported._maxParts = maxparts;
+ _reported._actParts = parts;
+ if (_reported._activeDocs != activeDocs) {
+ _dataset->updateActiveDocs_HasLock(GetConfRowID(), activeDocs, _reported._activeDocs);
+ _reported._activeDocs = activeDocs;
+ }
+ _isUp = true;
- _dataset->LinkInPart_HasLock(this);
+ _dataset->LinkInPart_HasLock(this);
- _dataset->UnlockDataset();
+ }
_dataset->ScheduleCheckTempFail();
if (onlined) {
@@ -383,13 +384,14 @@ FastS_EngineBase::HandleLostConnection()
_stats._floptime.SetNow();
LOG(warning, "Search node %s down", _config._name);
- _dataset->LockDataset();
- _dataset->LinkOutPart_HasLock(this);
- PossCount noDocs;
- noDocs.valid = true;
- _dataset->updateActiveDocs_HasLock(GetConfRowID(), noDocs, _reported._activeDocs);
- _reported._activeDocs = noDocs;
- _dataset->UnlockDataset();
+ {
+ auto dsGuard(_dataset->getDsGuard());
+ _dataset->LinkOutPart_HasLock(this);
+ PossCount noDocs;
+ noDocs.valid = true;
+ _dataset->updateActiveDocs_HasLock(GetConfRowID(), noDocs, _reported._activeDocs);
+ _reported._activeDocs = noDocs;
+ }
_dataset->ScheduleCheckTempFail();
HandleDown(); // classic: NotifyVirtualConnsDown
}
diff --git a/searchcore/src/vespa/searchcore/fdispatch/search/fnet_dataset.cpp b/searchcore/src/vespa/searchcore/fdispatch/search/fnet_dataset.cpp
index 92ef41cc636..f6fb46a67ca 100644
--- a/searchcore/src/vespa/searchcore/fdispatch/search/fnet_dataset.cpp
+++ b/searchcore/src/vespa/searchcore/fdispatch/search/fnet_dataset.cpp
@@ -108,7 +108,7 @@ FastS_FNET_DataSet::Free()
bool
FastS_FNET_DataSet::isGoodRow(uint32_t rowId)
{
- LockDataset();
+ auto dsGuard(getDsGuard());
uint64_t rowBit = 1ul << rowId;
bool wasBad = ((_failedRowsBitmask & rowBit) != 0);
bool isBad = false;
@@ -146,6 +146,5 @@ FastS_FNET_DataSet::isGoodRow(uint32_t rowId)
LOG(info, "Row %d is now good again (%lu/%g active docs, coverage %ld/%ld)",
rowId, candDocs, restAvg, nodesUp, configuredParts);
}
- UnlockDataset();
return !isBad;
}
diff --git a/searchcore/src/vespa/searchcore/fdispatch/search/fnet_engine.cpp b/searchcore/src/vespa/searchcore/fdispatch/search/fnet_engine.cpp
index 5b444427c4d..8cfd49e4108 100644
--- a/searchcore/src/vespa/searchcore/fdispatch/search/fnet_engine.cpp
+++ b/searchcore/src/vespa/searchcore/fdispatch/search/fnet_engine.cpp
@@ -64,10 +64,12 @@ FastS_FNET_Engine::Connect()
_transport->Connect(_spec.c_str(),
&FS4PersistentPacketStreamer::Instance,
this);
- LockDataSet();
- FNET_Connection *oldConn = _conn;
- _conn = newConn;
- UnlockDataSet();
+ FNET_Connection *oldConn;
+ {
+ auto dsGuard(getDsGuard());
+ oldConn = _conn;
+ _conn = newConn;
+ }
if (oldConn != NULL)
oldConn->SubRef();
if (newConn == NULL && !IsRealBad())
@@ -81,10 +83,12 @@ FastS_FNET_Engine::Disconnect()
{
if (_conn != NULL) {
_conn->CloseAdminChannel();
- LockDataSet();
- FNET_Connection *conn = _conn;
- _conn = NULL;
- UnlockDataSet();
+ FNET_Connection *conn;
+ {
+ auto dsGuard(getDsGuard());
+ conn = _conn;
+ _conn = NULL;
+ }
_transport->Close(conn, /* needref = */ false);
}
}
@@ -116,9 +120,8 @@ FastS_FNET_Engine::~FastS_FNET_Engine()
_connectTask.Kill();
Disconnect();
if (IsUp()) {
- LockDataSet();
+ auto dsGuard(getDsGuard());
_dataset->LinkOutPart_HasLock(this);
- UnlockDataSet();
}
if (_monitorQuery != NULL) {
_monitorQuery->Free();
diff --git a/searchcore/src/vespa/searchcore/fdispatch/search/fnet_engine.h b/searchcore/src/vespa/searchcore/fdispatch/search/fnet_engine.h
index 9f03f0319db..bd40229180d 100644
--- a/searchcore/src/vespa/searchcore/fdispatch/search/fnet_engine.h
+++ b/searchcore/src/vespa/searchcore/fdispatch/search/fnet_engine.h
@@ -95,8 +95,7 @@ public:
FastS_FNET_DataSet *dataset);
virtual ~FastS_FNET_Engine();
- void LockDataSet() { _dataset->LockDataset(); }
- void UnlockDataSet() { _dataset->UnlockDataset(); }
+ std::unique_lock<std::mutex> getDsGuard() { return _dataset->getDsGuard(); }
void StartWarnTimer();
void ScheduleConnect(double delay);
diff --git a/searchcore/src/vespa/searchcore/fdispatch/search/fnet_search.cpp b/searchcore/src/vespa/searchcore/fdispatch/search/fnet_search.cpp
index c5e3d001210..6beaf22a238 100644
--- a/searchcore/src/vespa/searchcore/fdispatch/search/fnet_search.cpp
+++ b/searchcore/src/vespa/searchcore/fdispatch/search/fnet_search.cpp
@@ -103,11 +103,11 @@ FastS_FNET_SearchNode::NT_InitMerge(uint32_t *numDocs,
FastS_EngineBase *
-FastS_FNET_SearchNode::getPartition(const FastOS_Mutex & dsMutex, bool userow, FastS_FNET_DataSet *dataset)
+FastS_FNET_SearchNode::getPartition(const std::unique_lock<std::mutex> &dsGuard, bool userow, FastS_FNET_DataSet *dataset)
{
return ((userow)
- ? dataset->getPartitionMLD(dsMutex, getPartID(), _flags._docsumMld, _docsumRow)
- : dataset->getPartitionMLD(dsMutex, getPartID(), _flags._docsumMld));
+ ? dataset->getPartitionMLD(dsGuard, getPartID(), _flags._docsumMld, _docsumRow)
+ : dataset->getPartitionMLD(dsGuard, getPartID(), _flags._docsumMld));
}
@@ -335,26 +335,26 @@ FastS_FNET_Search::ConnectQueryNodes()
}
EngineNodeMap engines;
engines.reserve(_nodes.size());
- FastOS_Mutex & dsLock = _dataset->getMutex();
- dsLock.Lock();
- for (uint32_t i = 0; i < _nodes.size(); i++) {
- FastS_EngineBase *engine = NULL;
- if (_dataset->useFixedRowDistribution()) {
- engine = _dataset->getPartition(dsLock, i, fixedRow);
- LOG(debug, "FixedRow: getPartition(part=%u, row=%u) -> engine(%s)", i, fixedRow, (engine != nullptr ? engine->GetName() : "null"));
- } else {
- engine = _dataset->getPartition(dsLock, i);
- }
- if (engine != nullptr) {
- LOG(debug, "Wanted part=%d, engine={name=%s, row=%d, partid=%d}", i, engine->GetName(), engine->GetConfRowID(), engine->GetPartID());
+ {
+ auto dsGuard(_dataset->getDsGuard());
+ for (uint32_t i = 0; i < _nodes.size(); i++) {
+ FastS_EngineBase *engine = NULL;
+ if (_dataset->useFixedRowDistribution()) {
+ engine = _dataset->getPartition(dsGuard, i, fixedRow);
+ LOG(debug, "FixedRow: getPartition(part=%u, row=%u) -> engine(%s)", i, fixedRow, (engine != nullptr ? engine->GetName() : "null"));
+ } else {
+ engine = _dataset->getPartition(dsGuard, i);
+ }
if (engine != nullptr) {
- engines.emplace_back(engine, getNode(i));
+ LOG(debug, "Wanted part=%d, engine={name=%s, row=%d, partid=%d}", i, engine->GetName(), engine->GetConfRowID(), engine->GetPartID());
+ if (engine != nullptr) {
+ engines.emplace_back(engine, getNode(i));
+ }
+ } else {
+ LOG(debug, "No engine for part %d", i);
}
- } else {
- LOG(debug, "No engine for part %d", i);
}
}
- dsLock.Unlock();
connectNodes(engines);
}
@@ -370,19 +370,19 @@ FastS_FNET_Search::ConnectEstimateNodes()
uint32_t partcnt = 0;
EngineNodeMap engines;
- FastOS_Mutex & dsLock = _dataset->getMutex();
- dsLock.Lock();
- while (partcnt < _dataset->GetEstimateParts() && trycnt < _estPartCutoff) {
- FastS_EngineBase *engine = _dataset->getPartition(dsLock, partid);
- if (engine != NULL) {
- engines.emplace_back(engine, getNode(partid));
- partcnt++;
+ {
+ auto dsGuard(_dataset->getDsGuard());
+ while (partcnt < _dataset->GetEstimateParts() && trycnt < _estPartCutoff) {
+ FastS_EngineBase *engine = _dataset->getPartition(dsGuard, partid);
+ if (engine != NULL) {
+ engines.emplace_back(engine, getNode(partid));
+ partcnt++;
+ }
+ trycnt++;
+ partid = (partid + 1) % _estPartCutoff;
}
- trycnt++;
- partid = (partid + 1) % _estPartCutoff;
+ _estParts = partcnt;
}
- _estParts = partcnt;
- dsLock.Unlock();
connectNodes(engines);
}
@@ -394,11 +394,10 @@ void FastS_FNET_SearchNode::Connect(FastS_FNET_Engine *engine)
_engine = engine;
_flags._needSubCost = true;
- _engine->LockDataSet();
+ auto dsGuard(_engine->getDsGuard());
_channel = _engine->OpenChannel_HasDSLock(this);
_rowid = _engine->GetConfRowID();
_stamp = _engine->GetTimeStamp();
- _engine->UnlockDataSet();
}
void FastS_FNET_SearchNode::Connect_HasDSLock(FastS_FNET_Engine *engine)
@@ -434,30 +433,30 @@ void FastS_FNET_Search::connectSearchPath(const SearchPath::Element &elem,
uint32_t dispatchLevel)
{
EngineNodeMap engines;
- FastOS_Mutex & dsLock = _dataset->getMutex();
- dsLock.Lock();
- if (!elem.hasRow()) {
- for (size_t partId : elem.nodes()) {
- if (partId < _nodes.size()) {
- FastS_EngineBase *engine = _dataset->getPartition(dsLock, partId);
- LOG(debug, "searchpath='%s', partId=%ld, dispatchLevel=%u", spec.c_str(), partId, dispatchLevel);
- if (engine != NULL) {
- engines.emplace_back(engine, getNode(partId));
+ {
+ auto dsGuard(_dataset->getDsGuard());
+ if (!elem.hasRow()) {
+ for (size_t partId : elem.nodes()) {
+ if (partId < _nodes.size()) {
+ FastS_EngineBase *engine = _dataset->getPartition(dsGuard, partId);
+ LOG(debug, "searchpath='%s', partId=%ld, dispatchLevel=%u", spec.c_str(), partId, dispatchLevel);
+ if (engine != NULL) {
+ engines.emplace_back(engine, getNode(partId));
+ }
}
}
- }
- } else {
- for (size_t partId : elem.nodes()) {
- if (partId < _nodes.size()) {
- FastS_EngineBase *engine = _dataset->getPartition(dsLock, partId, elem.row());
- LOG(debug, "searchpath='%s', partId=%ld, row=%ld, dispatchLevel=%u", spec.c_str(), partId, elem.row(), dispatchLevel);
- if (engine != NULL) {
- engines.emplace_back(engine, getNode(partId));
+ } else {
+ for (size_t partId : elem.nodes()) {
+ if (partId < _nodes.size()) {
+ FastS_EngineBase *engine = _dataset->getPartition(dsGuard, partId, elem.row());
+ LOG(debug, "searchpath='%s', partId=%ld, row=%ld, dispatchLevel=%u", spec.c_str(), partId, elem.row(), dispatchLevel);
+ if (engine != NULL) {
+ engines.emplace_back(engine, getNode(partId));
+ }
}
}
}
}
- dsLock.Unlock();
connectNodes(engines);
}
@@ -471,26 +470,26 @@ FastS_FNET_Search::ConnectDocsumNodes(bool ignoreRow)
bool userow = (_dataset->GetRowBits() > 0) && !ignoreRow;
EngineNodeMap engines;
- FastOS_Mutex & dsLock = _dataset->getMutex();
- dsLock.Lock();
- for (auto & node : _nodes) {
- if (node._gdx != NULL) {
- FastS_EngineBase *engine = node.getPartition(dsLock, userow, _dataset);
- if (engine != nullptr) {
- engines.emplace_back(engine, &node);
- }
- }
- for (FastS_FNET_SearchNode::ExtraDocsumNodesIter iter(&node); iter.valid(); ++iter) {
- FastS_FNET_SearchNode *eNode = *iter;
- if (eNode->_gdx != NULL) {
- FastS_EngineBase *engine = eNode->getPartition(dsLock, userow, _dataset);
+ {
+ auto dsGuard(_dataset->getDsGuard());
+ for (auto & node : _nodes) {
+ if (node._gdx != NULL) {
+ FastS_EngineBase *engine = node.getPartition(dsGuard, userow, _dataset);
if (engine != nullptr) {
- engines.emplace_back(engine, eNode);
+ engines.emplace_back(engine, &node);
+ }
+ }
+ for (FastS_FNET_SearchNode::ExtraDocsumNodesIter iter(&node); iter.valid(); ++iter) {
+ FastS_FNET_SearchNode *eNode = *iter;
+ if (eNode->_gdx != NULL) {
+ FastS_EngineBase *engine = eNode->getPartition(dsGuard, userow, _dataset);
+ if (engine != nullptr) {
+ engines.emplace_back(engine, eNode);
+ }
}
}
}
}
- dsLock.Unlock();
connectNodes(engines);
}
diff --git a/searchcore/src/vespa/searchcore/fdispatch/search/fnet_search.h b/searchcore/src/vespa/searchcore/fdispatch/search/fnet_search.h
index 3f9fc3db077..de913bda46f 100644
--- a/searchcore/src/vespa/searchcore/fdispatch/search/fnet_search.h
+++ b/searchcore/src/vespa/searchcore/fdispatch/search/fnet_search.h
@@ -112,7 +112,7 @@ public:
bool IsConnected() const { return _channel != NULL; }
void Connect(FastS_FNET_Engine *engine);
void Connect_HasDSLock(FastS_FNET_Engine *engine);
- FastS_EngineBase * getPartition(const FastOS_Mutex & dsMutex, bool userow, FastS_FNET_DataSet *dataset);
+ FastS_EngineBase * getPartition(const std::unique_lock<std::mutex> &dsGuard, bool userow, FastS_FNET_DataSet *dataset);
void allocGDX(search::docsummary::GetDocsumArgs *args, const search::engine::PropertiesMap &properties);
void postGDX(uint32_t *pendingDocsums, uint32_t *pendingDocsumNodes);
vespalib::string toString() const;
diff --git a/searchcore/src/vespa/searchcore/fdispatch/search/plain_dataset.cpp b/searchcore/src/vespa/searchcore/fdispatch/search/plain_dataset.cpp
index 1d3c26b8e57..aa1a783a7be 100644
--- a/searchcore/src/vespa/searchcore/fdispatch/search/plain_dataset.cpp
+++ b/searchcore/src/vespa/searchcore/fdispatch/search/plain_dataset.cpp
@@ -241,13 +241,12 @@ FastS_PlainDataSet::~FastS_PlainDataSet()
void
FastS_PlainDataSet::UpdateMaxHitsPerNodeLog(bool incomplete, bool fuzzy)
{
- LockDataset();
+ auto dsGuard(getDsGuard());
_MHPN_log._cnt++;
if (incomplete)
_MHPN_log._incompleteCnt++;
if (fuzzy)
_MHPN_log._fuzzyCnt++;
- UnlockDataset();
}
@@ -272,9 +271,8 @@ FastS_PlainDataSet::RefCostUseNewEngine(FastS_EngineBase *oldEngine,
void
FastS_PlainDataSet::updateSearchTime(double searchTime, uint32_t rowId)
{
- LockDataset();
+ auto dsGuard(getDsGuard());
_stateOfRows.updateSearchTime(searchTime, rowId);
- UnlockDataset();
}
uint32_t
@@ -316,9 +314,9 @@ FastS_PlainDataSet::UseNewEngine(FastS_EngineBase *oldEngine,
}
FastS_EngineBase *
-FastS_PlainDataSet::getPartition(const FastOS_Mutex & dsMutex, uint32_t partindex, uint32_t rowid)
+FastS_PlainDataSet::getPartition(const std::unique_lock<std::mutex> &dsGuard, uint32_t partindex, uint32_t rowid)
{
- (void) dsMutex;
+ (void) dsGuard;
FastS_EngineBase* ret = NULL;
if (IsValidPartIndex_HasLock(partindex)) {
@@ -365,9 +363,9 @@ FastS_PlainDataSet::countNodesUpInRow_HasLock(uint32_t rowid)
}
FastS_EngineBase *
-FastS_PlainDataSet::getPartition(const FastOS_Mutex & dsMutex, uint32_t partindex)
+FastS_PlainDataSet::getPartition(const std::unique_lock<std::mutex> &dsGuard, uint32_t partindex)
{
- (void) dsMutex;
+ (void) dsGuard;
FastS_EngineBase* ret = NULL;
unsigned int oldCount = 1;
unsigned int engineCount = 0;
@@ -400,9 +398,9 @@ FastS_PlainDataSet::getPartition(const FastOS_Mutex & dsMutex, uint32_t partinde
}
FastS_EngineBase *
-FastS_PlainDataSet::getPartitionMLD(const FastOS_Mutex & dsMutex, uint32_t partindex, bool mld)
+FastS_PlainDataSet::getPartitionMLD(const std::unique_lock<std::mutex> &dsGuard, uint32_t partindex, bool mld)
{
- (void) dsMutex;
+ (void) dsGuard;
FastS_EngineBase* ret = NULL;
unsigned int oldCount = 1;
if (partindex < _partMap._num_partitions) {
@@ -429,9 +427,9 @@ FastS_PlainDataSet::getPartitionMLD(const FastOS_Mutex & dsMutex, uint32_t parti
}
FastS_EngineBase *
-FastS_PlainDataSet::getPartitionMLD(const FastOS_Mutex & dsMutex, uint32_t partindex, bool mld, uint32_t rowid)
+FastS_PlainDataSet::getPartitionMLD(const std::unique_lock<std::mutex> &dsGuard, uint32_t partindex, bool mld, uint32_t rowid)
{
- (void) dsMutex;
+ (void) dsGuard;
FastS_EngineBase* ret = NULL;
unsigned int oldCount = 1;
@@ -464,11 +462,12 @@ FastS_PlainDataSet::getPartEngines(uint32_t partition)
typedef FastS_EngineBase EB;
typedef std::vector<EB *> EBV;
EBV partEngines;
- LockDataset();
- for (FastS_EngineBase *iter = _partMap._partitions[partition]._engines; iter != NULL; iter = iter->_nextpart) {
- partEngines.push_back(iter);
+ {
+ auto dsGuard(getDsGuard());
+ for (FastS_EngineBase *iter = _partMap._partitions[partition]._engines; iter != NULL; iter = iter->_nextpart) {
+ partEngines.push_back(iter);
+ }
}
- UnlockDataset();
return partEngines;
}
diff --git a/searchcore/src/vespa/searchcore/fdispatch/search/plain_dataset.h b/searchcore/src/vespa/searchcore/fdispatch/search/plain_dataset.h
index 827abc13ce7..7c04834bd38 100644
--- a/searchcore/src/vespa/searchcore/fdispatch/search/plain_dataset.h
+++ b/searchcore/src/vespa/searchcore/fdispatch/search/plain_dataset.h
@@ -174,13 +174,13 @@ public:
PossCount getActiveDocs() const { return _stateOfRows.getActiveDocs(); }
uint32_t getRandomWeightedRow() const;
- FastS_EngineBase * getPartition(const FastOS_Mutex & lock, uint32_t partid);
- FastS_EngineBase * getPartition(const FastOS_Mutex & lock, uint32_t partid, uint32_t rowid);
+ FastS_EngineBase * getPartition(const std::unique_lock<std::mutex> &dsGuard, uint32_t partid);
+ FastS_EngineBase * getPartition(const std::unique_lock<std::mutex> &dsGuard, uint32_t partid, uint32_t rowid);
size_t countNodesUpInRow_HasLock(uint32_t rowid);
- FastS_EngineBase * getPartitionMLD(const FastOS_Mutex & lock, uint32_t partid, bool mld);
- FastS_EngineBase * getPartitionMLD(const FastOS_Mutex & lock, uint32_t partid, bool mld, uint32_t rowid);
+ 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);