fix: properly set object with DenseLinkKey (#3980)

The interface around DenseLinkKey is confusing but SetObject
works only for non-link objects.
Added assert to catch these issues in the future.

Fixes #3973

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
Roman Gershman 2024-10-24 11:38:43 +03:00 committed by GitHub
parent 132ffe0920
commit a4659c0843
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 3 deletions

View file

@ -47,14 +47,16 @@ DenseSet::IteratorBase::IteratorBase(const DenseSet* owner, bool is_end)
}
void DenseSet::IteratorBase::SetExpiryTime(uint32_t ttl_sec) {
DensePtr* ptr = curr_entry_->IsLink() ? curr_entry_->AsLink() : curr_entry_;
void* src = ptr->GetObject();
if (!HasExpiry()) {
auto src = curr_entry_->GetObject();
void* new_obj = owner_->ObjectClone(src, false, true);
curr_entry_->SetObject(new_obj);
ptr->SetObject(new_obj);
curr_entry_->SetTtl(true);
owner_->ObjDelete(src, false);
src = new_obj;
}
owner_->ObjUpdateExpireTime(curr_entry_->GetObject(), ttl_sec);
owner_->ObjUpdateExpireTime(src, ttl_sec);
}
void DenseSet::IteratorBase::Advance() {