fix: skip empty objects on load and replication (#3514)

* skip empty objects in rdb save
* skip empty objects in rdb load
* delete empty keys in FindReadOnly

---------

Signed-off-by: kostas <kostas@dragonflydb.io>
This commit is contained in:
Kostas Kyrimis 2024-08-20 09:44:41 +03:00 committed by GitHub
parent 84a697dd75
commit b979994025
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 185 additions and 12 deletions

View file

@ -574,6 +574,12 @@ size_t CompactObj::Size() const {
case ROBJ_TAG:
raw_size = u_.r_obj.Size();
break;
case JSON_TAG:
raw_size = u_.json_obj.json_len;
break;
case SBF_TAG:
raw_size = u_.sbf->current_size();
break;
default:
LOG(DFATAL) << "Should not reach " << int(taglen_);
}
@ -684,9 +690,11 @@ void CompactObj::SetJson(JsonType&& j) {
if (taglen_ == JSON_TAG && u_.json_obj.encoding == kEncodingJsonCons) {
// already json
DCHECK(u_.json_obj.json_ptr != nullptr); // must be allocated
u_.json_obj.json_len = j.size();
u_.json_obj.json_ptr->swap(j);
} else {
SetMeta(JSON_TAG);
u_.json_obj.json_len = j.size();
u_.json_obj.json_ptr = AllocateMR<JsonType>(std::move(j));
u_.json_obj.encoding = kEncodingJsonCons;
}
@ -842,6 +850,11 @@ bool CompactObj::HasAllocated() const {
return true;
}
bool CompactObj::TagAllowsEmptyValue() const {
const auto type = ObjType();
return type == OBJ_JSON || type == OBJ_STREAM || type == OBJ_STRING || type == OBJ_SBF;
}
void __attribute__((noinline)) CompactObj::GetString(string* res) const {
res->resize(Size());
GetString(res->data());