Skip to content

Commit

Permalink
support recycle expired in compact
Browse files Browse the repository at this point in the history
  • Loading branch information
jjz921024 committed Jul 12, 2024
1 parent f0fe717 commit dfdb385
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/storage/compact_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "db_util.h"
#include "time_util.h"
#include "types/redis_bitmap.h"
#include "types/redis_hash.h"

namespace engine {

Expand Down Expand Up @@ -131,7 +132,9 @@ bool SubKeyFilter::Filter(int level, const Slice &key, const Slice &value, std::
return false;
}

return IsMetadataExpired(ikey, metadata) || (metadata.Type() == kRedisBitmap && redis::Bitmap::IsEmptySegment(value));
return IsMetadataExpired(ikey, metadata) ||
(metadata.Type() == kRedisBitmap && redis::Bitmap::IsEmptySegment(value)) ||
(metadata.Type() == kRedisHash && redis::Hash::IsExpiredField(metadata, value));
}

} // namespace engine
10 changes: 10 additions & 0 deletions src/types/redis_hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,16 @@ rocksdb::Status Hash::TTLFields(const Slice &user_key, const std::vector<Slice>
return rocksdb::Status::OK();
}

bool Hash::IsExpiredField(Metadata &metadata, const Slice &value) {
if (!(static_cast<HashMetadata*>(&metadata))->IsEncodedFieldExpire()) {
return false;
}
uint64_t expire = 0;
rocksdb::Slice data(value);
GetFixed64(&data, &expire);
return expire != 0 && expire < util::GetTimeStampMS();
}

rocksdb::Status Hash::decodeFieldValue(const HashMetadata &metadata, std::string *value, uint64_t &expire) {
if (!metadata.IsEncodedFieldExpire()) {
return rocksdb::Status::OK();
Expand Down
1 change: 1 addition & 0 deletions src/types/redis_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class Hash : public SubKeyScanner {
rocksdb::Status ExpireFields(const Slice &user_key, uint64_t expire_ms, const std::vector<Slice> &fields,
HashFieldExpireType type, bool is_persist, std::vector<int8_t> *ret);
rocksdb::Status TTLFields(const Slice &user_key, const std::vector<Slice> &fields, std::vector<int64_t> *ret);
static bool IsExpiredField(Metadata &metadata, const Slice &value);

private:
rocksdb::Status GetMetadata(Database::GetOptions get_options, const Slice &ns_key, HashMetadata *metadata);
Expand Down

0 comments on commit dfdb385

Please sign in to comment.