From bb34d86daac4d47b954b4e2e1f87947d51a1dd50 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Thu, 5 Jan 2023 23:26:31 -0800 Subject: [PATCH 01/30] add option to notify modules of all keys loaded from flash --- src/config.cpp | 13 +++++++++++++ src/redismodule.h | 1 + src/server.h | 2 ++ 3 files changed, 16 insertions(+) diff --git a/src/config.cpp b/src/config.cpp index 253f0726a..fc03b9ec9 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -360,6 +360,18 @@ bool initializeStorageProvider(const char **err) serverLog(LL_NOTICE, "Initializing FLASH storage provider (this may take a long time)"); adjustOpenFilesLimit(); g_pserver->m_pstorageFactory = CreateRocksDBStorageFactory(g_sdsArgs, cserver.dbnum, cserver.storage_conf, cserver.storage_conf ? strlen(cserver.storage_conf) : 0); + if (g_pserver->config_notify_flash_load) { + moduleFireServerEvent(REDISMODULE_EVENT_LOADING, REDISMODULE_SUBEVENT_LOADING_FLASH_START, NULL); + for (int idb = 0; idb < cserver.dbnum; ++idb) { + auto spsnapshot = g_pserver->db[idb]->CloneStorageCache(); + spsnapshot->enumerate([idb](const char *rgchKey, size_t cchKey, const void *, size_t) -> bool { + robj *keyobj = createEmbeddedStringObject(rgchKey, cchKey); + moduleNotifyKeyspaceEvent(NOTIFY_LOADED, "loaded", keyobj, idb); + return true; + }); + } + moduleFireServerEvent(REDISMODULE_EVENT_LOADING, REDISMODULE_SUBEVENT_LOADING_ENDED, NULL); + } #else serverLog(LL_WARNING, "To use the flash storage provider please compile KeyDB with ENABLE_FLASH=yes"); serverLog(LL_WARNING, "Exiting due to the use of an unsupported storage provider"); @@ -2910,6 +2922,7 @@ standardConfig configs[] = { createBoolConfig("allow-write-during-load", NULL, MODIFIABLE_CONFIG, g_pserver->fWriteDuringActiveLoad, 0, NULL, NULL), createBoolConfig("force-backlog-disk-reserve", NULL, MODIFIABLE_CONFIG, cserver.force_backlog_disk, 0, NULL, NULL), createBoolConfig("soft-shutdown", NULL, MODIFIABLE_CONFIG, g_pserver->config_soft_shutdown, 0, NULL, NULL), + createBoolConfig("module-notify-flash-load", NULL, MODIFIABLE_CONFIG, g_pserver->config_notify_flash_load, 0, NULL, NULL), #ifdef USE_OPENSSL createIntConfig("tls-port", NULL, MODIFIABLE_CONFIG, 0, 65535, g_pserver->tls_port, 0, INTEGER_CONFIG, NULL, updateTLSPort), /* TCP port. */ diff --git a/src/redismodule.h b/src/redismodule.h index 4313aee01..10736797a 100644 --- a/src/redismodule.h +++ b/src/redismodule.h @@ -326,6 +326,7 @@ static const RedisModuleEvent #define REDISMODULE_SUBEVENT_LOADING_ENDED 3 #define REDISMODULE_SUBEVENT_LOADING_FAILED 4 #define _REDISMODULE_SUBEVENT_LOADING_NEXT 5 +#define REDISMODULE_SUBEVENT_LOADING_FLASH_START 6 #define REDISMODULE_SUBEVENT_CLIENT_CHANGE_CONNECTED 0 #define REDISMODULE_SUBEVENT_CLIENT_CHANGE_DISCONNECTED 1 diff --git a/src/server.h b/src/server.h index eee584f2d..abbfa7a37 100644 --- a/src/server.h +++ b/src/server.h @@ -2731,6 +2731,8 @@ struct redisServer { int config_soft_shutdown = false; bool soft_shutdown = false; + int config_notify_flash_load = false; + /* Lock Contention Ring Buffer */ static const size_t s_lockContentionSamples = 64; uint16_t rglockSamples[s_lockContentionSamples]; From 3d7117a834247cac6c8e2f8e0e994598b8e6993c Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Fri, 6 Jan 2023 22:11:46 -0800 Subject: [PATCH 02/30] add test module --- src/modules/Makefile | 7 ++- src/modules/helloload.c | 94 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 src/modules/helloload.c diff --git a/src/modules/Makefile b/src/modules/Makefile index 3db19e79a..f8e4aab80 100644 --- a/src/modules/Makefile +++ b/src/modules/Makefile @@ -13,7 +13,7 @@ endif .SUFFIXES: .c .so .xo .o -all: helloworld.so hellotype.so helloblock.so hellocluster.so hellotimer.so hellodict.so hellohook.so helloacl.so +all: helloworld.so hellotype.so helloblock.so hellocluster.so hellotimer.so hellodict.so hellohook.so helloacl.so helloload.so .c.xo: $(CC) -I. $(CFLAGS) $(SHOBJ_CFLAGS) -fPIC -c $< -o $@ @@ -58,5 +58,10 @@ helloacl.xo: ../redismodule.h helloacl.so: helloacl.xo $(LD) -o $@ $< $(SHOBJ_LDFLAGS) $(LIBS) -lc +helloload.xo: ../redismodule.h + +helloload.so: helloload.xo + $(LD) -o $@ $< $(SHOBJ_LDFLAGS) $(LIBS) -lc + clean: rm -rf *.xo *.so diff --git a/src/modules/helloload.c b/src/modules/helloload.c new file mode 100644 index 000000000..f6f035bcf --- /dev/null +++ b/src/modules/helloload.c @@ -0,0 +1,94 @@ +/* Server hooks API example + * + * ----------------------------------------------------------------------------- + * + * Copyright (c) 2019, Salvatore Sanfilippo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Redis nor the names of its contributors may be used + * to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#define REDISMODULE_EXPERIMENTAL_API +#include "../redismodule.h" +#include +#include +#include +#include + +int count, finalCount; + +/* Client state change callback. */ +void loadCallback(RedisModuleCtx *ctx, RedisModuleEvent e, uint64_t sub, void *data) +{ + REDISMODULE_NOT_USED(ctx); + REDISMODULE_NOT_USED(e); + REDISMODULE_NOT_USED(data); + + if (sub == REDISMODULE_SUBEVENT_LOADING_FLASH_START || sub == REDISMODULE_SUBEVENT_LOADING_RDB_START || sub == REDISMODULE_SUBEVENT_LOADING_AOF_START || sub == REDISMODULE_SUBEVENT_LOADING_REPL_START) { + count = 0; + finalCount = 0; + } else if (sub == REDISMODULE_SUBEVENT_LOADING_ENDED) { + finalCount = count; + } +} + +void loadKeyCallback(RedisModuleCtx *ctx, RedisModuleEvent e, uint64_t sub, void *data) +{ + REDISMODULE_NOT_USED(ctx); + REDISMODULE_NOT_USED(e); + REDISMODULE_NOT_USED(data); + + count++; +} + +int HelloLoadCheck_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { + RedisModule_AutoMemory(ctx); /* Use automatic memory management. */ + + if (argc != 1) return RedisModule_WrongArity(ctx); + + RedisModule_ReplyWithLongLong(ctx, RedisModule_DbSize(ctx) == finalCount); + + return REDISMODULE_OK; +} + +/* This function must be present on each Redis module. It is used in order to + * register the commands into the Redis server. */ +int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { + REDISMODULE_NOT_USED(argv); + REDISMODULE_NOT_USED(argc); + + if (RedisModule_Init(ctx,"hellohook",1,REDISMODULE_APIVER_1) + == REDISMODULE_ERR) return REDISMODULE_ERR; + + RedisModule_SubscribeToServerEvent(ctx, + RedisModuleEvent_Loading, loadCallback); + RedisModule_SubscribeToKeyspaceEvents(ctx, + REDISMODULE_NOTIFY_LOADED, loadKeyCallback); + + if (RedisModule_CreateCommand(ctx,"helloload.check", + HelloLoadCheck_RedisCommand,"readonly",1,1,1) == REDISMODULE_ERR) + return REDISMODULE_ERR; + return REDISMODULE_OK; +} From 8a12ebbc86ba10ab86f52b9aa289636f44f71243 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Sat, 7 Jan 2023 00:28:20 -0800 Subject: [PATCH 03/30] add log for each loaded key --- src/modules/helloload.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/helloload.c b/src/modules/helloload.c index f6f035bcf..a7445d847 100644 --- a/src/modules/helloload.c +++ b/src/modules/helloload.c @@ -60,6 +60,8 @@ void loadKeyCallback(RedisModuleCtx *ctx, RedisModuleEvent e, uint64_t sub, void REDISMODULE_NOT_USED(e); REDISMODULE_NOT_USED(data); + RedisModule_Log(ctx, REDISMODULE_LOGLEVEL_NOTICE, "Loaded key: %s", data); + count++; } From 391df0ab08ef3eb34af565bfa114b09362983c13 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Sat, 7 Jan 2023 00:32:10 -0800 Subject: [PATCH 04/30] wrong function type --- src/modules/helloload.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/helloload.c b/src/modules/helloload.c index a7445d847..b50857cc8 100644 --- a/src/modules/helloload.c +++ b/src/modules/helloload.c @@ -54,13 +54,13 @@ void loadCallback(RedisModuleCtx *ctx, RedisModuleEvent e, uint64_t sub, void *d } } -void loadKeyCallback(RedisModuleCtx *ctx, RedisModuleEvent e, uint64_t sub, void *data) +void loadKeyCallback(RedisModuleCtx *ctx, int type, const char *event, RedisModuleString *key) { REDISMODULE_NOT_USED(ctx); - REDISMODULE_NOT_USED(e); - REDISMODULE_NOT_USED(data); + REDISMODULE_NOT_USED(type); + REDISMODULE_NOT_USED(event); - RedisModule_Log(ctx, REDISMODULE_LOGLEVEL_NOTICE, "Loaded key: %s", data); + RedisModule_Log(ctx, REDISMODULE_LOGLEVEL_NOTICE, "Loaded key: %s", key); count++; } From cfb77ce26c06de23d29ac34279b338bcad64a6bc Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Sat, 7 Jan 2023 00:33:08 -0800 Subject: [PATCH 05/30] wrong function type --- src/modules/helloload.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/helloload.c b/src/modules/helloload.c index b50857cc8..2a1622ed2 100644 --- a/src/modules/helloload.c +++ b/src/modules/helloload.c @@ -54,7 +54,7 @@ void loadCallback(RedisModuleCtx *ctx, RedisModuleEvent e, uint64_t sub, void *d } } -void loadKeyCallback(RedisModuleCtx *ctx, int type, const char *event, RedisModuleString *key) +int loadKeyCallback(RedisModuleCtx *ctx, int type, const char *event, RedisModuleString *key) { REDISMODULE_NOT_USED(ctx); REDISMODULE_NOT_USED(type); @@ -63,6 +63,7 @@ void loadKeyCallback(RedisModuleCtx *ctx, int type, const char *event, RedisMod RedisModule_Log(ctx, REDISMODULE_LOGLEVEL_NOTICE, "Loaded key: %s", key); count++; + return 0; } int HelloLoadCheck_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { From 8695915956ff92460c35d205accafe0e01b12479 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Sat, 7 Jan 2023 00:35:19 -0800 Subject: [PATCH 06/30] more log --- src/config.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config.cpp b/src/config.cpp index fc03b9ec9..5ed75776b 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -366,6 +366,7 @@ bool initializeStorageProvider(const char **err) auto spsnapshot = g_pserver->db[idb]->CloneStorageCache(); spsnapshot->enumerate([idb](const char *rgchKey, size_t cchKey, const void *, size_t) -> bool { robj *keyobj = createEmbeddedStringObject(rgchKey, cchKey); + serverLog(LL_NOTICE, "Loaded key %.s", cchKey, rhchKey); moduleNotifyKeyspaceEvent(NOTIFY_LOADED, "loaded", keyobj, idb); return true; }); From 3d43e6b29c0b2ef112506f6bdc58bffe9431f7e7 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Sat, 7 Jan 2023 00:36:04 -0800 Subject: [PATCH 07/30] h -> h --- src/config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.cpp b/src/config.cpp index 5ed75776b..bcf058c81 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -366,7 +366,7 @@ bool initializeStorageProvider(const char **err) auto spsnapshot = g_pserver->db[idb]->CloneStorageCache(); spsnapshot->enumerate([idb](const char *rgchKey, size_t cchKey, const void *, size_t) -> bool { robj *keyobj = createEmbeddedStringObject(rgchKey, cchKey); - serverLog(LL_NOTICE, "Loaded key %.s", cchKey, rhchKey); + serverLog(LL_NOTICE, "Loaded key %.s", cchKey, rgchKey); moduleNotifyKeyspaceEvent(NOTIFY_LOADED, "loaded", keyobj, idb); return true; }); From 5911a5d7a9e74d772d0313cc0a633f1611f84648 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Sat, 7 Jan 2023 00:37:44 -0800 Subject: [PATCH 08/30] missing * --- src/config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.cpp b/src/config.cpp index bcf058c81..811aa9c94 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -366,7 +366,7 @@ bool initializeStorageProvider(const char **err) auto spsnapshot = g_pserver->db[idb]->CloneStorageCache(); spsnapshot->enumerate([idb](const char *rgchKey, size_t cchKey, const void *, size_t) -> bool { robj *keyobj = createEmbeddedStringObject(rgchKey, cchKey); - serverLog(LL_NOTICE, "Loaded key %.s", cchKey, rgchKey); + serverLog(LL_NOTICE, "Loaded key %.*s", cchKey, rgchKey); moduleNotifyKeyspaceEvent(NOTIFY_LOADED, "loaded", keyobj, idb); return true; }); From 505abe85e626618d070cfdb73c822590dcc6cf79 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Sat, 7 Jan 2023 00:44:57 -0800 Subject: [PATCH 09/30] move to loadDataFromDisk --- src/config.cpp | 13 ------------- src/server.cpp | 13 +++++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index 811aa9c94..edb1cc16b 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -360,19 +360,6 @@ bool initializeStorageProvider(const char **err) serverLog(LL_NOTICE, "Initializing FLASH storage provider (this may take a long time)"); adjustOpenFilesLimit(); g_pserver->m_pstorageFactory = CreateRocksDBStorageFactory(g_sdsArgs, cserver.dbnum, cserver.storage_conf, cserver.storage_conf ? strlen(cserver.storage_conf) : 0); - if (g_pserver->config_notify_flash_load) { - moduleFireServerEvent(REDISMODULE_EVENT_LOADING, REDISMODULE_SUBEVENT_LOADING_FLASH_START, NULL); - for (int idb = 0; idb < cserver.dbnum; ++idb) { - auto spsnapshot = g_pserver->db[idb]->CloneStorageCache(); - spsnapshot->enumerate([idb](const char *rgchKey, size_t cchKey, const void *, size_t) -> bool { - robj *keyobj = createEmbeddedStringObject(rgchKey, cchKey); - serverLog(LL_NOTICE, "Loaded key %.*s", cchKey, rgchKey); - moduleNotifyKeyspaceEvent(NOTIFY_LOADED, "loaded", keyobj, idb); - return true; - }); - } - moduleFireServerEvent(REDISMODULE_EVENT_LOADING, REDISMODULE_SUBEVENT_LOADING_ENDED, NULL); - } #else serverLog(LL_WARNING, "To use the flash storage provider please compile KeyDB with ENABLE_FLASH=yes"); serverLog(LL_WARNING, "Exiting due to the use of an unsupported storage provider"); diff --git a/src/server.cpp b/src/server.cpp index 3a1fbbede..8c049845b 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -6953,6 +6953,19 @@ void loadDataFromDisk(void) { if (g_pserver->m_pstorageFactory) { + if (g_pserver->config_notify_flash_load) { + moduleFireServerEvent(REDISMODULE_EVENT_LOADING, REDISMODULE_SUBEVENT_LOADING_FLASH_START, NULL); + for (int idb = 0; idb < cserver.dbnum; ++idb) { + auto spsnapshot = g_pserver->db[idb]->CloneStorageCache(); + spsnapshot->enumerate([idb](const char *rgchKey, size_t cchKey, const void *, size_t) -> bool { + robj *keyobj = createEmbeddedStringObject(rgchKey, cchKey); + serverLog(LL_NOTICE, "Loaded key %.*s", cchKey, rgchKey); + moduleNotifyKeyspaceEvent(NOTIFY_LOADED, "loaded", keyobj, idb); + return true; + }); + } + moduleFireServerEvent(REDISMODULE_EVENT_LOADING, REDISMODULE_SUBEVENT_LOADING_ENDED, NULL); + } for (int idb = 0; idb < cserver.dbnum; ++idb) { if (g_pserver->db[idb]->size() > 0) From 630591ccd0e77976acc7c252addd9b5429a75a68 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Sat, 7 Jan 2023 00:56:34 -0800 Subject: [PATCH 10/30] fix logs --- src/modules/helloload.c | 2 ++ src/server.cpp | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/helloload.c b/src/modules/helloload.c index 2a1622ed2..c20d853b4 100644 --- a/src/modules/helloload.c +++ b/src/modules/helloload.c @@ -60,6 +60,8 @@ int loadKeyCallback(RedisModuleCtx *ctx, int type, const char *event, RedisModu REDISMODULE_NOT_USED(type); REDISMODULE_NOT_USED(event); + const char *keyname = RedisModule_StringPtrLen(key, NULL); + RedisModule_Log(ctx, REDISMODULE_LOGLEVEL_NOTICE, "Loaded key: %s", key); count++; diff --git a/src/server.cpp b/src/server.cpp index 8c049845b..f77b0d9df 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -6958,8 +6958,7 @@ void loadDataFromDisk(void) { for (int idb = 0; idb < cserver.dbnum; ++idb) { auto spsnapshot = g_pserver->db[idb]->CloneStorageCache(); spsnapshot->enumerate([idb](const char *rgchKey, size_t cchKey, const void *, size_t) -> bool { - robj *keyobj = createEmbeddedStringObject(rgchKey, cchKey); - serverLog(LL_NOTICE, "Loaded key %.*s", cchKey, rgchKey); + robj *keyobj = createEmbeddedStringObject(rgchKey, cchKey); moduleNotifyKeyspaceEvent(NOTIFY_LOADED, "loaded", keyobj, idb); return true; }); From 47c7d752885794291da388b57a4a373c21744b8c Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Sat, 7 Jan 2023 00:58:23 -0800 Subject: [PATCH 11/30] missed the name part --- src/modules/helloload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/helloload.c b/src/modules/helloload.c index c20d853b4..289345159 100644 --- a/src/modules/helloload.c +++ b/src/modules/helloload.c @@ -62,7 +62,7 @@ int loadKeyCallback(RedisModuleCtx *ctx, int type, const char *event, RedisModu const char *keyname = RedisModule_StringPtrLen(key, NULL); - RedisModule_Log(ctx, REDISMODULE_LOGLEVEL_NOTICE, "Loaded key: %s", key); + RedisModule_Log(ctx, REDISMODULE_LOGLEVEL_NOTICE, "Loaded key: %s", keyname); count++; return 0; From 4757fc8ab62d560e21c01cb78a744b1b0c5e4337 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Sat, 7 Jan 2023 01:01:07 -0800 Subject: [PATCH 12/30] fix warnings --- src/modules/helloload.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/modules/helloload.c b/src/modules/helloload.c index 289345159..82da2db01 100644 --- a/src/modules/helloload.c +++ b/src/modules/helloload.c @@ -37,11 +37,10 @@ #include #include -int count, finalCount; +size_t count, finalCount; /* Client state change callback. */ -void loadCallback(RedisModuleCtx *ctx, RedisModuleEvent e, uint64_t sub, void *data) -{ +void loadCallback(RedisModuleCtx *ctx, RedisModuleEvent e, uint64_t sub, void *data) { REDISMODULE_NOT_USED(ctx); REDISMODULE_NOT_USED(e); REDISMODULE_NOT_USED(data); @@ -54,8 +53,7 @@ void loadCallback(RedisModuleCtx *ctx, RedisModuleEvent e, uint64_t sub, void *d } } -int loadKeyCallback(RedisModuleCtx *ctx, int type, const char *event, RedisModuleString *key) -{ +int loadKeyCallback(RedisModuleCtx *ctx, int type, const char *event, RedisModuleString *key) { REDISMODULE_NOT_USED(ctx); REDISMODULE_NOT_USED(type); REDISMODULE_NOT_USED(event); @@ -69,6 +67,7 @@ int loadKeyCallback(RedisModuleCtx *ctx, int type, const char *event, RedisModu } int HelloLoadCheck_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { + REDISMODULE_NOT_USED(argv); RedisModule_AutoMemory(ctx); /* Use automatic memory management. */ if (argc != 1) return RedisModule_WrongArity(ctx); From 1329436c801b206aaf676d5f0b286417a00cb570 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Sat, 7 Jan 2023 01:06:50 -0800 Subject: [PATCH 13/30] move test module to test folder --- src/modules/helloload.c => tests/modules/load.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename src/modules/helloload.c => tests/modules/load.c (92%) diff --git a/src/modules/helloload.c b/tests/modules/load.c similarity index 92% rename from src/modules/helloload.c rename to tests/modules/load.c index 82da2db01..62d07f92a 100644 --- a/src/modules/helloload.c +++ b/tests/modules/load.c @@ -66,7 +66,7 @@ int loadKeyCallback(RedisModuleCtx *ctx, int type, const char *event, RedisModu return 0; } -int HelloLoadCheck_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { +int LoadCheck_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { REDISMODULE_NOT_USED(argv); RedisModule_AutoMemory(ctx); /* Use automatic memory management. */ @@ -83,7 +83,7 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) REDISMODULE_NOT_USED(argv); REDISMODULE_NOT_USED(argc); - if (RedisModule_Init(ctx,"hellohook",1,REDISMODULE_APIVER_1) + if (RedisModule_Init(ctx,"load",1,REDISMODULE_APIVER_1) == REDISMODULE_ERR) return REDISMODULE_ERR; RedisModule_SubscribeToServerEvent(ctx, @@ -91,8 +91,8 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) RedisModule_SubscribeToKeyspaceEvents(ctx, REDISMODULE_NOTIFY_LOADED, loadKeyCallback); - if (RedisModule_CreateCommand(ctx,"helloload.check", - HelloLoadCheck_RedisCommand,"readonly",1,1,1) == REDISMODULE_ERR) + if (RedisModule_CreateCommand(ctx,"load.check", + LoadCheck_RedisCommand,"readonly",1,1,1) == REDISMODULE_ERR) return REDISMODULE_ERR; return REDISMODULE_OK; } From 064c701f608b385d6a452272e9c8d9dafc5e4bb9 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Sat, 7 Jan 2023 01:14:32 -0800 Subject: [PATCH 14/30] add simple module test --- tests/unit/moduleapi/load.tcl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/unit/moduleapi/load.tcl diff --git a/tests/unit/moduleapi/load.tcl b/tests/unit/moduleapi/load.tcl new file mode 100644 index 000000000..d09986040 --- /dev/null +++ b/tests/unit/moduleapi/load.tcl @@ -0,0 +1,15 @@ +set testmodule [file normalize tests/modules/load.so] + +if {$::flash_enabled} { + start_server {tags {"modules"} overrides {storage-provider {flash ./rocks.db.master} databases 256}} { + r flushall + r set foo bar + r set bar foo + r set foobar barfoo + } + start_server {tags {"modules"} overrides {storage-provider {flash ./rocks.db.master} databases 256}} { + test "Module is notified of keys loaded from flash" { + r load.check + } {1} + } +} \ No newline at end of file From 2c9ef56099bdfa7a05f6271ef09e503531045ff6 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Sat, 7 Jan 2023 01:15:52 -0800 Subject: [PATCH 15/30] forgot to update script --- runtest-moduleapi | 1 + 1 file changed, 1 insertion(+) diff --git a/runtest-moduleapi b/runtest-moduleapi index 8adf2171d..4f0bca851 100755 --- a/runtest-moduleapi +++ b/runtest-moduleapi @@ -37,5 +37,6 @@ $TCLSH tests/test_helper.tcl \ --single unit/moduleapi/hash \ --single unit/moduleapi/zset \ --single unit/moduleapi/stream \ +--single unit/moduleapi/load \ --config server-threads 3 \ "${@}" From 33b2de4a08a7644b732432307c5e2cfdf35b62ba Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Sat, 7 Jan 2023 01:21:01 -0800 Subject: [PATCH 16/30] make test work --- tests/modules/Makefile | 3 ++- tests/modules/load.c | 8 ++++---- tests/unit/moduleapi/load.tcl | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/modules/Makefile b/tests/modules/Makefile index 1beb217b8..b630508cb 100644 --- a/tests/modules/Makefile +++ b/tests/modules/Makefile @@ -39,7 +39,8 @@ TEST_MODULES = \ defragtest.so \ hash.so \ zset.so \ - stream.so + stream.so \ + load.so .PHONY: all diff --git a/tests/modules/load.c b/tests/modules/load.c index 62d07f92a..313c1467f 100644 --- a/tests/modules/load.c +++ b/tests/modules/load.c @@ -66,13 +66,13 @@ int loadKeyCallback(RedisModuleCtx *ctx, int type, const char *event, RedisModu return 0; } -int LoadCheck_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { +int LoadCount_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { REDISMODULE_NOT_USED(argv); RedisModule_AutoMemory(ctx); /* Use automatic memory management. */ if (argc != 1) return RedisModule_WrongArity(ctx); - RedisModule_ReplyWithLongLong(ctx, RedisModule_DbSize(ctx) == finalCount); + RedisModule_ReplyWithLongLong(ctx, finalCount); return REDISMODULE_OK; } @@ -91,8 +91,8 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) RedisModule_SubscribeToKeyspaceEvents(ctx, REDISMODULE_NOTIFY_LOADED, loadKeyCallback); - if (RedisModule_CreateCommand(ctx,"load.check", - LoadCheck_RedisCommand,"readonly",1,1,1) == REDISMODULE_ERR) + if (RedisModule_CreateCommand(ctx,"load.count", + LoadCount_RedisCommand,"readonly",1,1,1) == REDISMODULE_ERR) return REDISMODULE_ERR; return REDISMODULE_OK; } diff --git a/tests/unit/moduleapi/load.tcl b/tests/unit/moduleapi/load.tcl index d09986040..45d2886ce 100644 --- a/tests/unit/moduleapi/load.tcl +++ b/tests/unit/moduleapi/load.tcl @@ -9,7 +9,7 @@ if {$::flash_enabled} { } start_server {tags {"modules"} overrides {storage-provider {flash ./rocks.db.master} databases 256}} { test "Module is notified of keys loaded from flash" { - r load.check - } {1} + assert_equal [r load.count] [r dbsize] + } } } \ No newline at end of file From d383f42e0d5055d7f9f478f2a15cf9ef676be4f2 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Sat, 7 Jan 2023 01:22:14 -0800 Subject: [PATCH 17/30] remove unnecessary includes --- tests/modules/load.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/modules/load.c b/tests/modules/load.c index 313c1467f..62a0f1e7e 100644 --- a/tests/modules/load.c +++ b/tests/modules/load.c @@ -31,11 +31,7 @@ */ #define REDISMODULE_EXPERIMENTAL_API -#include "../redismodule.h" -#include -#include -#include -#include +#include "redismodule.h" size_t count, finalCount; From b952a456f9700340fa96b92700a2f18cbabde9af Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Sat, 7 Jan 2023 01:26:24 -0800 Subject: [PATCH 18/30] idk --- tests/modules/load.c | 2 +- tests/unit/moduleapi/load.tcl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/modules/load.c b/tests/modules/load.c index 62a0f1e7e..a70579b6f 100644 --- a/tests/modules/load.c +++ b/tests/modules/load.c @@ -87,7 +87,7 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) RedisModule_SubscribeToKeyspaceEvents(ctx, REDISMODULE_NOTIFY_LOADED, loadKeyCallback); - if (RedisModule_CreateCommand(ctx,"load.count", + if (RedisModule_CreateCommand(ctx, "load.count", LoadCount_RedisCommand,"readonly",1,1,1) == REDISMODULE_ERR) return REDISMODULE_ERR; return REDISMODULE_OK; diff --git a/tests/unit/moduleapi/load.tcl b/tests/unit/moduleapi/load.tcl index 45d2886ce..1cdf4db24 100644 --- a/tests/unit/moduleapi/load.tcl +++ b/tests/unit/moduleapi/load.tcl @@ -7,7 +7,7 @@ if {$::flash_enabled} { r set bar foo r set foobar barfoo } - start_server {tags {"modules"} overrides {storage-provider {flash ./rocks.db.master} databases 256}} { + start_server {tags {"modules"} overrides {storage-provider {flash ./rocks.db.master} databases 256 loadmodule $testmodule}} { test "Module is notified of keys loaded from flash" { assert_equal [r load.count] [r dbsize] } From 801d858f9beb99bdc955073b12850ba0cc67f406 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Sat, 7 Jan 2023 01:27:41 -0800 Subject: [PATCH 19/30] I don't know tcl --- tests/unit/moduleapi/load.tcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/moduleapi/load.tcl b/tests/unit/moduleapi/load.tcl index 1cdf4db24..379a4419d 100644 --- a/tests/unit/moduleapi/load.tcl +++ b/tests/unit/moduleapi/load.tcl @@ -7,7 +7,7 @@ if {$::flash_enabled} { r set bar foo r set foobar barfoo } - start_server {tags {"modules"} overrides {storage-provider {flash ./rocks.db.master} databases 256 loadmodule $testmodule}} { + start_server {tags {"modules"} overrides {storage-provider {flash ./rocks.db.master} databases 256 loadmodule "$testmodule"}} { test "Module is notified of keys loaded from flash" { assert_equal [r load.count] [r dbsize] } From 2838edc661ed100d339376a88abc64c84b40a1b4 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Sat, 7 Jan 2023 01:29:09 -0800 Subject: [PATCH 20/30] just work --- tests/unit/moduleapi/load.tcl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/unit/moduleapi/load.tcl b/tests/unit/moduleapi/load.tcl index 379a4419d..ceb7eccb3 100644 --- a/tests/unit/moduleapi/load.tcl +++ b/tests/unit/moduleapi/load.tcl @@ -1,5 +1,3 @@ -set testmodule [file normalize tests/modules/load.so] - if {$::flash_enabled} { start_server {tags {"modules"} overrides {storage-provider {flash ./rocks.db.master} databases 256}} { r flushall @@ -7,7 +5,7 @@ if {$::flash_enabled} { r set bar foo r set foobar barfoo } - start_server {tags {"modules"} overrides {storage-provider {flash ./rocks.db.master} databases 256 loadmodule "$testmodule"}} { + start_server {tags {"modules"} overrides {storage-provider {flash ./rocks.db.master} databases 256 loadmodule tests/modules/load.so}} { test "Module is notified of keys loaded from flash" { assert_equal [r load.count] [r dbsize] } From cc2aa192cf4f981285f87fa2c7686dd63c22c0bf Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Sat, 7 Jan 2023 01:33:54 -0800 Subject: [PATCH 21/30] help --- keydb.conf | 3 +++ tests/unit/moduleapi/load.tcl | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/keydb.conf b/keydb.conf index 800657138..05e3b96fa 100644 --- a/keydb.conf +++ b/keydb.conf @@ -2088,3 +2088,6 @@ active-client-balancing yes # disk space or any other I/O error KeyDB will instead use memory. # # blob-support false + +# Use this config to notify modules of every key loaded from flash on startup (warning: can make startup much slower) +# module-notify-flash-load yes diff --git a/tests/unit/moduleapi/load.tcl b/tests/unit/moduleapi/load.tcl index ceb7eccb3..a8cdceee7 100644 --- a/tests/unit/moduleapi/load.tcl +++ b/tests/unit/moduleapi/load.tcl @@ -5,7 +5,7 @@ if {$::flash_enabled} { r set bar foo r set foobar barfoo } - start_server {tags {"modules"} overrides {storage-provider {flash ./rocks.db.master} databases 256 loadmodule tests/modules/load.so}} { + start_server {tags {"modules"} overrides {storage-provider {flash ./rocks.db.master} databases 256 loadmodule tests/modules/load.so module-notify-flash-load yes}} { test "Module is notified of keys loaded from flash" { assert_equal [r load.count] [r dbsize] } From e166ba12bb0994d2914d734ced87de1acd532039 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Sat, 7 Jan 2023 01:36:09 -0800 Subject: [PATCH 22/30] gsdgd --- tests/unit/moduleapi/load.tcl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/unit/moduleapi/load.tcl b/tests/unit/moduleapi/load.tcl index a8cdceee7..83fd65cdc 100644 --- a/tests/unit/moduleapi/load.tcl +++ b/tests/unit/moduleapi/load.tcl @@ -1,3 +1,5 @@ +set testmodule [file normalize tests/modules/load.so] + if {$::flash_enabled} { start_server {tags {"modules"} overrides {storage-provider {flash ./rocks.db.master} databases 256}} { r flushall @@ -5,7 +7,7 @@ if {$::flash_enabled} { r set bar foo r set foobar barfoo } - start_server {tags {"modules"} overrides {storage-provider {flash ./rocks.db.master} databases 256 loadmodule tests/modules/load.so module-notify-flash-load yes}} { + start_server {tags {"modules"} overrides {storage-provider {flash ./rocks.db.master} databases 256 loadmodule ["$testmodule"] module-notify-flash-load yes}} { test "Module is notified of keys loaded from flash" { assert_equal [r load.count] [r dbsize] } From 47a5d1c12010fb661c6fc545e08d5e8345cb0ad8 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Sat, 7 Jan 2023 01:43:43 -0800 Subject: [PATCH 23/30] sfsf --- tests/unit/moduleapi/load.tcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/moduleapi/load.tcl b/tests/unit/moduleapi/load.tcl index 83fd65cdc..6853f4b20 100644 --- a/tests/unit/moduleapi/load.tcl +++ b/tests/unit/moduleapi/load.tcl @@ -7,7 +7,7 @@ if {$::flash_enabled} { r set bar foo r set foobar barfoo } - start_server {tags {"modules"} overrides {storage-provider {flash ./rocks.db.master} databases 256 loadmodule ["$testmodule"] module-notify-flash-load yes}} { + start_server [list tags [list "modules"] overrides [list storage-provider {flash ./rocks.db.master} databases 256 loadmodule $testmodule]] { test "Module is notified of keys loaded from flash" { assert_equal [r load.count] [r dbsize] } From 24a665cffb25a66d739a2c88c8d904fcad947dd6 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Sat, 7 Jan 2023 01:46:57 -0800 Subject: [PATCH 24/30] remove helloload ref --- src/modules/Makefile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/modules/Makefile b/src/modules/Makefile index f8e4aab80..a722532c5 100644 --- a/src/modules/Makefile +++ b/src/modules/Makefile @@ -13,7 +13,7 @@ endif .SUFFIXES: .c .so .xo .o -all: helloworld.so hellotype.so helloblock.so hellocluster.so hellotimer.so hellodict.so hellohook.so helloacl.so helloload.so +all: helloworld.so hellotype.so helloblock.so hellocluster.so hellotimer.so hellodict.so hellohook.so helloacl.so .c.xo: $(CC) -I. $(CFLAGS) $(SHOBJ_CFLAGS) -fPIC -c $< -o $@ @@ -60,8 +60,5 @@ helloacl.so: helloacl.xo helloload.xo: ../redismodule.h -helloload.so: helloload.xo - $(LD) -o $@ $< $(SHOBJ_LDFLAGS) $(LIBS) -lc - clean: rm -rf *.xo *.so From 9570ca3d80de5d5a83095e3f5d67426ebe574a81 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Sat, 7 Jan 2023 01:47:36 -0800 Subject: [PATCH 25/30] asdasd --- src/modules/Makefile | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/modules/Makefile b/src/modules/Makefile index a722532c5..3db19e79a 100644 --- a/src/modules/Makefile +++ b/src/modules/Makefile @@ -58,7 +58,5 @@ helloacl.xo: ../redismodule.h helloacl.so: helloacl.xo $(LD) -o $@ $< $(SHOBJ_LDFLAGS) $(LIBS) -lc -helloload.xo: ../redismodule.h - clean: rm -rf *.xo *.so From a3f3b3f9a4d32dd16ac9a6596bcef9018426929c Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Mon, 9 Jan 2023 15:36:22 -0800 Subject: [PATCH 26/30] try to add module call back into initial load --- src/db.cpp | 12 ++++++++++-- src/server.cpp | 27 +++++++++------------------ 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/db.cpp b/src/db.cpp index 0446e224f..7b723aed0 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -2607,6 +2607,14 @@ void clusterStorageLoadCallback(const char *rgchkey, size_t cch, void *) slotToKeyUpdateKeyCore(rgchkey, cch, true /*add*/); } +void moduleLoadCallback(const char * rgchKey, size_t cchKey, void *data) { + if (g_pserver->cluster_enabled) { + clusterStorageLoadCallback(rgchKey, cchKey, data); + } + robj *keyobj = createEmbeddedStringObject(rgchKey, cchKey); + moduleNotifyKeyspaceEvent(NOTIFY_LOADED, "loaded", keyobj, *(int *)data); +} + void redisDb::initialize(int id) { redisDbPersistentData::initialize(); @@ -2625,8 +2633,8 @@ void redisDb::storageProviderInitialize() { if (g_pserver->m_pstorageFactory != nullptr) { - IStorageFactory::key_load_iterator itr = (g_pserver->cluster_enabled) ? clusterStorageLoadCallback : nullptr; - this->setStorageProvider(StorageCache::create(g_pserver->m_pstorageFactory, id, itr, nullptr)); + IStorageFactory::key_load_iterator itr = moduleLoadCallback; + this->setStorageProvider(StorageCache::create(g_pserver->m_pstorageFactory, id, itr, &id)); } } diff --git a/src/server.cpp b/src/server.cpp index f77b0d9df..3d2503149 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -4067,12 +4067,6 @@ void initServer(void) { } } - /* We have to initialize storage providers after the cluster has been initialized */ - for (int idb = 0; idb < cserver.dbnum; ++idb) - { - g_pserver->db[idb]->storageProviderInitialize(); - } - saveMasterStatusToStorage(false); // eliminate the repl-offset field /* Initialize ACL default password if it exists */ @@ -4085,6 +4079,15 @@ void initServer(void) { * Thread Local Storage initialization collides with dlopen call. * see: https://sourceware.org/bugzilla/show_bug.cgi?id=19329 */ void InitServerLast() { + + /* We have to initialize storage providers after the cluster has been initialized */ + moduleFireServerEvent(REDISMODULE_EVENT_LOADING, REDISMODULE_SUBEVENT_LOADING_FLASH_START, NULL); + for (int idb = 0; idb < cserver.dbnum; ++idb) + { + g_pserver->db[idb]->storageProviderInitialize(); + } + moduleFireServerEvent(REDISMODULE_EVENT_LOADING, REDISMODULE_SUBEVENT_LOADING_ENDED, NULL); + bioInit(); set_jemalloc_bg_thread(cserver.jemalloc_bg_thread); g_pserver->initial_memory_usage = zmalloc_used_memory(); @@ -6953,18 +6956,6 @@ void loadDataFromDisk(void) { if (g_pserver->m_pstorageFactory) { - if (g_pserver->config_notify_flash_load) { - moduleFireServerEvent(REDISMODULE_EVENT_LOADING, REDISMODULE_SUBEVENT_LOADING_FLASH_START, NULL); - for (int idb = 0; idb < cserver.dbnum; ++idb) { - auto spsnapshot = g_pserver->db[idb]->CloneStorageCache(); - spsnapshot->enumerate([idb](const char *rgchKey, size_t cchKey, const void *, size_t) -> bool { - robj *keyobj = createEmbeddedStringObject(rgchKey, cchKey); - moduleNotifyKeyspaceEvent(NOTIFY_LOADED, "loaded", keyobj, idb); - return true; - }); - } - moduleFireServerEvent(REDISMODULE_EVENT_LOADING, REDISMODULE_SUBEVENT_LOADING_ENDED, NULL); - } for (int idb = 0; idb < cserver.dbnum; ++idb) { if (g_pserver->db[idb]->size() > 0) From 0651e245b59f003df3b2991b70a8a56a3dbf15e6 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Mon, 9 Jan 2023 15:40:15 -0800 Subject: [PATCH 27/30] remove config --- keydb.conf | 3 --- src/config.cpp | 1 - src/server.h | 2 -- 3 files changed, 6 deletions(-) diff --git a/keydb.conf b/keydb.conf index 05e3b96fa..800657138 100644 --- a/keydb.conf +++ b/keydb.conf @@ -2088,6 +2088,3 @@ active-client-balancing yes # disk space or any other I/O error KeyDB will instead use memory. # # blob-support false - -# Use this config to notify modules of every key loaded from flash on startup (warning: can make startup much slower) -# module-notify-flash-load yes diff --git a/src/config.cpp b/src/config.cpp index edb1cc16b..253f0726a 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -2910,7 +2910,6 @@ standardConfig configs[] = { createBoolConfig("allow-write-during-load", NULL, MODIFIABLE_CONFIG, g_pserver->fWriteDuringActiveLoad, 0, NULL, NULL), createBoolConfig("force-backlog-disk-reserve", NULL, MODIFIABLE_CONFIG, cserver.force_backlog_disk, 0, NULL, NULL), createBoolConfig("soft-shutdown", NULL, MODIFIABLE_CONFIG, g_pserver->config_soft_shutdown, 0, NULL, NULL), - createBoolConfig("module-notify-flash-load", NULL, MODIFIABLE_CONFIG, g_pserver->config_notify_flash_load, 0, NULL, NULL), #ifdef USE_OPENSSL createIntConfig("tls-port", NULL, MODIFIABLE_CONFIG, 0, 65535, g_pserver->tls_port, 0, INTEGER_CONFIG, NULL, updateTLSPort), /* TCP port. */ diff --git a/src/server.h b/src/server.h index abbfa7a37..eee584f2d 100644 --- a/src/server.h +++ b/src/server.h @@ -2731,8 +2731,6 @@ struct redisServer { int config_soft_shutdown = false; bool soft_shutdown = false; - int config_notify_flash_load = false; - /* Lock Contention Ring Buffer */ static const size_t s_lockContentionSamples = 64; uint16_t rglockSamples[s_lockContentionSamples]; From 737adfa610f478572d9c3352c3c1d5bf9921e435 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Mon, 9 Jan 2023 16:17:29 -0800 Subject: [PATCH 28/30] add flash load case to hooks.c --- tests/modules/hooks.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/modules/hooks.c b/tests/modules/hooks.c index 3b69ac27a..185f3d5e0 100644 --- a/tests/modules/hooks.c +++ b/tests/modules/hooks.c @@ -212,6 +212,7 @@ void loadingCallback(RedisModuleCtx *ctx, RedisModuleEvent e, uint64_t sub, void case REDISMODULE_SUBEVENT_LOADING_RDB_START: keyname = "loading-rdb-start"; break; case REDISMODULE_SUBEVENT_LOADING_AOF_START: keyname = "loading-aof-start"; break; case REDISMODULE_SUBEVENT_LOADING_REPL_START: keyname = "loading-repl-start"; break; + case REDISMODULE_SUBEVENT_LOADING_FLASH_START: keyname = "loading-flash-start"; break; case REDISMODULE_SUBEVENT_LOADING_ENDED: keyname = "loading-end"; break; case REDISMODULE_SUBEVENT_LOADING_FAILED: keyname = "loading-failed"; break; } From 40c4887a835fc75374f76c532aff4307aee7bb5c Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Mon, 9 Jan 2023 18:16:22 -0800 Subject: [PATCH 29/30] fix test --- tests/unit/moduleapi/load.tcl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/unit/moduleapi/load.tcl b/tests/unit/moduleapi/load.tcl index 6853f4b20..f48e4204b 100644 --- a/tests/unit/moduleapi/load.tcl +++ b/tests/unit/moduleapi/load.tcl @@ -1,14 +1,14 @@ set testmodule [file normalize tests/modules/load.so] if {$::flash_enabled} { - start_server {tags {"modules"} overrides {storage-provider {flash ./rocks.db.master} databases 256}} { - r flushall - r set foo bar - r set bar foo - r set foobar barfoo - } start_server [list tags [list "modules"] overrides [list storage-provider {flash ./rocks.db.master} databases 256 loadmodule $testmodule]] { test "Module is notified of keys loaded from flash" { + r flushall + r set foo bar + r set bar foo + r set foobar barfoo + assert_equal [r load.count] 0 + r debug reload assert_equal [r load.count] [r dbsize] } } From 32832f380cb44cd0ed60dec6a26ff8eb97da31d3 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Mon, 9 Jan 2023 18:17:22 -0800 Subject: [PATCH 30/30] fix test --- tests/unit/moduleapi/load.tcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/moduleapi/load.tcl b/tests/unit/moduleapi/load.tcl index f48e4204b..853b9aebb 100644 --- a/tests/unit/moduleapi/load.tcl +++ b/tests/unit/moduleapi/load.tcl @@ -9,7 +9,7 @@ if {$::flash_enabled} { r set foobar barfoo assert_equal [r load.count] 0 r debug reload - assert_equal [r load.count] [r dbsize] + assert_equal [r load.count] 3 } } } \ No newline at end of file