mirror of
https://github.com/apple/foundationdb.git
synced 2025-06-02 03:12:12 +08:00
Rewrite corrupt block number calculations to be more clear.
This commit is contained in:
parent
df5b15e56c
commit
5c795c3abe
@ -153,18 +153,28 @@ struct PageChecksumCodec {
|
||||
if (!silent) {
|
||||
auto severity = SevError;
|
||||
if (g_network->isSimulated()) {
|
||||
auto firstBlock = pageNumber == 1 ? 0 : ((pageNumber - 1) * pageLen) / 4096;
|
||||
auto lastBlock = (pageNumber * pageLen + 4095) / 4096;
|
||||
// Calculate file offsets for the read/write operation space
|
||||
// Operation starts at a 1-based pageNumber and is of size pageLen
|
||||
int64_t fileOffsetStart = (pageNumber - 1) * pageLen;
|
||||
// End refers to the offset after the operation, not the last byte.
|
||||
int64_t fileOffsetEnd = fileOffsetStart + pageLen;
|
||||
|
||||
auto iter = g_simulator->corruptedBlocks.lower_bound(std::make_pair(filename, firstBlock));
|
||||
if (iter != g_simulator->corruptedBlocks.end() && iter->first == filename && iter->second < lastBlock) {
|
||||
// Convert the file offsets to potentially corrupt block numbers
|
||||
// Corrupt block numbers are 0-based and 4096 bytes in length.
|
||||
int64_t corruptBlockStart = fileOffsetStart / 4096;
|
||||
// corrupt block end is the block number AFTER the operation
|
||||
int64_t corruptBlockEnd = (fileOffsetEnd + 4095) / 4096;
|
||||
|
||||
auto iter = g_simulator->corruptedBlocks.lower_bound(std::make_pair(filename, corruptBlockStart));
|
||||
if (iter != g_simulator->corruptedBlocks.end() && iter->first == filename &&
|
||||
iter->second < corruptBlockEnd) {
|
||||
severity = SevWarnAlways;
|
||||
}
|
||||
TraceEvent("CheckCorruption")
|
||||
.detail("Filename", filename)
|
||||
.detail("NextFile", iter->first)
|
||||
.detail("FirstBlock", firstBlock)
|
||||
.detail("LastBlock", lastBlock)
|
||||
.detail("BlockStart", corruptBlockStart)
|
||||
.detail("BlockEnd", corruptBlockEnd)
|
||||
.detail("NextBlock", iter->second);
|
||||
}
|
||||
TraceEvent trEvent(severity, "SQLitePageChecksumFailure");
|
||||
|
Loading…
x
Reference in New Issue
Block a user