Add helper function to get debug type name (#10243)

Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/10243

Reviewed By: riversand963

Differential Revision: D37370236

Pulled By: jay-zhuang

fbshipit-source-id: 6e7a6fadf45fdfb5afe97b3f6fe4acf1260d4a86
main
Jay Zhuang 2 years ago committed by Facebook GitHub Bot
parent 69a18b9bad
commit dcb6a3be4e
  1. 29
      db/db_basic_test.cc
  2. 2
      db/dbformat.h
  3. 3
      include/rocksdb/utilities/debug.h
  4. 40
      utilities/debug.cc

@ -2618,12 +2618,19 @@ TEST_F(DBBasicTest, GetAllKeyVersions) {
ASSERT_OK(Delete(std::to_string(i)));
}
std::vector<KeyVersion> key_versions;
ASSERT_OK(ROCKSDB_NAMESPACE::GetAllKeyVersions(
db_, Slice(), Slice(), std::numeric_limits<size_t>::max(),
ASSERT_OK(GetAllKeyVersions(db_, Slice(), Slice(),
std::numeric_limits<size_t>::max(),
&key_versions));
ASSERT_EQ(kNumInserts + kNumDeletes + kNumUpdates, key_versions.size());
ASSERT_OK(ROCKSDB_NAMESPACE::GetAllKeyVersions(
db_, handles_[0], Slice(), Slice(), std::numeric_limits<size_t>::max(),
for (size_t i = 0; i < kNumInserts + kNumDeletes + kNumUpdates; i++) {
if (i % 3 == 0) {
ASSERT_EQ(key_versions[i].GetTypeName(), "TypeDeletion");
} else {
ASSERT_EQ(key_versions[i].GetTypeName(), "TypeValue");
}
}
ASSERT_OK(GetAllKeyVersions(db_, handles_[0], Slice(), Slice(),
std::numeric_limits<size_t>::max(),
&key_versions));
ASSERT_EQ(kNumInserts + kNumDeletes + kNumUpdates, key_versions.size());
@ -2637,11 +2644,21 @@ TEST_F(DBBasicTest, GetAllKeyVersions) {
for (size_t i = 0; i + 1 != kNumDeletes; ++i) {
ASSERT_OK(Delete(1, std::to_string(i)));
}
ASSERT_OK(ROCKSDB_NAMESPACE::GetAllKeyVersions(
db_, handles_[1], Slice(), Slice(), std::numeric_limits<size_t>::max(),
ASSERT_OK(GetAllKeyVersions(db_, handles_[1], Slice(), Slice(),
std::numeric_limits<size_t>::max(),
&key_versions));
ASSERT_EQ(kNumInserts + kNumDeletes + kNumUpdates - 3, key_versions.size());
}
TEST_F(DBBasicTest, ValueTypeString) {
KeyVersion key_version;
// when adding new type, please also update `value_type_string_map`
for (unsigned char i = ValueType::kTypeDeletion; i < ValueType::kTypeMaxValid;
i++) {
key_version.type = i;
ASSERT_TRUE(key_version.GetTypeName() != "Invalid");
}
}
#endif // !ROCKSDB_LITE
TEST_F(DBBasicTest, MultiGetIOBufferOverrun) {

@ -68,6 +68,8 @@ enum ValueType : unsigned char {
kTypeCommitXIDAndTimestamp = 0x15, // WAL only
kTypeWideColumnEntity = 0x16,
kTypeColumnFamilyWideColumnEntity = 0x17, // WAL only
kTypeMaxValid, // Should be after the last valid type, only used for
// validation
kMaxValue = 0x7F // Not used for storing records.
};

@ -25,9 +25,8 @@ struct KeyVersion {
std::string user_key;
std::string value;
SequenceNumber sequence;
// TODO(ajkr): we should provide a helper function that converts the int to a
// string describing the type for easier debugging.
int type;
std::string GetTypeName() const;
};
// Returns listing of all versions of keys in the provided user key range.

@ -8,9 +8,49 @@
#include "rocksdb/utilities/debug.h"
#include "db/db_impl/db_impl.h"
#include "rocksdb/utilities/options_type.h"
namespace ROCKSDB_NAMESPACE {
static std::unordered_map<std::string, ValueType> value_type_string_map = {
{"TypeDeletion", ValueType::kTypeDeletion},
{"TypeValue", ValueType::kTypeValue},
{"TypeMerge", ValueType::kTypeMerge},
{"TypeLogData", ValueType::kTypeLogData},
{"TypeColumnFamilyDeletion", ValueType::kTypeColumnFamilyDeletion},
{"TypeColumnFamilyValue", ValueType::kTypeColumnFamilyValue},
{"TypeColumnFamilyMerge", ValueType::kTypeColumnFamilyMerge},
{"TypeSingleDeletion", ValueType::kTypeSingleDeletion},
{"TypeColumnFamilySingleDeletion",
ValueType::kTypeColumnFamilySingleDeletion},
{"TypeBeginPrepareXID", ValueType::kTypeBeginPrepareXID},
{"TypeEndPrepareXID", ValueType::kTypeEndPrepareXID},
{"TypeCommitXID", ValueType::kTypeCommitXID},
{"TypeRollbackXID", ValueType::kTypeRollbackXID},
{"TypeNoop", ValueType::kTypeNoop},
{"TypeColumnFamilyRangeDeletion",
ValueType::kTypeColumnFamilyRangeDeletion},
{"TypeRangeDeletion", ValueType::kTypeRangeDeletion},
{"TypeColumnFamilyBlobIndex", ValueType::kTypeColumnFamilyBlobIndex},
{"TypeBlobIndex", ValueType::kTypeBlobIndex},
{"TypeBeginPersistedPrepareXID", ValueType::kTypeBeginPersistedPrepareXID},
{"TypeBeginUnprepareXID", ValueType::kTypeBeginUnprepareXID},
{"TypeDeletionWithTimestamp", ValueType::kTypeDeletionWithTimestamp},
{"TypeCommitXIDAndTimestamp", ValueType::kTypeCommitXIDAndTimestamp},
{"TypeWideColumnEntity", ValueType::kTypeWideColumnEntity},
{"TypeColumnFamilyWideColumnEntity",
ValueType::kTypeColumnFamilyWideColumnEntity}};
std::string KeyVersion::GetTypeName() const {
std::string type_name;
if (SerializeEnum<ValueType>(value_type_string_map,
static_cast<ValueType>(type), &type_name)) {
return type_name;
} else {
return "Invalid";
}
}
Status GetAllKeyVersions(DB* db, Slice begin_key, Slice end_key,
size_t max_num_ikeys,
std::vector<KeyVersion>* key_versions) {

Loading…
Cancel
Save