summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2024-02-09 14:05:52 +0100
committerGitHub <noreply@github.com>2024-02-09 14:05:52 +0100
commit6a99659d85bc9d8f4303b168a809d424d7130218 (patch)
treec6b44aad9ec4061313ea1f1f48d832a05fe6cf38
parent097d6e69ba67f0d06b285148c6cc64cb39d788be (diff)
parentffb88643646c0304850971a39c38f96b46b88217 (diff)
Merge pull request #30227 from vespa-engine/balder/reduce-buffer-size-and-gc-some-unused-code
Use smaller buffer for reading file headers. And GC some unused code.
-rw-r--r--searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp3
-rw-r--r--searchcore/src/vespa/searchcorespi/index/indexreadutilities.cpp9
-rw-r--r--searchcore/src/vespa/searchcorespi/index/indexwriteutilities.cpp41
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attributevector.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/sourceselector.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/common/documentsummary.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/diskindex/bitvectorfile.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/diskindex/bitvectoridxfile.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/diskindex/dictionarywordreader.cpp8
-rw-r--r--searchlib/src/vespa/searchlib/diskindex/diskindex.cpp40
-rw-r--r--searchlib/src/vespa/searchlib/diskindex/indexbuilder.cpp9
-rw-r--r--searchlib/src/vespa/searchlib/diskindex/indexbuilder.h1
-rw-r--r--searchlib/src/vespa/searchlib/diskindex/wordnummapper.cpp2
-rw-r--r--vespalib/src/vespa/fastlib/io/bufferedfile.cpp9
-rw-r--r--vespalib/src/vespa/fastlib/io/bufferedfile.h57
-rw-r--r--vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp4
-rw-r--r--vespalib/src/vespa/vespalib/util/mmap_file_allocator.h14
17 files changed, 80 insertions, 127 deletions
diff --git a/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp b/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp
index f7f5b2328c4..9ab8f4829a0 100644
--- a/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp
+++ b/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp
@@ -14,7 +14,6 @@
#include <getopt.h>
#include <vector>
#include <limits>
-#include <unistd.h>
#include <filesystem>
#include <vespa/log/log.h>
@@ -552,7 +551,7 @@ DocumentGenerator::generate(uint32_t docMin, uint32_t docIdLimit,
{
string fullName(prependBaseDir(baseDir, feedFileName));
std::filesystem::remove(std::filesystem::path(fullName));
- Fast_BufferedFile f(new FastOS_File);
+ Fast_BufferedFile f;
f.WriteOpen(fullName.c_str());
if (json) {
bool first = true;
diff --git a/searchcore/src/vespa/searchcorespi/index/indexreadutilities.cpp b/searchcore/src/vespa/searchcorespi/index/indexreadutilities.cpp
index d3f45ec081b..6683e9aa935 100644
--- a/searchcore/src/vespa/searchcorespi/index/indexreadutilities.cpp
+++ b/searchcore/src/vespa/searchcorespi/index/indexreadutilities.cpp
@@ -36,8 +36,7 @@ scanForIndexes(const vespalib::string &baseDir,
if (name.find(IndexDiskLayout::FusionDirPrefix) == 0) {
if (!fusionDir.empty()) {
// Should never happen, since we run cleanup before load.
- LOG(warning, "Base directory '%s' contains multiple fusion indexes",
- baseDir.c_str());
+ LOG(warning, "Base directory '%s' contains multiple fusion indexes", baseDir.c_str());
}
fusionDir = name;
}
@@ -59,8 +58,8 @@ IndexReadUtilities::readFusionSpec(const vespalib::string &baseDir)
fusionId = atoi(fusionDir.substr(IndexDiskLayout::FusionDirPrefix.size()).c_str());
}
std::set<uint32_t> flushIds;
- for (size_t i = 0; i < flushDirs.size(); ++i) {
- uint32_t id = atoi(flushDirs[i].substr(IndexDiskLayout::FlushDirPrefix.size()).c_str());
+ for (const auto & flushDir : flushDirs) {
+ uint32_t id = atoi(flushDir.substr(IndexDiskLayout::FlushDirPrefix.size()).c_str());
flushIds.insert(id);
}
@@ -74,7 +73,7 @@ SerialNum
IndexReadUtilities::readSerialNum(const vespalib::string &dir)
{
const vespalib::string fileName = IndexDiskLayout::getSerialNumFileName(dir);
- Fast_BufferedFile file;
+ Fast_BufferedFile file(16_Ki);
file.ReadOpen(fileName.c_str());
FileHeader fileHeader;
diff --git a/searchcore/src/vespa/searchcorespi/index/indexwriteutilities.cpp b/searchcore/src/vespa/searchcorespi/index/indexwriteutilities.cpp
index d2f77cfaf29..dfef52cc8e8 100644
--- a/searchcore/src/vespa/searchcorespi/index/indexwriteutilities.cpp
+++ b/searchcore/src/vespa/searchcorespi/index/indexwriteutilities.cpp
@@ -40,12 +40,11 @@ IndexWriteUtilities::writeSerialNum(SerialNum serialNum,
const vespalib::string &dir,
const FileHeaderContext &fileHeaderContext)
{
- const vespalib::string fileName =
- IndexDiskLayout::getSerialNumFileName(dir);
+ const vespalib::string fileName = IndexDiskLayout::getSerialNumFileName(dir);
const vespalib::string tmpFileName = fileName + ".tmp";
SerialNumFileHeaderContext snFileHeaderContext(fileHeaderContext, serialNum);
- Fast_BufferedFile file;
+ Fast_BufferedFile file(16_Ki);
file.WriteOpen(tmpFileName.c_str());
FileHeader fileHeader;
snFileHeaderContext.addTags(fileHeader, fileName);
@@ -103,17 +102,13 @@ IndexWriteUtilities::copySerialNumFile(const vespalib::string &sourceDir,
}
void
-IndexWriteUtilities::writeSourceSelector(FixedSourceSelector::SaveInfo &
- saveInfo,
+IndexWriteUtilities::writeSourceSelector(FixedSourceSelector::SaveInfo & saveInfo,
uint32_t sourceId,
- const TuneFileAttributes &
- tuneFileAttributes,
- const FileHeaderContext &
- fileHeaderContext,
+ const TuneFileAttributes & tuneFileAttributes,
+ const FileHeaderContext & fileHeaderContext,
SerialNum serialNum)
{
- SerialNumFileHeaderContext snFileHeaderContext(fileHeaderContext,
- serialNum);
+ SerialNumFileHeaderContext snFileHeaderContext(fileHeaderContext, serialNum);
if (!saveInfo.save(tuneFileAttributes, snFileHeaderContext)) {
std::ostringstream msg;
msg << "Flush of sourceselector failed. Source id = " << sourceId;
@@ -122,20 +117,16 @@ IndexWriteUtilities::writeSourceSelector(FixedSourceSelector::SaveInfo &
}
void
-IndexWriteUtilities::updateDiskIndexSchema(const vespalib::string &indexDir,
- const Schema &schema,
- SerialNum serialNum)
+IndexWriteUtilities::updateDiskIndexSchema(const vespalib::string &indexDir, const Schema &schema, SerialNum serialNum)
{
vespalib::string schemaName = IndexDiskLayout::getSchemaFileName(indexDir);
Schema oldSchema;
if (!oldSchema.loadFromFile(schemaName)) {
- LOG(error, "Could not open schema '%s'",
- schemaName.c_str());
+ LOG(error, "Could not open schema '%s'", schemaName.c_str());
return;
}
if (!SchemaUtil::validateSchema(oldSchema)) {
- LOG(error, "Could not validate schema loaded from '%s'",
- schemaName.c_str());
+ LOG(error, "Could not validate schema loaded from '%s'", schemaName.c_str());
return;
}
Schema::UP newSchema = Schema::intersect(oldSchema, schema);
@@ -152,8 +143,7 @@ IndexWriteUtilities::updateDiskIndexSchema(const vespalib::string &indexDir,
vespalib::string schemaOrigName = schemaName + ".orig";
fs::remove(fs::path(schemaTmpName));
if (!newSchema->saveToFile(schemaTmpName)) {
- LOG(error, "Could not save schema to '%s'",
- schemaTmpName.c_str());
+ LOG(error, "Could not save schema to '%s'", schemaTmpName.c_str());
}
FastOS_StatInfo statInfo;
bool statres;
@@ -161,15 +151,12 @@ IndexWriteUtilities::updateDiskIndexSchema(const vespalib::string &indexDir,
if (!statres) {
if (statInfo._error != FastOS_StatInfo::FileNotFound) {
LOG(error, "Failed to stat orig schema '%s': %s",
- schemaOrigName.c_str(),
- FastOS_File::getLastErrorString().c_str());
+ schemaOrigName.c_str(), FastOS_File::getLastErrorString().c_str());
}
int linkres = ::link(schemaName.c_str(), schemaOrigName.c_str());
if (linkres != 0) {
LOG(error, "Could not link '%s' to '%s': %s",
- schemaOrigName.c_str(),
- schemaName.c_str(),
- FastOS_File::getLastErrorString().c_str());
+ schemaOrigName.c_str(), schemaName.c_str(), FastOS_File::getLastErrorString().c_str());
}
vespalib::File::sync(indexDir);
}
@@ -178,9 +165,7 @@ IndexWriteUtilities::updateDiskIndexSchema(const vespalib::string &indexDir,
int error = errno;
std::string errString = FastOS_File::getErrorString(error);
LOG(error, "Could not rename '%s' to '%s': %s",
- schemaTmpName.c_str(),
- schemaName.c_str(),
- errString.c_str());
+ schemaTmpName.c_str(), schemaName.c_str(), errString.c_str());
}
vespalib::File::sync(indexDir);
}
diff --git a/searchlib/src/vespa/searchlib/attribute/attributevector.cpp b/searchlib/src/vespa/searchlib/attribute/attributevector.cpp
index 4654cf435b1..dcf627b0ce2 100644
--- a/searchlib/src/vespa/searchlib/attribute/attributevector.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/attributevector.cpp
@@ -328,7 +328,7 @@ bool
AttributeVector::isEnumeratedSaveFormat() const
{
vespalib::string datName(fmt("%s.dat", getBaseFileName().c_str()));
- Fast_BufferedFile datFile;
+ Fast_BufferedFile datFile(16_Ki);
vespalib::FileHeader datHeader(FileSettings::DIRECTIO_ALIGNMENT);
if ( ! datFile.OpenReadOnly(datName.c_str()) ) {
LOG(error, "could not open %s: %s", datFile.GetFileName(), getLastErrorString().c_str());
diff --git a/searchlib/src/vespa/searchlib/attribute/sourceselector.cpp b/searchlib/src/vespa/searchlib/attribute/sourceselector.cpp
index 907d54467c1..77c86e21b2a 100644
--- a/searchlib/src/vespa/searchlib/attribute/sourceselector.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/sourceselector.cpp
@@ -81,7 +81,7 @@ void
SourceSelector::LoadInfo::load()
{
const vespalib::string fileName = _header._baseFileName + ".dat";
- Fast_BufferedFile file;
+ Fast_BufferedFile file(16_Ki);
// XXX no checking for success
file.ReadOpen(fileName.c_str());
diff --git a/searchlib/src/vespa/searchlib/common/documentsummary.cpp b/searchlib/src/vespa/searchlib/common/documentsummary.cpp
index f004e5cc4cf..9341cf92b89 100644
--- a/searchlib/src/vespa/searchlib/common/documentsummary.cpp
+++ b/searchlib/src/vespa/searchlib/common/documentsummary.cpp
@@ -40,7 +40,7 @@ bool
DocumentSummary::writeDocIdLimit(const vespalib::string &dir, uint32_t count)
{
vespalib::string qcntname = dir + "/docsum.qcnt";
- Fast_BufferedFile qcntfile(new FastOS_File);
+ Fast_BufferedFile qcntfile(4_Ki);
qcntfile.WriteOpen(qcntname.c_str());
if (!qcntfile.IsOpened()) {
diff --git a/searchlib/src/vespa/searchlib/diskindex/bitvectorfile.cpp b/searchlib/src/vespa/searchlib/diskindex/bitvectorfile.cpp
index fc7fd9c2fb7..8c47e5c193e 100644
--- a/searchlib/src/vespa/searchlib/diskindex/bitvectorfile.cpp
+++ b/searchlib/src/vespa/searchlib/diskindex/bitvectorfile.cpp
@@ -49,7 +49,7 @@ BitVectorFileWrite::open(const vespalib::string &name, uint32_t docIdLimit,
Parent::open(name, docIdLimit, tuneFileWrite, fileHeaderContext);
- _datFile = std::make_unique<Fast_BufferedFile>(new FastOS_File);
+ _datFile = std::make_unique<Fast_BufferedFile>();
if (tuneFileWrite.getWantSyncWrites()) {
_datFile->EnableSyncWrites();
}
diff --git a/searchlib/src/vespa/searchlib/diskindex/bitvectoridxfile.cpp b/searchlib/src/vespa/searchlib/diskindex/bitvectoridxfile.cpp
index 7e3f0f5f258..cec3db35d60 100644
--- a/searchlib/src/vespa/searchlib/diskindex/bitvectoridxfile.cpp
+++ b/searchlib/src/vespa/searchlib/diskindex/bitvectoridxfile.cpp
@@ -59,7 +59,7 @@ BitVectorIdxFileWrite::open(const vespalib::string &name, uint32_t docIdLimit,
vespalib::string idxname = name + getBitVectorKeyScopeSuffix(_scope);
assert( !_idxFile);
- _idxFile = std::make_unique<Fast_BufferedFile>(new FastOS_File());
+ _idxFile = std::make_unique<Fast_BufferedFile>();
if (tuneFileWrite.getWantSyncWrites()) {
_idxFile->EnableSyncWrites();
}
diff --git a/searchlib/src/vespa/searchlib/diskindex/dictionarywordreader.cpp b/searchlib/src/vespa/searchlib/diskindex/dictionarywordreader.cpp
index 1392f47525e..19741b3b166 100644
--- a/searchlib/src/vespa/searchlib/diskindex/dictionarywordreader.cpp
+++ b/searchlib/src/vespa/searchlib/diskindex/dictionarywordreader.cpp
@@ -6,6 +6,8 @@
#include <vespa/fastlib/io/bufferedfile.h>
#include <vespa/log/log.h>
+
+#include <memory>
LOG_SETUP(".diskindex.dictionarywordreader");
namespace search::diskindex {
@@ -21,17 +23,15 @@ DictionaryWordReader::DictionaryWordReader()
{
}
-
DictionaryWordReader::~DictionaryWordReader() = default;
-
bool
DictionaryWordReader::open(const vespalib::string & dictionaryName,
const vespalib::string & wordMapName,
const TuneFileSeqRead &tuneFileRead)
{
- _old2newwordfile.reset(new Fast_BufferedFile(new FastOS_File));
- _dictFile.reset(new PageDict4FileSeqRead);
+ _old2newwordfile = std::make_unique<Fast_BufferedFile>();
+ _dictFile = std::make_unique<PageDict4FileSeqRead>();
if (!_dictFile->open(dictionaryName, tuneFileRead)) {
LOG(error, "Could not open dictionary %s: %s",
dictionaryName.c_str(), getLastErrorString().c_str());
diff --git a/searchlib/src/vespa/searchlib/diskindex/diskindex.cpp b/searchlib/src/vespa/searchlib/diskindex/diskindex.cpp
index bf295acec75..105151d8132 100644
--- a/searchlib/src/vespa/searchlib/diskindex/diskindex.cpp
+++ b/searchlib/src/vespa/searchlib/diskindex/diskindex.cpp
@@ -121,26 +121,20 @@ DiskIndex::openField(const vespalib::string &fieldDir,
DiskPostingFileReal::getSubIdentifier()) {
dynamicK = false;
} else {
- LOG(warning,
- "Could not detect format for posocc file read %s",
- postingName.c_str());
+ LOG(warning, "Could not detect format for posocc file read %s", postingName.c_str());
}
}
- pFile.reset(dynamicK ?
- new DiskPostingFileDynamicKReal() :
- new DiskPostingFileReal());
+ pFile.reset(dynamicK
+ ? new DiskPostingFileDynamicKReal()
+ : new DiskPostingFileReal());
if (!pFile->open(postingName, tuneFileSearch._read)) {
- LOG(warning,
- "Could not open posting list file '%s'",
- postingName.c_str());
+ LOG(warning, "Could not open posting list file '%s'", postingName.c_str());
return false;
}
bDict.reset(new BitVectorDictionary());
if (!bDict->open(fieldDir, tuneFileSearch._read, BitVectorKeyScope::PERFIELD_WORDS)) {
- LOG(warning,
- "Could not open bit vector dictionary in '%s'",
- fieldDir.c_str());
+ LOG(warning, "Could not open bit vector dictionary in '%s'", fieldDir.c_str());
return false;
}
_postingFiles.push_back(pFile);
@@ -158,8 +152,7 @@ DiskIndex::setup(const TuneFileSearch &tuneFileSearch)
return false;
}
for (SchemaUtil::IndexIterator itr(_schema); itr.isValid(); ++itr) {
- vespalib::string fieldDir =
- _indexDir + "/" + itr.getName() + "/";
+ vespalib::string fieldDir = _indexDir + "/" + itr.getName() + "/";
if (!openField(fieldDir, tuneFileSearch)) {
return false;
}
@@ -169,8 +162,7 @@ DiskIndex::setup(const TuneFileSearch &tuneFileSearch)
}
bool
-DiskIndex::setup(const TuneFileSearch &tuneFileSearch,
- const DiskIndex &old)
+DiskIndex::setup(const TuneFileSearch &tuneFileSearch, const DiskIndex &old)
{
if (tuneFileSearch != old._tuneFileSearch) {
return setup(tuneFileSearch);
@@ -180,8 +172,7 @@ DiskIndex::setup(const TuneFileSearch &tuneFileSearch,
}
const Schema &oldSchema = old._schema;
for (SchemaUtil::IndexIterator itr(_schema); itr.isValid(); ++itr) {
- vespalib::string fieldDir =
- _indexDir + "/" + itr.getName() + "/";
+ vespalib::string fieldDir = _indexDir + "/" + itr.getName() + "/";
SchemaUtil::IndexSettings settings = itr.getIndexSettings();
if (settings.hasError()) {
return false;
@@ -336,12 +327,11 @@ DiskIndex::LookupResult G_nothing;
class LookupCache {
public:
- LookupCache(DiskIndex & diskIndex, const std::vector<uint32_t> & fieldIds) :
- _diskIndex(diskIndex),
- _fieldIds(fieldIds),
- _cache()
- {
- }
+ LookupCache(DiskIndex & diskIndex, const std::vector<uint32_t> & fieldIds)
+ : _diskIndex(diskIndex),
+ _fieldIds(fieldIds),
+ _cache()
+ { }
const DiskIndex::LookupResult &
lookup(const vespalib::string & word, uint32_t fieldId) {
auto it = _cache.find(word);
@@ -473,7 +463,7 @@ DiskIndex::get_field_length_info(const vespalib::string& field_name) const
if (fieldId != Schema::UNKNOWN_FIELD_ID) {
return _postingFiles[fieldId]->get_field_length_info();
} else {
- return FieldLengthInfo();
+ return {};
}
}
diff --git a/searchlib/src/vespa/searchlib/diskindex/indexbuilder.cpp b/searchlib/src/vespa/searchlib/diskindex/indexbuilder.cpp
index 5cf80d06c87..ae1e5594320 100644
--- a/searchlib/src/vespa/searchlib/diskindex/indexbuilder.cpp
+++ b/searchlib/src/vespa/searchlib/diskindex/indexbuilder.cpp
@@ -180,10 +180,10 @@ FileHandle::close()
FieldHandle::FieldHandle(const Schema &schema, uint32_t fieldId, IndexBuilder &builder, uint32_t docIdLimit,
uint64_t numWordIds, const IFieldLengthInspector & field_length_inspector,
const TuneFileSeqWrite &tuneFileWrite, const FileHeaderContext &fileHeaderContext)
- : _schema(schema),
- _builder(builder),
- _file(),
- _fieldId(fieldId)
+ : _schema(schema),
+ _builder(builder),
+ _file(),
+ _fieldId(fieldId)
{
std::filesystem::create_directory(std::filesystem::path(getDir()));
_file.open(getDir(), SchemaUtil::IndexIterator(_schema, getIndexId()), docIdLimit, numWordIds,
@@ -251,7 +251,6 @@ IndexBuilder::IndexBuilder(const Schema &schema, vespalib::stringref prefix, uin
uint64_t numWordIds, const index::IFieldLengthInspector &field_length_inspector,
const TuneFileIndexing &tuneFileIndexing, const search::common::FileHeaderContext &fileHeaderContext)
: index::IndexBuilder(schema),
- _schema(schema),
_fields(extractFields(schema)),
_prefix(prefix),
_docIdLimit(docIdLimit),
diff --git a/searchlib/src/vespa/searchlib/diskindex/indexbuilder.h b/searchlib/src/vespa/searchlib/diskindex/indexbuilder.h
index 4ef6ab4a813..3417f595faa 100644
--- a/searchlib/src/vespa/searchlib/diskindex/indexbuilder.h
+++ b/searchlib/src/vespa/searchlib/diskindex/indexbuilder.h
@@ -30,7 +30,6 @@ public:
std::unique_ptr<index::FieldIndexBuilder> startField(uint32_t fieldId) override;
vespalib::string appendToPrefix(vespalib::stringref name) const;
private:
- const index::Schema &_schema;
std::vector<int> _fields;
const vespalib::string _prefix;
const uint32_t _docIdLimit;
diff --git a/searchlib/src/vespa/searchlib/diskindex/wordnummapper.cpp b/searchlib/src/vespa/searchlib/diskindex/wordnummapper.cpp
index 83033b137f8..bda0a0594b7 100644
--- a/searchlib/src/vespa/searchlib/diskindex/wordnummapper.cpp
+++ b/searchlib/src/vespa/searchlib/diskindex/wordnummapper.cpp
@@ -18,7 +18,7 @@ WordNumMapping::readMappingFile(const vespalib::string &name,
const TuneFileSeqRead &tuneFileRead)
{
// Open word mapping file
- Fast_BufferedFile old2newwordfile(new FastOS_File);
+ Fast_BufferedFile old2newwordfile;
if (tuneFileRead.getWantDirectIO()) {
old2newwordfile.EnableDirectIO();
}
diff --git a/vespalib/src/vespa/fastlib/io/bufferedfile.cpp b/vespalib/src/vespa/fastlib/io/bufferedfile.cpp
index 0fa62aca295..4d46427ed33 100644
--- a/vespalib/src/vespa/fastlib/io/bufferedfile.cpp
+++ b/vespalib/src/vespa/fastlib/io/bufferedfile.cpp
@@ -202,7 +202,7 @@ Fast_BufferedFile::ReadLine(char *line, size_t buflen)
p = line;
ep = line + buflen - 1;
- while (1) {
+ while (true) {
while (_bufi < _bufe && *_bufi != '\n' && p < ep)
*p++ = *_bufi++;
if (p >= ep) {
@@ -258,7 +258,7 @@ Fast_BufferedFile::Read(void *dst, size_t dstlen)
{
char * p = static_cast<char *>(dst);
char * pe = p + dstlen;
- while (1) {
+ while (true) {
int64_t sz = std::min(_bufe - _bufi, pe - p);
memcpy(p, _bufi, sz);
p += sz;
@@ -334,11 +334,6 @@ Fast_BufferedFile::WriteOpen(const char *name)
_openFlags = FASTOS_FILE_OPEN_WRITE;
}
-Fast_BufferedFile::Fast_BufferedFile(FastOS_FileInterface *file) :
- Fast_BufferedFile(file, DEFAULT_BUF_SIZE)
-{
-}
-
Fast_BufferedFile::Fast_BufferedFile() :
Fast_BufferedFile(DEFAULT_BUF_SIZE)
{
diff --git a/vespalib/src/vespa/fastlib/io/bufferedfile.h b/vespalib/src/vespa/fastlib/io/bufferedfile.h
index 8a22ec89bd7..16153b79171 100644
--- a/vespalib/src/vespa/fastlib/io/bufferedfile.h
+++ b/vespalib/src/vespa/fastlib/io/bufferedfile.h
@@ -28,30 +28,40 @@ private:
char * buf() { return static_cast<char *>(_buf.get()); }
const char * buf() const { return static_cast<const char *>(_buf.get()); }
-protected:
/** The file instance used for low-level file access. */
std::unique_ptr<FastOS_FileInterface> _file;
-public:
- /**
- * Create buffered file.
- * @param file file instance that should be used for low-level
- * file access. If this is NULL, an instance of
- * FastOS_File will be created. NOTE: the file
- * instance given here will be deleted by
- * the destructor.
- **/
Fast_BufferedFile(FastOS_FileInterface *file, size_t bufferSize);
- Fast_BufferedFile(FastOS_FileInterface *file);
+ /**
+ * Reset the internal start and end pointers to the
+ * head of the buffer, thus "emptying" it.
+ */
+ void ResetBuf();
+ /**
+ * Write the buffer to the file. Caution: Uses obsolete
+ * FastOS_FileInterface::WriteBuf.
+ * Allocates a 32kB buffer if not previously allocated.
+ */
+ void flushWriteBuf();
+ /**
+ * Read from the file into the buffer. Allocates a 32kB
+ * buffer if not previously allocated. Fills the buffer,
+ * or reads as much as possible if the (rest of) the file
+ * is smaller than the buffer.
+ * Caution: If the amount read is smaller than the expected
+ * amount, the method will abort.
+ */
+ void fillReadBuf();
+public:
Fast_BufferedFile();
- Fast_BufferedFile(size_t bufferSize);
+ explicit Fast_BufferedFile(size_t bufferSize);
Fast_BufferedFile(const Fast_BufferedFile &) = delete;
Fast_BufferedFile & operator = (const Fast_BufferedFile &) = delete;
/**
* Delete the file instance used for low-level file access.
**/
- virtual ~Fast_BufferedFile();
+ ~Fast_BufferedFile() override;
/**
* Open an existing file for reading.
*
@@ -71,26 +81,7 @@ public:
* @param name The name of the file to open.
*/
void WriteOpen(const char *name);
- /**
- * Reset the internal start and end pointers to the
- * head of the buffer, thus "emptying" it.
- */
- void ResetBuf();
- /**
- * Write the buffer to the file. Caution: Uses obsolete
- * FastOS_FileInterface::WriteBuf.
- * Allocates a 32kB buffer if not previously allocated.
- */
- void flushWriteBuf();
- /**
- * Read from the file into the buffer. Allocates a 32kB
- * buffer if not previously allocated. Fills the buffer,
- * or reads as much as possible if the (rest of) the file
- * is smaller than the buffer.
- * Caution: If the amount read is smaller than the expected
- * amount, the method will abort.
- */
- void fillReadBuf();
+
/**
* Read the next line of the buffered file into a buffer,
* reading from the file as necessary.
diff --git a/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp b/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp
index a663c6a601b..e6a00f4b86d 100644
--- a/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp
+++ b/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp
@@ -75,7 +75,7 @@ PtrAndSize
MmapFileAllocator::alloc(size_t sz) const
{
if (sz == 0) {
- return PtrAndSize(); // empty allocation
+ return {}; // empty allocation
}
static constexpr size_t alignment = 128;
sz = (sz + alignment - 1) & -alignment; // round sz to a multiple of alignment
@@ -107,7 +107,7 @@ MmapFileAllocator::alloc_large(size_t sz) const
retval = madvise(buf, sz, MADV_DONTDUMP);
assert(retval == 0);
#endif
- return PtrAndSize(buf, sz);
+ return {buf, sz};
}
void*
diff --git a/vespalib/src/vespa/vespalib/util/mmap_file_allocator.h b/vespalib/src/vespa/vespalib/util/mmap_file_allocator.h
index 96a69f50e43..f568a14572a 100644
--- a/vespalib/src/vespa/vespalib/util/mmap_file_allocator.h
+++ b/vespalib/src/vespa/vespalib/util/mmap_file_allocator.h
@@ -24,15 +24,11 @@ class MmapFileAllocator : public MemoryAllocator {
struct SizeAndOffset {
size_t size;
uint64_t offset;
- SizeAndOffset()
- : SizeAndOffset(0u, 0u)
- {
- }
- SizeAndOffset(size_t size_in, uint64_t offset_in)
+ SizeAndOffset() noexcept : SizeAndOffset(0u, 0u) { }
+ SizeAndOffset(size_t size_in, uint64_t offset_in) noexcept
: size(size_in),
offset(offset_in)
- {
- }
+ { }
};
using Allocations = hash_map<void *, SizeAndOffset>;
const vespalib::string _dir_name;
@@ -55,9 +51,9 @@ class MmapFileAllocator : public MemoryAllocator {
public:
static constexpr uint32_t default_small_limit = 128_Ki;
static constexpr uint32_t default_premmap_size = 1_Mi;
- MmapFileAllocator(const vespalib::string& dir_name);
+ explicit MmapFileAllocator(const vespalib::string& dir_name);
MmapFileAllocator(const vespalib::string& dir_name, uint32_t small_limit, uint32_t premmap_size);
- ~MmapFileAllocator();
+ ~MmapFileAllocator() override;
PtrAndSize alloc(size_t sz) const override;
void free(PtrAndSize alloc) const noexcept override;
size_t resize_inplace(PtrAndSize, size_t) const override;