diff options
11 files changed, 133 insertions, 108 deletions
diff --git a/searchlib/src/tests/common/bitvector/bitvector_test.cpp b/searchlib/src/tests/common/bitvector/bitvector_test.cpp index 571ea80ef36..351890e94bf 100644 --- a/searchlib/src/tests/common/bitvector/bitvector_test.cpp +++ b/searchlib/src/tests/common/bitvector/bitvector_test.cpp @@ -645,45 +645,45 @@ TEST("requireThatGrowWorks") EXPECT_EQUAL(4u, v.writer().countTrueBits()); EXPECT_EQUAL(200u, v.reader().size()); - EXPECT_EQUAL(1023u, v.writer().capacity()); + EXPECT_EQUAL(2047u, v.writer().capacity()); EXPECT_TRUE(assertBV("[7,39,71,103]", v.reader())); EXPECT_EQUAL(4u, v.writer().countTrueBits()); - EXPECT_TRUE(v.reserve(1024)); + EXPECT_TRUE(v.reserve(2048u)); EXPECT_EQUAL(200u, v.reader().size()); - EXPECT_EQUAL(2047u, v.writer().capacity()); + EXPECT_EQUAL(4095u, v.writer().capacity()); EXPECT_TRUE(assertBV("[7,39,71,103]", v.reader())); EXPECT_EQUAL(4u, v.writer().countTrueBits()); EXPECT_FALSE(v.extend(202)); EXPECT_EQUAL(202u, v.reader().size()); - EXPECT_EQUAL(2047u, v.writer().capacity()); + EXPECT_EQUAL(4095u, v.writer().capacity()); EXPECT_TRUE(assertBV("[7,39,71,103]", v.reader())); EXPECT_EQUAL(4u, v.writer().countTrueBits()); EXPECT_FALSE(v.shrink(200)); EXPECT_EQUAL(200u, v.reader().size()); - EXPECT_EQUAL(2047u, v.writer().capacity()); + EXPECT_EQUAL(4095u, v.writer().capacity()); EXPECT_TRUE(assertBV("[7,39,71,103]", v.reader())); EXPECT_EQUAL(4u, v.writer().countTrueBits()); - EXPECT_FALSE(v.reserve(2047)); + EXPECT_FALSE(v.reserve(4095u)); EXPECT_EQUAL(200u, v.reader().size()); - EXPECT_EQUAL(2047u, v.writer().capacity()); + EXPECT_EQUAL(4095u, v.writer().capacity()); EXPECT_TRUE(assertBV("[7,39,71,103]", v.reader())); EXPECT_EQUAL(4u, v.writer().countTrueBits()); EXPECT_FALSE(v.shrink(202)); EXPECT_EQUAL(202u, v.reader().size()); - EXPECT_EQUAL(2047u, v.writer().capacity()); + EXPECT_EQUAL(4095u, v.writer().capacity()); EXPECT_TRUE(assertBV("[7,39,71,103]", v.reader())); EXPECT_EQUAL(4u, v.writer().countTrueBits()); EXPECT_FALSE(v.shrink(100)); EXPECT_EQUAL(100u, v.reader().size()); - EXPECT_EQUAL(2047u, v.writer().capacity()); + EXPECT_EQUAL(4095u, v.writer().capacity()); EXPECT_TRUE(assertBV("[7,39,71]", v.reader())); EXPECT_EQUAL(3u, v.writer().countTrueBits()); v.writer().invalidateCachedCount(); - EXPECT_TRUE(v.reserve(3100)); + EXPECT_TRUE(v.reserve(5100u)); EXPECT_EQUAL(100u, v.reader().size()); - EXPECT_EQUAL(4095u, v.writer().capacity()); + EXPECT_EQUAL(6143u, v.writer().capacity()); EXPECT_EQUAL(3u, v.writer().countTrueBits()); g.assign_generation(1); @@ -700,9 +700,9 @@ TEST("require that growable bit vectors keeps memory allocator") EXPECT_EQUAL(AllocStats(1, 0), stats); v.writer().resize(1); // DO NOT TRY THIS AT HOME EXPECT_EQUAL(AllocStats(2, 1), stats); - v.reserve(2000); + v.reserve(2048); EXPECT_EQUAL(AllocStats(3, 1), stats); - v.extend(4000); + v.extend(5000); EXPECT_EQUAL(AllocStats(4, 1), stats); v.shrink(200); EXPECT_EQUAL(AllocStats(4, 1), stats); diff --git a/searchlib/src/vespa/searchlib/common/CMakeLists.txt b/searchlib/src/vespa/searchlib/common/CMakeLists.txt index 970937e18ec..3270c170327 100644 --- a/searchlib/src/vespa/searchlib/common/CMakeLists.txt +++ b/searchlib/src/vespa/searchlib/common/CMakeLists.txt @@ -10,6 +10,7 @@ vespa_add_library(searchlib_common OBJECT documentlocations.cpp documentsummary.cpp fileheadercontext.cpp + fileheadertags.cpp flush_token.cpp geo_gcd.cpp geo_location.cpp diff --git a/searchlib/src/vespa/searchlib/common/bitvector.cpp b/searchlib/src/vespa/searchlib/common/bitvector.cpp index a75066a67a9..598bc01da9a 100644 --- a/searchlib/src/vespa/searchlib/common/bitvector.cpp +++ b/searchlib/src/vespa/searchlib/common/bitvector.cpp @@ -39,7 +39,7 @@ BitVector::allocatePaddedAndAligned(Index start, Index end, Index capacity, cons { assert(capacity >= end); uint32_t words = numActiveWords(start, capacity); - words += (-words & 15); // Pad to 128 byte alignment + words += (-words & (getAlignment()/sizeof(Word) - 1)); // Pad to required alignment const size_t sz(words * sizeof(Word)); Alloc alloc = (init_alloc != nullptr) ? init_alloc->create(sz) : Alloc::alloc(sz, MMAP_LIMIT); assert(alloc.size()/sizeof(Word) >= words); diff --git a/searchlib/src/vespa/searchlib/common/bitvector.h b/searchlib/src/vespa/searchlib/common/bitvector.h index 943db5f06ba..d69f2ac845b 100644 --- a/searchlib/src/vespa/searchlib/common/bitvector.h +++ b/searchlib/src/vespa/searchlib/common/bitvector.h @@ -281,6 +281,8 @@ public: static UP create(Index numberOfElements); static UP create(const BitVector & rhs); static void consider_enable_range_check(); + static Index numWords(Index bits) noexcept { return wordNum(bits + 1 + (WordLen - 1)); } + static Index numBytes(Index bits) noexcept { return numWords(bits) * sizeof(Word); } protected: using Alloc = vespalib::alloc::Alloc; VESPA_DLL_LOCAL BitVector(void * buf, Index start, Index end) noexcept; @@ -292,10 +294,8 @@ protected: VESPA_DLL_LOCAL void clearIntervalNoInvalidation(Range range); bool isValidCount() const noexcept { return isValidCount(_numTrueBits.load(std::memory_order_relaxed)); } static bool isValidCount(Index v) noexcept { return v != invalidCount(); } - static Index numWords(Index bits) noexcept { return wordNum(bits + 1 + (WordLen - 1)); } - static Index numBytes(Index bits) noexcept { return numWords(bits) * sizeof(Word); } size_t numWords() const noexcept { return numWords(size()); } - static constexpr size_t getAlignment() noexcept { return 0x40u; } + static constexpr size_t getAlignment() noexcept { return 0x100u; } static size_t numActiveBytes(Index start, Index end) noexcept { return numActiveWords(start, end) * sizeof(Word); } static Alloc allocatePaddedAndAligned(Index sz) { return allocatePaddedAndAligned(0, sz); diff --git a/searchlib/src/vespa/searchlib/common/fileheadercontext.cpp b/searchlib/src/vespa/searchlib/common/fileheadercontext.cpp index 77246e2b202..067d7aeaae9 100644 --- a/searchlib/src/vespa/searchlib/common/fileheadercontext.cpp +++ b/searchlib/src/vespa/searchlib/common/fileheadercontext.cpp @@ -1,6 +1,7 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "fileheadercontext.h" +#include "fileheadertags.h" #include <vespa/vespalib/data/fileheader.h> #include <chrono> @@ -9,6 +10,7 @@ using namespace std::chrono; namespace search::common { using vespalib::GenericHeader; +using namespace tags; FileHeaderContext::FileHeaderContext() = default; @@ -18,17 +20,17 @@ void FileHeaderContext::addCreateAndFreezeTime(GenericHeader &header) { using Tag = GenericHeader::Tag; - header.putTag(Tag("createTime", duration_cast<microseconds>(system_clock::now().time_since_epoch()).count())); - header.putTag(Tag("freezeTime", 0)); + header.putTag(Tag(CREATE_TIME, duration_cast<microseconds>(system_clock::now().time_since_epoch()).count())); + header.putTag(Tag(FREEZE_TIME, 0)); } void FileHeaderContext::setFreezeTime(GenericHeader &header) { using Tag = GenericHeader::Tag; - if (header.hasTag("freezeTime") && - header.getTag("freezeTime").getType() == Tag::TYPE_INTEGER) { - header.putTag(Tag("freezeTime", duration_cast<microseconds>(system_clock::now().time_since_epoch()).count())); + if (header.hasTag(FREEZE_TIME) && + header.getTag(FREEZE_TIME).getType() == Tag::TYPE_INTEGER) { + header.putTag(Tag(FREEZE_TIME, duration_cast<microseconds>(system_clock::now().time_since_epoch()).count())); } } diff --git a/searchlib/src/vespa/searchlib/common/fileheadertags.cpp b/searchlib/src/vespa/searchlib/common/fileheadertags.cpp new file mode 100644 index 00000000000..aaef218a98b --- /dev/null +++ b/searchlib/src/vespa/searchlib/common/fileheadertags.cpp @@ -0,0 +1,16 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "fileheadertags.h" + +namespace search::tags { +// Do not change these constants, they are persisted in many file headers. +vespalib::string FREEZE_TIME("freezeTime"); +vespalib::string CREATE_TIME("createTime"); +vespalib::string FROZEN("frozen"); +vespalib::string DOCID_LIMIT("docidLimit"); +vespalib::string FILE_BIT_SIZE("fileBitSize"); +vespalib::string DESC("desc"); +vespalib::string ENTRY_SIZE("entrySize"); +vespalib::string NUM_KEYS("numKeys"); + +} diff --git a/searchlib/src/vespa/searchlib/common/fileheadertags.h b/searchlib/src/vespa/searchlib/common/fileheadertags.h new file mode 100644 index 00000000000..c7e7385160e --- /dev/null +++ b/searchlib/src/vespa/searchlib/common/fileheadertags.h @@ -0,0 +1,17 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#pragma once + +#include <vespa/vespalib/stllike/string.h> + +namespace search::tags { + +extern vespalib::string FREEZE_TIME; +extern vespalib::string CREATE_TIME; +extern vespalib::string FROZEN; +extern vespalib::string DOCID_LIMIT; +extern vespalib::string FILE_BIT_SIZE; +extern vespalib::string DESC; +extern vespalib::string ENTRY_SIZE; +extern vespalib::string NUM_KEYS; + +} diff --git a/searchlib/src/vespa/searchlib/diskindex/bitvectordictionary.cpp b/searchlib/src/vespa/searchlib/diskindex/bitvectordictionary.cpp index f2a7ec4d88b..b5c07dca923 100644 --- a/searchlib/src/vespa/searchlib/diskindex/bitvectordictionary.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/bitvectordictionary.cpp @@ -1,6 +1,7 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "bitvectordictionary.h" +#include <vespa/searchlib/common/fileheadertags.h> #include <vespa/vespalib/data/fileheader.h> #include <vespa/fastos/file.h> #include <cassert> @@ -10,10 +11,12 @@ LOG_SETUP(".diskindex.bitvectordictionary"); namespace search::diskindex { +using namespace tags; + BitVectorDictionary::BitVectorDictionary() - : _docIdLimit(), + : _docIdLimit(0u), _entries(), - _vectorSize(), + _vectorSize(0u), _datFile(), _datHeaderLen(0u) { } @@ -27,27 +30,32 @@ BitVectorDictionary::open(const vespalib::string &pathPrefix, const TuneFileRandRead &tuneFileRead, BitVectorKeyScope scope) { - vespalib::string booloccIdxName = pathPrefix + "boolocc" + - getBitVectorKeyScopeSuffix(scope); + vespalib::string booloccIdxName = pathPrefix + "boolocc" + getBitVectorKeyScopeSuffix(scope); vespalib::string booloccDatName = pathPrefix + "boolocc.bdat"; { FastOS_File idxFile; idxFile.OpenReadOnly(booloccIdxName.c_str()); if (!idxFile.IsOpened()) { - LOG(warning, "Could not open bitvector idx file '%s'", - booloccIdxName.c_str()); + LOG(warning, "Could not open bitvector idx file '%s'", booloccIdxName.c_str()); return false; } vespalib::FileHeader idxHeader; uint32_t idxHeaderLen = idxHeader.readFile(idxFile); idxFile.SetPosition(idxHeaderLen); - assert(idxHeader.hasTag("frozen")); - assert(idxHeader.hasTag("docIdLimit")); - assert(idxHeader.hasTag("numKeys")); - assert(idxHeader.getTag("frozen").asInteger() != 0); - _docIdLimit = idxHeader.getTag("docIdLimit").asInteger(); - uint32_t numEntries = idxHeader.getTag("numKeys").asInteger(); + assert(idxHeader.hasTag(FROZEN)); + assert(idxHeader.hasTag(DOCID_LIMIT)); + assert(idxHeader.hasTag(NUM_KEYS)); + assert(idxHeader.getTag(FROZEN).asInteger() != 0); + _docIdLimit = idxHeader.getTag(DOCID_LIMIT).asInteger(); + uint32_t numEntries = idxHeader.getTag(NUM_KEYS).asInteger(); + if (idxHeader.hasTag(ENTRY_SIZE)) { + _vectorSize = idxHeader.getTag(ENTRY_SIZE).asInteger(); + } else { + constexpr size_t LEGACY_ALIGNMENT = 0x40; + BitVector::Index bytes = BitVector::numBytes(_docIdLimit); + _vectorSize = bytes + (-bytes & (LEGACY_ALIGNMENT - 1)); + } _entries.resize(numEntries); size_t bufSize = sizeof(WordSingleKey) * numEntries; @@ -69,14 +77,12 @@ BitVectorDictionary::open(const vespalib::string &pathPrefix, } _datFile->OpenReadOnly(booloccDatName.c_str()); if (!_datFile->IsOpened()) { - LOG(warning, "Could not open bitvector dat file '%s'", - booloccDatName.c_str()); + LOG(warning, "Could not open bitvector dat file '%s'", booloccDatName.c_str()); return false; } vespalib::FileHeader datHeader(64); _datHeaderLen = datHeader.readFile(*_datFile); - assert(_datFile->getSize() >= - static_cast<int64_t>(_vectorSize * _entries.size() + _datHeaderLen)); + assert(_datFile->getSize() >= static_cast<int64_t>(_vectorSize * _entries.size() + _datHeaderLen)); return true; } @@ -88,12 +94,10 @@ BitVectorDictionary::lookup(uint64_t wordNum) key._wordNum = wordNum; auto itr = std::lower_bound(_entries.begin(), _entries.end(), key); if (itr == _entries.end() || key < *itr) { - return BitVector::UP(); + return {}; } int64_t pos = &*itr - &_entries[0]; - return BitVector::create(_docIdLimit, *_datFile, - ((int64_t) _vectorSize) * pos + _datHeaderLen, - itr->_numDocs); + return BitVector::create(_docIdLimit, *_datFile, ((int64_t) _vectorSize) * pos + _datHeaderLen, itr->_numDocs); } } diff --git a/searchlib/src/vespa/searchlib/diskindex/bitvectorfile.cpp b/searchlib/src/vespa/searchlib/diskindex/bitvectorfile.cpp index e78b740c837..d2129ed81d5 100644 --- a/searchlib/src/vespa/searchlib/diskindex/bitvectorfile.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/bitvectorfile.cpp @@ -3,6 +3,7 @@ #include "bitvectorfile.h" #include <vespa/searchlib/common/bitvector.h> #include <vespa/searchlib/common/fileheadercontext.h> +#include <vespa/searchlib/common/fileheadertags.h> #include <vespa/searchlib/index/bitvectorkeys.h> #include <vespa/searchlib/util/file_settings.h> #include <vespa/vespalib/data/fileheader.h> @@ -14,12 +15,12 @@ namespace search::diskindex { using search::index::BitVectorWordSingleKey; using search::common::FileHeaderContext; +using namespace tags; namespace { void -readHeader(vespalib::FileHeader &h, - const vespalib::string &name) +readHeader(vespalib::FileHeader &h, const vespalib::string &name) { Fast_BufferedFile file(32_Ki); file.ReadOpenExisting(name.c_str()); @@ -35,13 +36,10 @@ BitVectorFileWrite::BitVectorFileWrite(BitVectorKeyScope scope) { } - BitVectorFileWrite::~BitVectorFileWrite() = default; - void -BitVectorFileWrite::open(const vespalib::string &name, - uint32_t docIdLimit, +BitVectorFileWrite::open(const vespalib::string &name, uint32_t docIdLimit, const TuneFileSeqWrite &tuneFileWrite, const FileHeaderContext &fileHeaderContext) { @@ -65,18 +63,10 @@ BitVectorFileWrite::open(const vespalib::string &name, makeDatHeader(fileHeaderContext); } - int64_t pos; - size_t bitmapbytes; - - bitmapbytes = BitVector::getFileBytes(_docIdLimit); - - pos = static_cast<int64_t>(_numKeys) * - static_cast<int64_t>(bitmapbytes) + _datHeaderLen; - - int64_t olddatsize = _datFile->getSize(); - assert(olddatsize >= pos); - (void) olddatsize; + size_t bitmapbytes = BitVector::getFileBytes(_docIdLimit); + int64_t pos = static_cast<int64_t>(_numKeys) * static_cast<int64_t>(bitmapbytes) + _datHeaderLen; + assert(_datFile->getSize() >= pos); _datFile->SetSize(pos); assert(pos == _datFile->getPosition()); @@ -89,11 +79,12 @@ BitVectorFileWrite::makeDatHeader(const FileHeaderContext &fileHeaderContext) vespalib::FileHeader h(FileSettings::DIRECTIO_ALIGNMENT); using Tag = vespalib::GenericHeader::Tag; fileHeaderContext.addTags(h, _datFile->GetFileName()); - h.putTag(Tag("docIdLimit", _docIdLimit)); - h.putTag(Tag("numKeys", _numKeys)); - h.putTag(Tag("frozen", 0)); - h.putTag(Tag("fileBitSize", 0)); - h.putTag(Tag("desc", "Bitvector data file")); + h.putTag(Tag(ENTRY_SIZE, BitVector::getFileBytes(_docIdLimit))); + h.putTag(Tag(DOCID_LIMIT, _docIdLimit)); + h.putTag(Tag(NUM_KEYS, _numKeys)); + h.putTag(Tag(FROZEN, 0)); + h.putTag(Tag(FILE_BIT_SIZE, 0)); + h.putTag(Tag(DESC, "Bitvector data file")); _datFile->SetPosition(0); _datHeaderLen = h.writeFile(*_datFile); _datFile->Flush(); @@ -107,9 +98,9 @@ BitVectorFileWrite::updateDatHeader(uint64_t fileBitSize) using Tag = vespalib::GenericHeader::Tag; readHeader(h, _datFile->GetFileName()); FileHeaderContext::setFreezeTime(h); - h.putTag(Tag("numKeys", _numKeys)); - h.putTag(Tag("frozen", 1)); - h.putTag(Tag("fileBitSize", fileBitSize)); + h.putTag(Tag(NUM_KEYS, _numKeys)); + h.putTag(Tag(FROZEN, 1)); + h.putTag(Tag(FILE_BIT_SIZE, fileBitSize)); bool sync_ok = _datFile->Sync(); assert(sync_ok); assert(h.getSize() == _datHeaderLen); @@ -121,14 +112,12 @@ BitVectorFileWrite::updateDatHeader(uint64_t fileBitSize) void -BitVectorFileWrite::addWordSingle(uint64_t wordNum, - const BitVector &bitVector) +BitVectorFileWrite::addWordSingle(uint64_t wordNum, const BitVector &bitVector) { assert(bitVector.size() == _docIdLimit); bitVector.invalidateCachedCount(); Parent::addWordSingle(wordNum, bitVector.countTrueBits()); - _datFile->WriteBuf(bitVector.getStart(), - bitVector.getFileBytes()); + _datFile->WriteBuf(bitVector.getStart(), bitVector.getFileBytes()); } @@ -153,21 +142,17 @@ BitVectorFileWrite::sync() void BitVectorFileWrite::close() { - size_t bitmapbytes = BitVector::getFileBytes(_docIdLimit); - - if (_datFile != nullptr) { - if (_datFile->IsOpened()) { - uint64_t pos = _datFile->getPosition(); - assert(pos == static_cast<uint64_t>(_numKeys) * - static_cast<uint64_t>(bitmapbytes) + _datHeaderLen); - (void) bitmapbytes; - _datFile->alignEndForDirectIO(); - updateDatHeader(pos * 8); - bool close_ok = _datFile->Close(); - assert(close_ok); - } - _datFile.reset(); + if (_datFile && _datFile->IsOpened()) { + size_t bitmapbytes = BitVector::getFileBytes(_docIdLimit); + uint64_t pos = _datFile->getPosition(); + assert(pos == static_cast<uint64_t>(_numKeys) * static_cast<uint64_t>(bitmapbytes) + _datHeaderLen); + (void) bitmapbytes; + _datFile->alignEndForDirectIO(); + updateDatHeader(pos * 8); + bool close_ok = _datFile->Close(); + assert(close_ok); } + _datFile.reset(); Parent::close(); } diff --git a/searchlib/src/vespa/searchlib/diskindex/bitvectoridxfile.cpp b/searchlib/src/vespa/searchlib/diskindex/bitvectoridxfile.cpp index ec436205578..e4f70484fac 100644 --- a/searchlib/src/vespa/searchlib/diskindex/bitvectoridxfile.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/bitvectoridxfile.cpp @@ -2,6 +2,7 @@ #include "bitvectoridxfile.h" #include <vespa/searchlib/common/fileheadercontext.h> +#include <vespa/searchlib/common/fileheadertags.h> #include <vespa/searchlib/index/bitvectorkeys.h> #include <vespa/searchlib/util/file_settings.h> #include <vespa/vespalib/data/fileheader.h> @@ -13,6 +14,7 @@ namespace search::diskindex { using search::index::BitVectorWordSingleKey; using search::common::FileHeaderContext; +using namespace tags; namespace { @@ -45,10 +47,9 @@ BitVectorIdxFileWrite::idxSize() const } void -BitVectorIdxFileWrite::open(const vespalib::string &name, - uint32_t docIdLimit, - const TuneFileSeqWrite &tuneFileWrite, - const FileHeaderContext &fileHeaderContext) +BitVectorIdxFileWrite::open(const vespalib::string &name, uint32_t docIdLimit, + const TuneFileSeqWrite &tuneFileWrite, + const FileHeaderContext &fileHeaderContext) { if (_numKeys != 0) { assert(docIdLimit == _docIdLimit); @@ -90,13 +91,14 @@ BitVectorIdxFileWrite::makeIdxHeader(const FileHeaderContext &fileHeaderContext) vespalib::FileHeader h(FileSettings::DIRECTIO_ALIGNMENT); using Tag = vespalib::GenericHeader::Tag; fileHeaderContext.addTags(h, _idxFile->GetFileName()); - h.putTag(Tag("docIdLimit", _docIdLimit)); - h.putTag(Tag("numKeys", _numKeys)); - h.putTag(Tag("frozen", 0)); + h.putTag(Tag(ENTRY_SIZE, BitVector::getFileBytes(_docIdLimit))); + h.putTag(Tag(DOCID_LIMIT, _docIdLimit)); + h.putTag(Tag(NUM_KEYS, _numKeys)); + h.putTag(Tag(FROZEN, 0)); if (_scope != BitVectorKeyScope::SHARED_WORDS) { - h.putTag(Tag("fileBitSize", 0)); + h.putTag(Tag(FILE_BIT_SIZE, 0)); } - h.putTag(Tag("desc", "Bitvector dictionary file, single words")); + h.putTag(Tag(DESC, "Bitvector dictionary file, single words")); _idxFile->SetPosition(0); _idxHeaderLen = h.writeFile(*_idxFile); _idxFile->Flush(); @@ -109,10 +111,10 @@ BitVectorIdxFileWrite::updateIdxHeader(uint64_t fileBitSize) using Tag = vespalib::GenericHeader::Tag; readHeader(h, _idxFile->GetFileName()); FileHeaderContext::setFreezeTime(h); - h.putTag(Tag("numKeys", _numKeys)); - h.putTag(Tag("frozen", 1)); + h.putTag(Tag(NUM_KEYS, _numKeys)); + h.putTag(Tag(FROZEN, 1)); if (_scope != BitVectorKeyScope::SHARED_WORDS) { - h.putTag(Tag("fileBitSize", fileBitSize)); + h.putTag(Tag(FILE_BIT_SIZE, fileBitSize)); } bool sync_ok = _idxFile->Sync(); assert(sync_ok); @@ -160,17 +162,15 @@ BitVectorIdxFileWrite::sync() void BitVectorIdxFileWrite::close() { - if (_idxFile) { - if (_idxFile->IsOpened()) { - uint64_t pos = _idxFile->getPosition(); - assert(pos == idxSize()); - _idxFile->alignEndForDirectIO(); - updateIdxHeader(pos * 8); - bool close_ok = _idxFile->Close(); - assert(close_ok); - } - _idxFile.reset(); + if (_idxFile && _idxFile->IsOpened()) { + uint64_t pos = _idxFile->getPosition(); + assert(pos == idxSize()); + _idxFile->alignEndForDirectIO(); + updateIdxHeader(pos * 8); + bool close_ok = _idxFile->Close(); + assert(close_ok); } + _idxFile.reset(); } } diff --git a/searchlib/src/vespa/searchlib/diskindex/bitvectoridxfile.h b/searchlib/src/vespa/searchlib/diskindex/bitvectoridxfile.h index 533f5620ea2..9f1e5ce0f80 100644 --- a/searchlib/src/vespa/searchlib/diskindex/bitvectoridxfile.h +++ b/searchlib/src/vespa/searchlib/diskindex/bitvectoridxfile.h @@ -2,10 +2,10 @@ #pragma once +#include "bitvectorkeyscope.h" #include <vespa/searchlib/common/bitvector.h> #include <vespa/searchlib/common/tunefileinfo.h> #include <vespa/vespalib/stllike/string.h> -#include "bitvectorkeyscope.h" class Fast_BufferedFile; |