diff options
author | Håvard Pettersen <havardpe@yahooinc.com> | 2022-05-11 13:21:16 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@yahooinc.com> | 2022-05-11 14:14:53 +0000 |
commit | 530f4786b3ba73f2bb4a7e64132b7234e041d597 (patch) | |
tree | aaef5a32162c36b5f582a5f6c13de7884861839b /searchcore | |
parent | dfd60ee97e0531f1df053eaf6f506560eccbe89d (diff) |
make new bitvector when growing
Diffstat (limited to 'searchcore')
7 files changed, 44 insertions, 44 deletions
diff --git a/searchcore/src/tests/proton/documentmetastore/lid_allocator/lid_allocator_test.cpp b/searchcore/src/tests/proton/documentmetastore/lid_allocator/lid_allocator_test.cpp index b0f1220c768..2d675e82db2 100644 --- a/searchcore/src/tests/proton/documentmetastore/lid_allocator/lid_allocator_test.cpp +++ b/searchcore/src/tests/proton/documentmetastore/lid_allocator/lid_allocator_test.cpp @@ -83,7 +83,7 @@ protected: std::vector<uint32_t> get_active_lids() { std::vector<uint32_t> result; - auto active_lids = _allocator.getActiveLids(); + const auto &active_lids = _allocator.getActiveLids(); uint32_t lid = active_lids.getNextTrueBit(1); while (lid < active_lids.size()) { if (active_lids.testBit(lid)) { diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.cpp b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.cpp index 4df80dba74d..15de7b9b1d2 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.cpp +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.cpp @@ -1065,7 +1065,7 @@ DocumentMetaStore::getEstimatedShrinkLidSpaceGain() const BucketId DocumentMetaStore::getBucketOf(const vespalib::GenerationHandler::Guard &, uint32_t lid) const { - if (__builtin_expect(validLidFastSafe(lid, getCommittedDocIdLimit()), true)) { + if (__builtin_expect(validLidFast(lid, getCommittedDocIdLimit()), true)) { return getRawMetaData(lid).getBucketId(); } return BucketId(); diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.h b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.h index 6076bfb2865..0a5fff24a0e 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.h +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastore.h @@ -185,7 +185,7 @@ public: void move(DocId fromLid, DocId toLid, uint64_t prepare_serial_num) override; bool validButMaybeUnusedLid(DocId lid) const { return _lidAlloc.validButMaybeUnusedLid(lid); } bool validLidFast(DocId lid) const { return _lidAlloc.validLid(lid); } - bool validLidFastSafe(DocId lid, uint32_t limit) const { return _lidAlloc.validLidSafe(lid, limit); } + bool validLidFast(DocId lid, uint32_t limit) const { return _lidAlloc.validLid(lid, limit); } bool validLid(DocId lid) const override { return validLidFast(lid); } void removeBatch(const std::vector<DocId> &lidsToRemove, const DocId docIdLimit) override; const RawDocumentMetaData & getRawMetaData(DocId lid) const override { return _metaDataStore.acquire_elem_ref(lid); } @@ -254,7 +254,7 @@ public: return AttributeVector::getGenerationHandler(); } - const search::GrowableBitVector &getActiveLids() const { return _lidAlloc.getActiveLids(); } + const search::BitVector &getActiveLids() const { return _lidAlloc.getActiveLids(); } void clearDocs(DocId lidLow, DocId lidLimit, bool in_shrink_lid_space) override; diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.cpp b/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.cpp index 4163b59b4ca..57f8be576db 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.cpp +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.cpp @@ -181,7 +181,7 @@ namespace { class WhiteListBlueprint : public SimpleLeafBlueprint { private: - const search::GrowableBitVector &_activeLids; + const search::BitVector &_activeLids; mutable std::mutex _lock; mutable std::vector<search::fef::TermFieldMatchData *> _matchDataVector; @@ -193,7 +193,7 @@ private: return createFilterSearch(strict, FilterConstraint::UPPER_BOUND); } public: - WhiteListBlueprint(const search::GrowableBitVector &activeLids) + WhiteListBlueprint(const search::BitVector &activeLids) : SimpleLeafBlueprint(FieldSpecBaseList()), _activeLids(activeLids), _matchDataVector() diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.h b/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.h index 05795aee7d5..6118701b0dc 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.h +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.h @@ -68,10 +68,11 @@ public: return lid < _usedLids.size(); } bool validLid(DocId lid) const { - return (lid < _usedLids.getSizeSafe() && _usedLids.testBit(lid)); + auto &vector = _usedLids.getBitVector(); + return (lid < vector.getSizeAcquire() && vector.testBitAcquire(lid)); } - bool validLidSafe(DocId lid, uint32_t limit) const { - return (lid < limit && _usedLids.testBitSafe(lid)); + bool validLid(DocId lid, uint32_t limit) const { + return (lid < limit && _usedLids.testBitAcquire(lid)); } DocId getLowestFreeLid() const { return _freeLids.getLowest(); @@ -80,7 +81,7 @@ public: return _usedLids.getHighest(); } - const search::GrowableBitVector &getActiveLids() const { return _activeLids.getBitVector(); } + const search::BitVector &getActiveLids() const { return _activeLids.getBitVector(); } }; } diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/lidstatevector.cpp b/searchcore/src/vespa/searchcore/proton/documentmetastore/lidstatevector.cpp index 27b9cfdd197..22fa4c24cd5 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/lidstatevector.cpp +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/lidstatevector.cpp @@ -25,27 +25,27 @@ LidStateVector::resizeVector(uint32_t newSize, uint32_t newCapacity) { uint32_t lowest = getLowest(); uint32_t highest = getHighest(); - assert(!_trackLowest || lowest <= _bv.size()); - assert(!_trackHighest || _bv.size() == 0 || highest < _bv.size()); - bool nolowest(lowest == _bv.size()); - if (_bv.size() > newSize) { + assert(!_trackLowest || lowest <= _bv.writer().size()); + assert(!_trackHighest || _bv.writer().size() == 0 || highest < _bv.writer().size()); + bool nolowest(lowest == _bv.writer().size()); + if (_bv.writer().size() > newSize) { _bv.shrink(newSize); } - if (_bv.capacity() < newCapacity) { + if (_bv.writer().capacity() < newCapacity) { _bv.reserve(newCapacity); } - if (_bv.size() < newSize) { + if (_bv.writer().size() < newSize) { _bv.extend(newSize); } if (_trackLowest) { - if (nolowest || lowest > _bv.size()) { - lowest = _bv.size(); + if (nolowest || lowest > _bv.writer().size()) { + lowest = _bv.writer().size(); _lowest.store(lowest, std::memory_order_relaxed); } } if (_trackHighest) { - if (highest >= _bv.size()) { - highest = _bv.size() > 0 ? _bv.getPrevTrueBit(_bv.size() - 1) : 0; + if (highest >= _bv.writer().size()) { + highest = _bv.writer().size() > 0 ? _bv.writer().getPrevTrueBit(_bv.writer().size() - 1) : 0; _highest.store(highest, std::memory_order_relaxed); } } @@ -54,38 +54,38 @@ LidStateVector::resizeVector(uint32_t newSize, uint32_t newCapacity) void LidStateVector::updateLowest(uint32_t lowest) { - lowest = _bv.getNextTrueBit(lowest); - assert(lowest <= _bv.size()); + lowest = _bv.writer().getNextTrueBit(lowest); + assert(lowest <= _bv.writer().size()); _lowest.store(lowest, std::memory_order_relaxed); } void LidStateVector::updateHighest(uint32_t highest) { - highest = _bv.getPrevTrueBit(highest); - assert(_bv.size() == 0 || highest < _bv.size()); + highest = _bv.writer().getPrevTrueBit(highest); + assert(_bv.writer().size() == 0 || highest < _bv.writer().size()); _highest.store(highest, std::memory_order_relaxed); } void LidStateVector::setBit(unsigned int idx) { - assert(idx < _bv.size()); + assert(idx < _bv.writer().size()); if (_trackLowest && idx < getLowest()) { _lowest.store(idx, std::memory_order_relaxed); } if (_trackHighest && idx > getHighest()) { _highest.store(idx, std::memory_order_relaxed); } - assert(!_bv.testBit(idx)); - _bv.setBitAndMaintainCount(idx); + assert(!_bv.writer().testBit(idx)); + _bv.writer().setBitAndMaintainCount(idx); } template <bool do_set> uint32_t LidStateVector::assert_is_not_set_then_set_bits_helper(const std::vector<uint32_t>& idxs) { - uint32_t size = _bv.size(); + uint32_t size = _bv.writer().size(); uint32_t high = 0; uint32_t low = size; for (auto idx : idxs) { @@ -93,12 +93,12 @@ LidStateVector::assert_is_not_set_then_set_bits_helper(const std::vector<uint32_ if (idx > high) { high = idx; } - assert(!_bv.testBit(idx)); + assert(!_bv.writer().testBit(idx)); if (do_set) { if (idx < low) { low = idx; } - _bv.setBitAndMaintainCount(idx); + _bv.writer().setBitAndMaintainCount(idx); } } if (do_set) { @@ -128,9 +128,9 @@ LidStateVector::set_bits(const std::vector<uint32_t>& idxs) void LidStateVector::clearBit(unsigned int idx) { - assert(idx < _bv.size()); - assert(_bv.testBit(idx)); - _bv.clearBitAndMaintainCount(idx); + assert(idx < _bv.writer().size()); + assert(_bv.writer().testBit(idx)); + _bv.writer().clearBitAndMaintainCount(idx); maybeUpdateLowest(); maybeUpdateHighest(); } @@ -141,9 +141,9 @@ LidStateVector::assert_is_set_then_clear_bits_helper(const std::vector<uint32_t> { for (auto idx : idxs) { if (do_assert) { - assert(_bv.testBit(idx)); + assert(_bv.writer().testBit(idx)); } - _bv.clearBitAndMaintainCount(idx); + _bv.writer().clearBitAndMaintainCount(idx); } maybeUpdateLowest(); maybeUpdateHighest(); diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/lidstatevector.h b/searchcore/src/vespa/searchcore/proton/documentmetastore/lidstatevector.h index 08bd93f063d..a23c3657453 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/lidstatevector.h +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/lidstatevector.h @@ -19,13 +19,13 @@ class LidStateVector void updateHighest(uint32_t highest); void maybeUpdateLowest() { uint32_t lowest = getLowest(); - if (_trackLowest && lowest < _bv.size() && !_bv.testBit(lowest)) { + if (_trackLowest && lowest < _bv.writer().size() && !_bv.writer().testBit(lowest)) { updateLowest(lowest); } } void maybeUpdateHighest() { uint32_t highest = getHighest(); - if (_trackHighest && highest != 0 && !_bv.testBit(highest)) { + if (_trackHighest && highest != 0 && !_bv.writer().testBit(highest)) { updateHighest(highest); } } @@ -48,10 +48,9 @@ public: void clearBit(unsigned int idx); void consider_clear_bits(const std::vector<uint32_t>& idxs); void clear_bits(const std::vector<uint32_t>& idxs); - bool testBit(unsigned int idx) const { return _bv.testBit(idx); } - bool testBitSafe(unsigned int idx) const { return _bv.testBitSafe(idx); } - unsigned int size() const { return _bv.size(); } - unsigned int getSizeSafe() const { return _bv.getSizeSafe(); } + bool testBit(unsigned int idx) const { return _bv.reader().testBit(idx); } + bool testBitAcquire(unsigned int idx) const { return _bv.reader().testBitAcquire(idx); } + unsigned int size() const { return _bv.reader().size(); } unsigned int byteSize() const { return _bv.extraByteSize() + sizeof(LidStateVector); } @@ -65,14 +64,14 @@ public: */ uint32_t count() const { // Called by document db executor thread or metrics related threads - return _bv.countTrueBits(); + return _bv.reader().countTrueBits(); } unsigned int getNextTrueBit(unsigned int idx) const { - return _bv.getNextTrueBit(idx); + return _bv.reader().getNextTrueBit(idx); } - const search::GrowableBitVector &getBitVector() const { return _bv; } + const search::BitVector &getBitVector() const { return _bv.reader(); } }; } |