diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2016-06-29 09:25:35 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2016-06-29 09:25:35 +0200 |
commit | 7fbb5d012c1b581f0c95dbffea132fdc630ee8cf (patch) | |
tree | daefbc3d38cc90cfd221c7f33c5f76e029532b42 /searchlib | |
parent | 673e688bfb16add9ccbaa364c36125d44be26e5e (diff) |
Ensure that the lock is held all the time from allocating the id to inserting it.
Use a single way of inserting it and signal that the lock must be held.
Diffstat (limited to 'searchlib')
-rw-r--r-- | searchlib/src/vespa/searchlib/docstore/logdatastore.cpp | 27 | ||||
-rw-r--r-- | searchlib/src/vespa/searchlib/docstore/logdatastore.h | 2 |
2 files changed, 15 insertions, 14 deletions
diff --git a/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp b/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp index 080dc71cbf2..90147c9d586 100644 --- a/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp +++ b/searchlib/src/vespa/searchlib/docstore/logdatastore.cpp @@ -10,6 +10,7 @@ LOG_SETUP(".searchlib.docstore.logdatastore"); #include <vespa/vespalib/data/fileheader.h> #include <vespa/vespalib/stllike/hash_map.h> #include <vespa/vespalib/xxhash/xxhash.h> +#include <thread> namespace search { @@ -173,7 +174,7 @@ LogDataStore::requireSpace(LockGuard guard, WriteableFileChunk & active) active.getName().c_str(), oldSz, _config.getMaxFileSize()); if (oldSz > _config.getMaxFileSize()) { FileId fileId = allocateFileId(guard); - _fileChunks[fileId.getId()] = createWritableFile(fileId, active.getSerialNum()); + setNewFileChunk(guard, createWritableFile(fileId, active.getSerialNum())); setActive(guard, fileId); std::unique_ptr<FileChunkHolder> activeHolder = holdFileChunk(active.getFileId()); guard.unlock(); @@ -605,6 +606,13 @@ bool LogDataStore::shouldCompactToActiveFile(size_t compactedSize) const { || (_config.getMinFileSizeFactor() * _config.getMaxFileSize() > compactedSize); } +void LogDataStore::setNewFileChunk(const LockGuard & guard, FileChunk::UP file) +{ + assert(guard.locks(_updateLock)); + assert( ! _fileChunks[file->getFileId().getId()]); + _fileChunks[file->getFileId().getId()] = std::move(file); +} + void LogDataStore::compactFile(FileId fileId) { FileChunk::UP & fc(_fileChunks[fileId.getId()]); @@ -615,10 +623,9 @@ void LogDataStore::compactFile(FileId fileId) FileId destinationFileId = FileId::active(); if (_bucketizer) { if ( ! shouldCompactToActiveFile(fc->getDiskFootprint() - fc->getDiskBloat())) { - destinationFileId = allocateFileId(); - FileChunk::UP destination = createWritableFile(destinationFileId, fc->getLastPersistedSerialNum(), - fc->getNameId().next()); - _fileChunks[destination->getFileId().getId()] = std::move(destination); + LockGuard guard(_updateLock); + destinationFileId = allocateFileId(guard); + setNewFileChunk(guard, createWritableFile(destinationFileId, fc->getLastPersistedSerialNum(), fc->getNameId().next())); } compacter.reset(new BucketCompacter(*this, *_bucketizer, fc->getFileId(), destinationFileId)); @@ -637,7 +644,7 @@ void LogDataStore::compactFile(FileId fileId) compactTo.freeze(); } - FastOS_Thread::Sleep(10 * 1000); + std::this_thread::sleep_for(std::chrono::seconds(10));; FileChunk::UP toDie; for (;;) { LockGuard guard(_updateLock); @@ -650,7 +657,7 @@ void LogDataStore::compactFile(FileId fileId) * Wait for requireSpace() and flush() methods to leave chunk * alone. */ - FastOS_Thread::Sleep(1000); + std::this_thread::sleep_for(std::chrono::seconds(1));; } toDie->erase(); LockGuard guard(_updateLock); @@ -686,12 +693,6 @@ LogDataStore::memoryMeta() const } FileChunk::FileId -LogDataStore::allocateFileId() -{ - LockGuard guard(_updateLock); - return allocateFileId(guard); -} -FileChunk::FileId LogDataStore::allocateFileId(const LockGuard & guard) { (void) guard; diff --git a/searchlib/src/vespa/searchlib/docstore/logdatastore.h b/searchlib/src/vespa/searchlib/docstore/logdatastore.h index 53e5d5a5b69..1d9aa051b7c 100644 --- a/searchlib/src/vespa/searchlib/docstore/logdatastore.h +++ b/searchlib/src/vespa/searchlib/docstore/logdatastore.h @@ -214,7 +214,7 @@ private: NameIdSet scanDir(const vespalib::string &dir, const vespalib::string &suffix); FileId allocateFileId(const LockGuard & guard); - FileId allocateFileId(); + void setNewFileChunk(const LockGuard & guard, FileChunk::UP fileChunk); vespalib::string ls(const NameIdSet & partList); WriteableFileChunk & getActive(const LockGuard & guard) { |