fix: enforce load limits when loading snapshot (#4136)

* fix: enforce load limits when loading snapshot

Prevent loading snapshots with used memory higher than max memory limit.

1. Store the used memory metadata only inside the summary file
2. Load the summary file before loading anything else, and if the used-memory is higher,
   abort the load.
---------

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
Roman Gershman 2024-11-20 06:12:47 +02:00 committed by GitHub
parent 4e7800f94f
commit 0e7ae34fe4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 82 additions and 81 deletions

View file

@ -94,7 +94,7 @@ TEST_F(RdbTest, Crc) {
TEST_F(RdbTest, LoadEmpty) {
auto ec = LoadRdb("empty.rdb");
CHECK(!ec);
ASSERT_FALSE(ec) << ec;
}
TEST_F(RdbTest, LoadSmall6) {
@ -646,4 +646,13 @@ TEST_F(RdbTest, LoadHugeStream) {
ASSERT_EQ(2000, CheckedInt({"xlen", "test:0"}));
}
TEST_F(RdbTest, SnapshotTooBig) {
// Run({"debug", "populate", "10000", "foo", "1000"});
// usleep(5000); // let the stats to sync
max_memory_limit = 100000;
used_mem_current = 1000000;
auto resp = Run({"debug", "reload"});
ASSERT_THAT(resp, ErrArg("Out of memory"));
}
} // namespace dfly