From: Sage Weil Date: Thu, 8 Oct 2015 17:08:16 +0000 (-0400) Subject: log_writer: conditionally adjust crc X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e24306f58ba323d8a4d2b6f6e61552be257d5312;p=rocksdb.git log_writer: conditionally adjust crc If recycle_log_files is enabled, XOR the log_number into the message CRC in the log. This ensures that if we read a recycled log and see an old event from a previous incarnation of the log we will fail the CRC check. Signed-off-by: Sage Weil --- diff --git a/db/log_writer.cc b/db/log_writer.cc index 9bef090f..ab0ab012 100644 --- a/db/log_writer.cc +++ b/db/log_writer.cc @@ -93,8 +93,15 @@ Status Writer::EmitPhysicalRecord(RecordType t, const char* ptr, size_t n) { // Compute the crc of the record type and the payload. uint32_t crc = crc32c::Extend(type_crc_[t], ptr, n); - crc = crc32c::Mask(crc); // Adjust for storage - EncodeFixed32(buf, crc); + if (recycle_log_files_) { + // XOR in log number + uint32_t final_crc = crc ^ static_cast(log_number_); + final_crc = crc32c::Mask(final_crc); // Adjust for storage + EncodeFixed32(buf, final_crc); + } else { + crc = crc32c::Mask(crc); // Adjust for storage + EncodeFixed32(buf, crc); + } // Write the header and the payload Status s = dest_->Append(Slice(buf, kHeaderSize));