summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-02-07 14:10:26 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2019-02-07 14:10:26 +0000
commitb856689444b618a4031fecd76fdaa7f719afe8f7 (patch)
treeed0058fe6e05e9bcda1284be28d4d85c88cc9319 /searchlib
parent8551296d35793b1713ead2d7c6e420ffb1783618 (diff)
Hold the lock so that restart is not needed.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp21
-rw-r--r--searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h2
2 files changed, 9 insertions, 14 deletions
diff --git a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp
index d3167060ecf..e6a78b21a0b 100644
--- a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp
+++ b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.cpp
@@ -344,10 +344,9 @@ getAlignedStartPos(FastOS_File & file)
}
WriteableFileChunk::ProcessedChunkQ
-WriteableFileChunk::drainQ()
+WriteableFileChunk::drainQ(MonitorGuard & guard)
{
ProcessedChunkQ newChunks;
- MonitorGuard guard(_writeMonitor);
newChunks.swap(_writeQ);
if ( ! newChunks.empty() ) {
guard.broadcast();
@@ -496,8 +495,10 @@ WriteableFileChunk::fileWriter(const uint32_t firstChunkId)
LOG(debug, "Starting the filewriter with chunkid = %d", firstChunkId);
uint32_t nextChunkId(firstChunkId);
bool done(false);
+ MonitorGuard guard(_writeMonitor);
{
- for (ProcessedChunkQ newChunks(drainQ()); !newChunks.empty(); newChunks = drainQ()) {
+ for (ProcessedChunkQ newChunks(drainQ(guard)); !newChunks.empty(); newChunks = drainQ(guard)) {
+ guard.unlock();
insertChunks(_orderedChunks, newChunks, nextChunkId);
ProcessedChunkQ chunks(fetchNextChain(_orderedChunks, nextChunkId));
nextChunkId += chunks.size();
@@ -507,14 +508,14 @@ WriteableFileChunk::fileWriter(const uint32_t firstChunkId)
writeData(chunks, sz);
updateChunkInfo(chunks, cmetaV, sz);
LOG(spam, "bucket spread = '%3.2f'", getBucketSpread());
+ guard = MonitorGuard(_writeMonitor);
if (done) break;
}
}
LOG(debug, "Stopping the filewriter with startchunkid = %d and ending chunkid = %d done=%d",
firstChunkId, nextChunkId, done);
- MonitorGuard guard(_writeMonitor);
+ assert(_writeQ.empty());
if (done) {
- assert(_writeQ.empty());
assert(_chunkMap.empty());
for (const ChunkInfo & cm : _chunkInfo) {
(void) cm;
@@ -523,14 +524,8 @@ WriteableFileChunk::fileWriter(const uint32_t firstChunkId)
_writeTaskIsRunning = false;
guard.broadcast();
} else {
- if (_writeQ.empty()) {
- _firstChunkIdToBeWritten = nextChunkId;
- _writeTaskIsRunning = false;
- } else {
- _writeTaskIsRunning = true;
- guard.unlock();
- restart(nextChunkId);
- }
+ _firstChunkIdToBeWritten = nextChunkId;
+ _writeTaskIsRunning = false;
}
}
diff --git a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h
index f5923134138..bb550096251 100644
--- a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h
+++ b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h
@@ -84,7 +84,7 @@ private:
int32_t flushLastIfNonEmpty(bool force);
// _writeMonitor should not be held when calling restart
void restart(uint32_t nextChunkId);
- ProcessedChunkQ drainQ();
+ ProcessedChunkQ drainQ(vespalib::MonitorGuard & guard);
void readDataHeader();
void readIdxHeader(FastOS_FileInterface & idxFile);
void writeDataHeader(const common::FileHeaderContext &fileHeaderContext);