Make the storage provider configurable, and show it in the info command

Former-commit-id: e201ce622ff3c7832d03c6b5759386f0efc23cdf
This commit is contained in:
John Sully 2019-12-09 21:07:37 -05:00
parent 38f7cca61a
commit 74cbadb753
3 changed files with 43 additions and 6 deletions

View File

@ -6,6 +6,7 @@ class IStorageFactory
public:
virtual ~IStorageFactory() {}
virtual class IStorage *create(int db) = 0;
virtual const char *name() const = 0;
};
class IStorage

View File

@ -29,10 +29,13 @@
*/
#include "server.h"
#include "storage/rocksdbfactory.h"
#include "cluster.h"
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/sysinfo.h>
const char *KEYDB_SET_VERSION = KEYDB_REAL_VERSION;
@ -212,6 +215,38 @@ void queueLoadModule(sds path, sds *argv, int argc) {
listAddNodeTail(g_pserver->loadmodule_queue,loadmod);
}
static bool initializeStorageProvider(sds *argv, int argc, const char **err)
{
bool fResult = false;
if (!strcasecmp(argv[0], "flash") && argc == 2)
{
// Create The Storage Factory (if necessary)
g_pserver->m_pstorageFactory = CreateRocksDBStorageFactory(argv[1], cserver.dbnum);
fResult = true;
}
if (fResult)
{
// We need to set max memory to a sane default so keys are actually evicted properly
if (g_pserver->maxmemory == 0)
{
struct sysinfo sys;
if (sysinfo(&sys) == 0)
{
// By default it's half the memory. This gives sufficient room for background saving
g_pserver->maxmemory = sys.totalram / 2;
if (g_pserver->maxmemory_policy == MAXMEMORY_NO_EVICTION)
g_pserver->maxmemory_policy = MAXMEMORY_ALLKEYS_LRU;
}
}
}
else
{
*err = "Unknown storage provider";
}
return fResult;
}
void loadServerConfigFromString(char *config) {
const char *err = NULL;
int linenum = 0, totlines, i;
@ -802,6 +837,9 @@ void loadServerConfigFromString(char *config) {
g_fTestMode = yesnotoi(argv[1]);
} else if (!strcasecmp(argv[0],"rdbfuzz-mode")) {
// NOP, handled in main
} else if (!strcasecmp(argv[0],"storage-provider") && argc >= 2) {
if (!initializeStorageProvider(argv+1, argc-1, &err))
goto loaderr;
} else {
err = "Bad directive or wrong number of arguments"; goto loaderr;
}

View File

@ -61,7 +61,6 @@
#include <uuid/uuid.h>
#include <mutex>
#include "aelocker.h"
#include "storage/rocksdbfactory.h"
int g_fTestMode = false;
@ -3016,9 +3015,6 @@ void initServer(void) {
signal(SIGPIPE, SIG_IGN);
setupSignalHandlers();
// Create The Storage Factory (if necessary)
g_pserver->m_pstorageFactory = CreateRocksDBStorageFactory("/tmp/rocks.db", cserver.dbnum);
zfree(g_pserver->db); // initServerConfig created a dummy array, free that now
g_pserver->db = (redisDb**)zmalloc(sizeof(redisDb*)*cserver.dbnum, MALLOC_LOCAL);
@ -4289,7 +4285,8 @@ sds genRedisInfoString(const char *section) {
"mem_aof_buffer:%zu\r\n"
"mem_allocator:%s\r\n"
"active_defrag_running:%d\r\n"
"lazyfree_pending_objects:%zu\r\n",
"lazyfree_pending_objects:%zu\r\n"
"storage_provider:%s\r\n",
zmalloc_used,
hmem,
g_pserver->cron_malloc_stats.process_rss,
@ -4329,7 +4326,8 @@ sds genRedisInfoString(const char *section) {
mh->aof_buffer,
ZMALLOC_LIB,
g_pserver->active_defrag_running,
lazyfreeGetPendingObjectsCount()
lazyfreeGetPendingObjectsCount(),
g_pserver->m_pstorageFactory ? g_pserver->m_pstorageFactory->name() : "none"
);
freeMemoryOverheadData(mh);
}