output_validator.cc 1.1 KB

1234567891011121314151617181920212223242526272829
  1. // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. //
  6. #include "db/output_validator.h"
  7. #include "test_util/sync_point.h"
  8. #include "util/hash.h"
  9. namespace ROCKSDB_NAMESPACE {
  10. Status OutputValidator::Add(const Slice& key, const Slice& value) {
  11. if (enable_hash_) {
  12. // Generate a rolling 64-bit hash of the key and values
  13. paranoid_hash_ = NPHash64(key.data(), key.size(), paranoid_hash_);
  14. paranoid_hash_ = NPHash64(value.data(), value.size(), paranoid_hash_);
  15. }
  16. if (key.size() < kNumInternalBytes) {
  17. return Status::Corruption(
  18. "Compaction tries to write a key without internal bytes.");
  19. }
  20. // prev_key_ starts with empty.
  21. if (!prev_key_.empty() && icmp_.Compare(key, prev_key_) < 0) {
  22. return Status::Corruption("Compaction sees out-of-order keys.");
  23. }
  24. prev_key_.assign(key.data(), key.size());
  25. return Status::OK();
  26. }
  27. } // namespace ROCKSDB_NAMESPACE