This is an automated email from the ASF dual-hosted git repository.
twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new a2051946b chore(metadata): wrap RedisTypeNames as a method (#2838)
a2051946b is described below
commit a2051946b655d46ffbdfc93b71b8f4d91d9d4868
Author: Twice <[email protected]>
AuthorDate: Fri Mar 21 08:24:16 2025 +0800
chore(metadata): wrap RedisTypeNames as a method (#2838)
Signed-off-by: PragmaTwice <[email protected]>
---
src/cluster/slot_migrate.cc | 2 +-
src/commands/cmd_search.cc | 2 +-
src/search/search_encoding.h | 2 ++
src/storage/redis_db.cc | 2 +-
src/storage/redis_metadata.cc | 2 ++
src/storage/redis_metadata.h | 1 +
6 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/cluster/slot_migrate.cc b/src/cluster/slot_migrate.cc
index 4bd7e56c5..dd6e2efa1 100644
--- a/src/cluster/slot_migrate.cc
+++ b/src/cluster/slot_migrate.cc
@@ -790,7 +790,7 @@ Status SlotMigrator::migrateComplexKey(const rocksdb::Slice
&key, const Metadata
if (metadata.Type() > RedisTypeNames.size()) {
return {Status::NotOK, "unknown key type: " +
std::to_string(metadata.Type())};
}
- return {Status::NotOK, "unsupported complex key type: " +
RedisTypeNames[metadata.Type()]};
+ return {Status::NotOK, "unsupported complex key type: " +
metadata.TypeName()};
}
}
diff --git a/src/commands/cmd_search.cc b/src/commands/cmd_search.cc
index 75bf08dd9..1fcb08dc5 100644
--- a/src/commands/cmd_search.cc
+++ b/src/commands/cmd_search.cc
@@ -436,7 +436,7 @@ class CommandFTInfo : public Commander {
output->append(redis::SimpleString("index_definition"));
output->append(redis::MultiLen(4));
output->append(redis::SimpleString("key_type"));
-
output->append(redis::BulkString(RedisTypeNames[(size_t)info->metadata.on_data_type]));
+ output->append(redis::BulkString(info->metadata.OnDataTypeName()));
output->append(redis::SimpleString("prefixes"));
output->append(redis::ArrayOfBulkStrings(info->prefixes.prefixes));
diff --git a/src/search/search_encoding.h b/src/search/search_encoding.h
index bbc84f847..af8acea01 100644
--- a/src/search/search_encoding.h
+++ b/src/search/search_encoding.h
@@ -40,6 +40,8 @@ class IndexMetadata {
uint8_t flag = 0; // all reserved
IndexOnDataType on_data_type;
+ const std::string &OnDataTypeName() const { return
RedisTypeNames[(size_t)on_data_type]; }
+
void Encode(std::string *dst) const {
PutFixed8(dst, flag);
PutFixed8(dst, uint8_t(on_data_type));
diff --git a/src/storage/redis_db.cc b/src/storage/redis_db.cc
index 38845fef8..1ff52c8b0 100644
--- a/src/storage/redis_db.cc
+++ b/src/storage/redis_db.cc
@@ -477,7 +477,7 @@ rocksdb::Status Database::Dump(engine::Context &ctx, const
Slice &user_key, std:
infos->emplace_back("namespace");
infos->emplace_back(namespace_);
infos->emplace_back("type");
- infos->emplace_back(RedisTypeNames[metadata.Type()]);
+ infos->emplace_back(metadata.TypeName());
infos->emplace_back("version");
infos->emplace_back(std::to_string(metadata.version));
infos->emplace_back("expire");
diff --git a/src/storage/redis_metadata.cc b/src/storage/redis_metadata.cc
index c957901a0..a09b3f8cf 100644
--- a/src/storage/redis_metadata.cc
+++ b/src/storage/redis_metadata.cc
@@ -222,6 +222,8 @@ bool Metadata::operator==(const Metadata &that) const {
RedisType Metadata::Type() const { return static_cast<RedisType>(flags &
METADATA_TYPE_MASK); }
+const std::string &Metadata::TypeName() const { return RedisTypeNames[Type()];
}
+
size_t Metadata::GetOffsetAfterExpire(uint8_t flags) {
if (flags & METADATA_64BIT_ENCODING_MASK) {
return 1 + 8;
diff --git a/src/storage/redis_metadata.h b/src/storage/redis_metadata.h
index dd956e0e3..7fc97cbf2 100644
--- a/src/storage/redis_metadata.h
+++ b/src/storage/redis_metadata.h
@@ -176,6 +176,7 @@ class Metadata {
void PutExpire(std::string *dst) const;
RedisType Type() const;
+ const std::string &TypeName() const;
size_t CommonEncodedSize() const;
int64_t TTL() const;
timeval Time() const;