Snapchat / KeyDB

A Multithreaded Fork of Redis
https://keydb.dev
BSD 3-Clause "New" or "Revised" License
11.02k stars 564 forks source link

[BUG] NOTIFY_LOADED incorrect key #742

Open keithchew opened 7 months ago

keithchew commented 7 months ago

Describe the bug

There are 2 places where KeyDB does a KeySpaceEvent:

in db.cpp (for flash):

moduleNotifyKeyspaceEvent(NOTIFY_LOADED, "loaded", &keyobj, *(int *)data);

and in rdb.cpp (for RDB):

moduleNotifyKeyspaceEvent(NOTIFY_LOADED, "loaded", &keyobj, job.db->id);

Testing a single key in the DB:

HSET namespace:test-h:abc testType t2

start keydb-server without flash, the module will log out the key:

66202:66202:M 20 Nov 2023 07:21:47.765 # <mymodule> key [namespace:test-h:abc]

stop keydb-server enable flash storage provider start keydb-server, the RDB will be loaded into flash stop keydb-server start keydb-server, the module will log out the key:

66264:66264:M 20 Nov 2023 07:21:52.879 # <mymodule> key [namespace:test-h:abcn]

You can see the key is different, causing an issue in the module.

This notification was added in v6.3.3.

Expected behavior

Key to be correct, ie match up with RDB version.

keithchew commented 7 months ago

I can confirm that in StorageCache.h key_load_itr() method:

data->itrParent(rgchKey, cchKey, data->privdataParent);

is passing in const char* to the iterator, which is not consistent with how rdb loading passes the key to the iterator. It should be converted to sds, ie:

sds sdsKey = sdsnewlen(rgchKey, cchKey);