From 1bcef3d83c668afa690dd40c89bb1e955be0b1da Mon Sep 17 00:00:00 2001 From: Yanqin Jin Date: Tue, 6 Oct 2020 13:51:22 -0700 Subject: [PATCH] Make sure assert(false) handles failures too (#7483) Summary: In opt mode, assertions are just no-ops. Therefore, we need to report errors instead of just doing an `assert(false)`. Pull Request resolved: https://github.com/facebook/rocksdb/pull/7483 Test Plan: make check Reviewed By: anand1976 Differential Revision: D24142725 Pulled By: riversand963 fbshipit-source-id: 5629556dbe29f00dd09e30a7d5df5e6cf09ee435 --- db/compaction/compaction_picker_universal.cc | 3 ++ db/db_iter.cc | 32 +++++++++++++++----- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/db/compaction/compaction_picker_universal.cc b/db/compaction/compaction_picker_universal.cc index 8d782f59b..1e95191d6 100644 --- a/db/compaction/compaction_picker_universal.cc +++ b/db/compaction/compaction_picker_universal.cc @@ -996,6 +996,9 @@ Compaction* UniversalCompactionBuilder::PickCompactionToOldest( comp_reason_print_string = "size amp"; } else { assert(false); + comp_reason_print_string = "unknown: "; + comp_reason_print_string.append( + std::to_string(static_cast(compaction_reason))); } char file_num_buf[256]; diff --git a/db/db_iter.cc b/db/db_iter.cc index b4e3f2d20..a9eee88dd 100644 --- a/db/db_iter.cc +++ b/db/db_iter.cc @@ -384,8 +384,11 @@ bool DBIter::FindNextUserEntryInternal(bool skipping_saved_key, } break; default: - assert(false); - break; + valid_ = false; + status_ = Status::Corruption( + "Unknown value type: " + + std::to_string(static_cast(ikey_.type))); + return false; } } } else { @@ -556,7 +559,11 @@ bool DBIter::MergeValuesNewToOld() { valid_ = false; return false; } else { - assert(false); + valid_ = false; + status_ = Status::Corruption( + "Unrecognized value type: " + + std::to_string(static_cast(ikey.type))); + return false; } } @@ -832,7 +839,11 @@ bool DBIter::FindValueForCurrentKey() { } break; default: - assert(false); + valid_ = false; + status_ = Status::Corruption( + "Unknown value type: " + + std::to_string(static_cast(last_key_entry_type))); + return false; } PERF_COUNTER_ADD(internal_key_skipped_count, 1); @@ -898,8 +909,11 @@ bool DBIter::FindValueForCurrentKey() { is_blob_ = true; break; default: - assert(false); - break; + valid_ = false; + status_ = Status::Corruption( + "Unknown value type: " + + std::to_string(static_cast(last_key_entry_type))); + return false; } if (!s.ok()) { valid_ = false; @@ -1048,7 +1062,11 @@ bool DBIter::FindValueForCurrentKeyUsingSeek() { valid_ = false; return false; } else { - assert(false); + valid_ = false; + status_ = Status::Corruption( + "Unknown value type: " + + std::to_string(static_cast(ikey.type))); + return false; } }