Skip to content

Commit 072c6b1

Browse files
committed
fix bug
1 parent 4feeafe commit 072c6b1

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

src/storage/redis_db.cc

+33-3
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,16 @@ rocksdb::Status Database::TTL(engine::Context &ctx, const Slice &user_key, int64
259259
Metadata metadata(kRedisNone, false);
260260
s = metadata.Decode(value);
261261
if (!s.ok()) return s;
262+
if (metadata.Type() == kRedisHash) {
263+
HashMetadata hash_metadata(false);
264+
s = hash_metadata.Decode(value);
265+
if (!s.ok()) return s;
266+
redis::Hash hash_db(storage_, namespace_);
267+
if (!hash_db.ExistValidField(ctx, ns_key, hash_metadata)) {
268+
*ttl = -2;
269+
return rocksdb::Status::OK();
270+
}
271+
}
262272
*ttl = metadata.TTL();
263273

264274
return rocksdb::Status::OK();
@@ -603,7 +613,7 @@ rocksdb::Status SubKeyScanner::Scan(engine::Context &ctx, RedisType type, const
603613
std::string raw_value;
604614
Slice rest;
605615

606-
rocksdb::Status s = GetMetadata(ctx, {type}, ns_key, &metadata);
616+
rocksdb::Status s = GetMetadata(ctx, {type}, ns_key, &raw_value, &metadata, &rest);
607617
if (!s.ok()) return s;
608618

609619
// for hash type, we should filter expired field if encoding is with_ttl
@@ -613,7 +623,7 @@ rocksdb::Status SubKeyScanner::Scan(engine::Context &ctx, RedisType type, const
613623
if (!GetFixed8(&rest, reinterpret_cast<uint8_t *>(&field_encoding))) {
614624
return rocksdb::Status::InvalidArgument();
615625
}
616-
if (uint8_t(field_encoding) > 1) {
626+
if (field_encoding > HashSubkeyEncoding::VALUE_WITH_TTL) {
617627
return rocksdb::Status::InvalidArgument("unexpected subkey encoding version");
618628
}
619629
if (field_encoding == HashSubkeyEncoding::VALUE_WITH_TTL) {
@@ -700,7 +710,17 @@ rocksdb::Status Database::existsInternal(engine::Context &ctx, const std::vector
700710
Metadata metadata(kRedisNone, false);
701711
s = metadata.Decode(value);
702712
if (!s.ok()) return s;
703-
if (!metadata.Expired()) *ret += 1;
713+
if (metadata.Expired()) continue;
714+
if (metadata.Type() == kRedisHash) {
715+
HashMetadata hash_metadata(false);
716+
s = hash_metadata.Decode(value);
717+
if (!s.ok()) return s;
718+
redis::Hash hash_db(storage_, namespace_);
719+
if (!hash_db.ExistValidField(ctx, key, hash_metadata)) {
720+
continue;
721+
}
722+
}
723+
*ret += 1;
704724
}
705725
}
706726
return rocksdb::Status::OK();
@@ -717,6 +737,16 @@ rocksdb::Status Database::typeInternal(engine::Context &ctx, const Slice &key, R
717737
if (!s.ok()) return s.IsNotFound() ? rocksdb::Status::OK() : s;
718738
if (metadata.Expired()) {
719739
*type = kRedisNone;
740+
} else if (metadata.Type() == kRedisHash) {
741+
HashMetadata hash_metadata(false);
742+
s = hash_metadata.Decode(value);
743+
if (!s.ok()) return s;
744+
redis::Hash hash_db(storage_, namespace_);
745+
if (hash_db.ExistValidField(ctx, key, hash_metadata)) {
746+
*type = metadata.Type();
747+
} else {
748+
*type = kRedisNone;
749+
}
720750
} else {
721751
*type = metadata.Type();
722752
}

0 commit comments

Comments
 (0)