Skip to content

Commit

Permalink
Improve diskindex write error detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
toregge committed Jan 26, 2022
1 parent 3b1c1f0 commit b2e4b88
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 35 deletions.
42 changes: 23 additions & 19 deletions searchlib/src/vespa/searchlib/diskindex/pagedict4file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ PageDict4FileSeqWrite::open(const vespalib::string &name,
bool
PageDict4FileSeqWrite::close()
{
bool success = true;
_pWriter->flush();
uint64_t usedPBits = _pe.getWriteOffset();
uint64_t usedSPBits = _spe.getWriteOffset();
Expand All @@ -415,28 +416,28 @@ PageDict4FileSeqWrite::close()
_ssWriteContext.writeComprBuffer(true);

_pWriteContext.dropComprBuf();
_pfile.Sync();
_pfile.Close();
success &= _pfile.Sync();
success &= _pfile.Close();
_pWriteContext.setFile(nullptr);
_spWriteContext.dropComprBuf();
_spfile.Sync();
_spfile.Close();
success &= _spfile.Sync();
success &= _spfile.Close();
_spWriteContext.setFile(nullptr);
_ssWriteContext.dropComprBuf();
_ssfile.Sync();
_ssfile.Close();
success &= _ssfile.Sync();
success &= _ssfile.Close();
_ssWriteContext.setFile(nullptr);

// Update file headers
updatePHeader(usedPBits);
updateSPHeader(usedSPBits);
updateSSHeader(usedSSBits);
success &= updatePHeader(usedPBits);
success &= updateSPHeader(usedSPBits);
success &= updateSSHeader(usedSSBits);

_pWriter.reset();
_spWriter.reset();
_ssWriter.reset();

return true;
return success;
}


Expand Down Expand Up @@ -548,7 +549,7 @@ PageDict4FileSeqWrite::makeSSHeader(const FileHeaderContext &fileHeaderContext)
}


void
bool
PageDict4FileSeqWrite::updatePHeader(uint64_t fileBitSize)
{
vespalib::FileHeader h(FileSettings::DIRECTIO_ALIGNMENT);
Expand All @@ -560,12 +561,13 @@ PageDict4FileSeqWrite::updatePHeader(uint64_t fileBitSize)
h.putTag(Tag("frozen", 1));
h.putTag(Tag("fileBitSize", fileBitSize));
h.rewriteFile(f);
f.Sync();
f.Close();
bool success = f.Sync();
success &= f.Close();
return success;
}


void
bool
PageDict4FileSeqWrite::updateSPHeader(uint64_t fileBitSize)
{
vespalib::FileHeader h(FileSettings::DIRECTIO_ALIGNMENT);
Expand All @@ -577,12 +579,13 @@ PageDict4FileSeqWrite::updateSPHeader(uint64_t fileBitSize)
h.putTag(Tag("frozen", 1));
h.putTag(Tag("fileBitSize", fileBitSize));
h.rewriteFile(f);
f.Sync();
f.Close();
bool success = f.Sync();
success &= f.Close();
return success;
}


void
bool
PageDict4FileSeqWrite::updateSSHeader(uint64_t fileBitSize)
{
vespalib::FileHeader h(FileSettings::DIRECTIO_ALIGNMENT);
Expand All @@ -597,8 +600,9 @@ PageDict4FileSeqWrite::updateSSHeader(uint64_t fileBitSize)
assert(wordNum <= _sse._numWordIds);
h.putTag(Tag("numWordIds", wordNum));
h.rewriteFile(f);
f.Sync();
f.Close();
bool success = f.Sync();
success &= f.Close();
return success;
}


Expand Down
6 changes: 3 additions & 3 deletions searchlib/src/vespa/searchlib/diskindex/pagedict4file.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ class PageDict4FileSeqWrite : public index::DictionaryFileSeqWrite
void makePHeader(const FileHeaderContext &fileHeaderContext);
void makeSPHeader(const FileHeaderContext &fileHeaderContext);
void makeSSHeader(const FileHeaderContext &fileHeaderContext);
void updatePHeader(uint64_t fileBitSize);
void updateSPHeader(uint64_t fileBitSize);
void updateSSHeader(uint64_t fileBitSize);
bool updatePHeader(uint64_t fileBitSize);
bool updateSPHeader(uint64_t fileBitSize);
bool updateSSHeader(uint64_t fileBitSize);
public:
PageDict4FileSeqWrite();
~PageDict4FileSeqWrite();
Expand Down
15 changes: 8 additions & 7 deletions searchlib/src/vespa/searchlib/diskindex/zcposting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ Zc4PostingSeqWrite::makeHeader(const FileHeaderContext &fileHeaderContext)
}


void
bool
Zc4PostingSeqWrite::updateHeader()
{
vespalib::FileHeader h;
Expand All @@ -271,8 +271,9 @@ Zc4PostingSeqWrite::updateHeader()
h.putTag(Tag("fileBitSize", _fileBitSize));
h.putTag(Tag("numWords", _writer.get_num_words()));
h.rewriteFile(f);
f.Sync();
f.Close();
bool success = f.Sync();
success &= f.Close();
return success;
}


Expand Down Expand Up @@ -320,11 +321,11 @@ Zc4PostingSeqWrite::close()
_writer.on_close(); // flush and pad
auto &writeContext = _writer.get_write_context();
writeContext.dropComprBuf();
_file.Sync();
_file.Close();
bool success = _file.Sync();
success &= _file.Close();
writeContext.setFile(nullptr);
updateHeader();
return true;
success &= updateHeader();
return success;
}

void
Expand Down
11 changes: 5 additions & 6 deletions searchlib/src/vespa/searchlib/diskindex/zcposting.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ class Zc4PostingSeqWrite : public index::PostingListFileSeqWrite
FastOS_File _file;
uint64_t _fileBitSize;
index::PostingListCountFileSeqWrite *const _countFile;
/**
* Make header using feature encode write context.
*/
void makeHeader(const search::common::FileHeaderContext &fileHeaderContext);
bool updateHeader();
public:
Zc4PostingSeqWrite(index::PostingListCountFileSeqWrite *countFile);
~Zc4PostingSeqWrite();
Expand All @@ -81,12 +86,6 @@ class Zc4PostingSeqWrite : public index::PostingListFileSeqWrite
void getParams(PostingListParams &params) override;
void setFeatureParams(const PostingListParams &params) override;
void getFeatureParams(PostingListParams &params) override;

/**
* Make header using feature encode write context.
*/
void makeHeader(const search::common::FileHeaderContext &fileHeaderContext);
void updateHeader();
};

class ZcPostingSeqWrite : public Zc4PostingSeqWrite
Expand Down

0 comments on commit b2e4b88

Please sign in to comment.