fix(server): rdb loader catch bad alloc (#1748)

While loading rdb snapshot, if oom is reached a bad alloc exception is thrown. Now we
catch it and write warning to log and fali loader.

Signed-off-by: adi_holden <adi@dragonflydb.io>
This commit is contained in:
adiholden 2023-08-27 13:48:41 +03:00 committed by GitHub
parent e020f8734b
commit 901d3fff58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2268,9 +2268,16 @@ void RdbLoader::LoadItemsBuffer(DbIndex db_ind, const ItemsBuf& ib) {
if (item->expire_ms > 0 && db_cntx.time_now_ms >= item->expire_ms)
continue;
auto [it, added] = db_slice.AddOrUpdate(db_cntx, item->key, std::move(pv), item->expire_ms);
if (!added) {
LOG(WARNING) << "RDB has duplicated key '" << item->key << "' in DB " << db_ind;
try {
auto [it, added] = db_slice.AddOrUpdate(db_cntx, item->key, std::move(pv), item->expire_ms);
if (!added) {
LOG(WARNING) << "RDB has duplicated key '" << item->key << "' in DB " << db_ind;
}
} catch (const std::bad_alloc&) {
LOG(ERROR) << "OOM failed to add key '" << item->key << "' in DB " << db_ind;
ec_ = RdbError(errc::out_of_memory);
stop_early_ = true;
break;
}
}