summaryrefslogtreecommitdiffstats
path: root/vdslib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2016-09-21 21:05:49 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2016-09-21 21:05:49 +0000
commitd67c9a50560441d627171522da27aed281df1d00 (patch)
treea946dc7b801feb5ec5cc83dbf04264700b5980fb /vdslib
parent113cf5248cd21544eef2f32e76c6e3601e61daf9 (diff)
Ai, ai, ai. Here a nasty bug has been lurking... Accessing a moved/erase object....
Diffstat (limited to 'vdslib')
-rw-r--r--vdslib/src/vespa/vdslib/distribution/idealnodecalculatorcache.h15
1 files changed, 8 insertions, 7 deletions
diff --git a/vdslib/src/vespa/vdslib/distribution/idealnodecalculatorcache.h b/vdslib/src/vespa/vdslib/distribution/idealnodecalculatorcache.h
index 54ffba869bd..22b1de941f5 100644
--- a/vdslib/src/vespa/vdslib/distribution/idealnodecalculatorcache.h
+++ b/vdslib/src/vespa/vdslib/distribution/idealnodecalculatorcache.h
@@ -44,20 +44,21 @@ class IdealNodeCalculatorCache : public IdealNodeCalculatorConfigurable {
public:
typedef vespalib::LinkedPtr<TypeCache> LP;
- TypeCache(const IdealNodeCalculator& c, const NodeType& t,
- UpStates us, uint32_t size)
+ TypeCache(const IdealNodeCalculator& c, const NodeType& t, UpStates us, uint32_t size)
: _calc(c), _nodeType(t), _upStates(us), _order(size, *this),
- _hitCount(0), _missCount(0) {}
+ _hitCount(0), _missCount(0)
+ { }
IdealNodeList get(const document::BucketId& bucket) {
EntryMap::const_iterator it(_entries.find(bucket));
if (it == _entries.end()) {
++_missCount;
Entry& newEntry(_entries[bucket]);
- newEntry._result = _calc.getIdealNodes(
- _nodeType, bucket, _upStates);
- newEntry._order = _order.add(bucket);
- return newEntry._result;
+ newEntry._result = _calc.getIdealNodes(_nodeType, bucket, _upStates);
+ LruOrder<BucketId, TypeCache>::EntryRef tmpOrder = _order.add(bucket);
+ Entry& movedEntry(_entries[bucket]); // The entry might very well move after the previous add.
+ movedEntry._order = tmpOrder;
+ return movedEntry._result;
} else {
++_hitCount;
_order.moveToStart(it->second._order);