add dense_set.SetExpiryTime in preparation for fieldexpire (#3780)

* feat: add DenseSet::IteratorBase::SetExpiryTime

This commit is in preparation for adding FIELDEXPIRE and HEXPIRE.

* fix: 0 is a valid input for MakeSetSds
This commit is contained in:
Joakim Rishaug 2024-10-01 10:36:00 +02:00 committed by GitHub
parent e3214cb603
commit 2ab480e160
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 115 additions and 38 deletions

View file

@ -46,6 +46,17 @@ DenseSet::IteratorBase::IteratorBase(const DenseSet* owner, bool is_end)
}
}
void DenseSet::IteratorBase::SetExpiryTime(uint32_t ttl_sec) {
if (!HasExpiry()) {
auto src = curr_entry_->GetObject();
void* new_obj = owner_->ObjectClone(src, false, true);
curr_entry_->SetObject(new_obj);
curr_entry_->SetTtl(true);
owner_->ObjDelete(src, false);
}
owner_->ObjUpdateExpireTime(curr_entry_->GetObject(), ttl_sec);
}
void DenseSet::IteratorBase::Advance() {
bool step_link = false;
DCHECK(curr_entry_);
@ -211,7 +222,7 @@ void DenseSet::CloneBatch(unsigned len, CloneItem* items, DenseSet* other) const
auto& src = items[i];
if (src.obj) {
// The majority of the CPU is spent in this block.
void* new_obj = other->ObjectClone(src.obj, src.has_ttl);
void* new_obj = other->ObjectClone(src.obj, src.has_ttl, false);
uint64_t hash = Hash(src.obj, 0);
other->AddUnique(new_obj, src.has_ttl, hash);
src.obj = nullptr;