Skip to content

Commit a235230

Browse files
committed
Use cb::couchstore::seek(End) to detect concurrent write
As part of the catch up phase while running concurrent compaction we want to detect if the flusher wrote data to the database while the compactor was copying data without holding the lock. Instead of iterating over _all_ 4k blocks on disk from the current header until the end of the file to find the last header block it is more efficient to just try to locate the last header on the file (which should be at the end of the file). Improve the logging messages to include if the flusher is being paused or not while copying the data. Change-Id: I515a513f6606d1b4bb8d21fa41f69f5e3c41a987 Reviewed-on: http://review.couchbase.org/c/kv_engine/+/138071 Tested-by: Build Bot <[email protected]> Reviewed-by: Dave Rigby <[email protected]>
1 parent 33d0afc commit a235230

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

engines/ep/src/couch-kvstore/couch-kvstore.cc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,22 +1449,16 @@ bool CouchKVStore::tryToCatchUpDbFile(Db& source,
14491449

14501450
auto start = cb::couchstore::getHeader(source);
14511451

1452-
couchstore_error_t err;
1453-
while ((err = cb::couchstore::seek(source,
1454-
cb::couchstore::Direction::Forward)) ==
1455-
COUCHSTORE_SUCCESS) {
1456-
// nothing (I should probably add one seek END and SEEK_START)
1457-
}
1458-
1459-
if (err != COUCHSTORE_ERROR_NO_HEADER) {
1452+
auto err = cb::couchstore::seek(source, cb::couchstore::Direction::End);
1453+
if (err != COUCHSTORE_SUCCESS) {
14601454
// seek failed - deal with it
14611455
throw std::runtime_error("Failed to seek in the database file: " +
14621456
couchkvstore_strerrno(&source, err));
14631457
}
14641458

14651459
auto end = cb::couchstore::getHeader(source);
14661460
if (end.headerPosition == start.headerPosition) {
1467-
// at the end!
1461+
// Catchup complete
14681462
return true;
14691463
}
14701464

@@ -1484,10 +1478,11 @@ bool CouchKVStore::tryToCatchUpDbFile(Db& source,
14841478
.count();
14851479
}
14861480

1487-
EP_LOG_INFO("Try to catch up {}: from {} to {}",
1481+
EP_LOG_INFO("Try to catch up {}: from {} to {} {} stopping flusher",
14881482
vbid,
14891483
start.updateSeqNum,
1490-
end.updateSeqNum);
1484+
end.updateSeqNum,
1485+
copyWithoutLock ? "without" : "while");
14911486
err = cb::couchstore::replay(
14921487
source,
14931488
destination,
@@ -1506,14 +1501,19 @@ bool CouchKVStore::tryToCatchUpDbFile(Db& source,
15061501
throw std::runtime_error("Failed to replay data!");
15071502
}
15081503

1504+
bool ret = true;
15091505
if (copyWithoutLock) {
15101506
lock.lock();
15111507
// the database may have changed.. just return false and let the
15121508
// caller call us again to check..
1513-
return false;
1509+
ret = false;
15141510
}
15151511

1516-
return true;
1512+
logger.info("Catch up of {} to {} complete{}",
1513+
vbid,
1514+
end.updateSeqNum,
1515+
copyWithoutLock ? ", stopping flusher" : "");
1516+
return ret;
15171517
}
15181518

15191519
vbucket_state* CouchKVStore::getVBucketState(Vbid vbucketId) {

0 commit comments

Comments
 (0)