]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
log_writer: conditionally adjust crc
authorSage Weil <sage@redhat.com>
Thu, 8 Oct 2015 17:08:16 +0000 (13:08 -0400)
committerSage Weil <sage@redhat.com>
Thu, 8 Oct 2015 17:41:06 +0000 (13:41 -0400)
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 <sage@redhat.com>
db/log_writer.cc

index 9bef090f1537a1858dfec5b09a2eeda81c844a26..ab0ab012a6a620bdc54d9f8cfc85588e0f6f0750 100644 (file)
@@ -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<uint32_t>(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));