#include "table/block_based/reader_common.h"
#include "monitoring/perf_context_imp.h"
#include "rocksdb/table.h"
#include "table/format.h"
#include "util/coding.h"
#include "util/crc32c.h"
#include "util/string_util.h"
namespace ROCKSDB_NAMESPACE {
void ForceReleaseCachedEntry(void* arg, void* h) {
Cache* cache = static_cast<Cache*>(arg);
Cache::Handle* handle = static_cast<Cache::Handle*>(h);
cache->Release(handle, true );
}
Status VerifyBlockChecksum(const Footer& footer, const char* data,
size_t block_size, const std::string& file_name,
uint64_t offset, BlockType block_type) {
PERF_TIMER_GUARD(block_checksum_time);
assert(footer.GetBlockTrailerSize() == 5);
ChecksumType type = footer.checksum_type();
size_t len = block_size + 1;
uint32_t stored = DecodeFixed32(data + len);
uint32_t computed = ComputeBuiltinChecksum(type, data, len);
uint32_t modifier =
ChecksumModifierForContext(footer.base_context_checksum(), offset);
stored -= modifier;
if (stored == computed) {
return Status::OK();
} else {
if (type == kCRC32c) {
stored = crc32c::Unmask(stored);
computed = crc32c::Unmask(computed);
}
return Status::Corruption(
"block checksum mismatch: stored" +
std::string(modifier ? "(context removed)" : "") + " = " +
std::to_string(stored) + ", computed = " + std::to_string(computed) +
", type = " + std::to_string(type) + " in " + file_name + " offset " +
std::to_string(offset) + " size " + std::to_string(block_size) +
", block_type = " + BlockTypeToString(block_type));
}
}
}