MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / initializeStorageProvider

Function initializeStorageProvider

src/config.cpp:351–412  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

349sds g_sdsArgs = nullptr;
350
351bool initializeStorageProvider(const char **err)
352{
353 try
354 {
355 bool fTest = false;
356 if (g_sdsProvider == nullptr)
357 return true;
358 if (!strcasecmp(g_sdsProvider, "flash") && g_sdsArgs != nullptr)
359 {
360#ifdef ENABLE_ROCKSDB
361 // Create The Storage Factory (if necessary)
362 serverLog(LL_NOTICE, "Initializing FLASH storage provider (this may take a long time)");
363 adjustOpenFilesLimit();
364 g_pserver->m_pstorageFactory = CreateRocksDBStorageFactory(g_sdsArgs, cserver.dbnum, cserver.storage_conf, cserver.storage_conf ? strlen(cserver.storage_conf) : 0);
365#else
366 serverLog(LL_WARNING, "To use the flash storage provider please compile KeyDB with ENABLE_FLASH=yes");
367 serverLog(LL_WARNING, "Exiting due to the use of an unsupported storage provider");
368 exit(EXIT_FAILURE);
369#endif
370 }
371 else if (!strcasecmp(g_sdsProvider, "test") && g_sdsArgs == nullptr)
372 {
373 g_pserver->m_pstorageFactory = new (MALLOC_LOCAL) TestStorageFactory();
374 fTest = true;
375 }
376
377 if (g_pserver->m_pstorageFactory != nullptr && !fTest)
378 {
379 // We need to set max memory to a sane default so keys are actually evicted properly
380 if (g_pserver->maxmemory == 0 && g_pserver->maxmemory_policy == MAXMEMORY_NO_EVICTION)
381 {
382#ifdef __linux__
383 struct sysinfo sys;
384 if (sysinfo(&sys) == 0)
385 {
386 // By default it's a little under half the memory. This gives sufficient room for background saving
387 g_pserver->maxmemory = static_cast<unsigned long long>(sys.totalram / 2.2);
388 g_pserver->maxmemory_policy = MAXMEMORY_ALLKEYS_LRU;
389 }
390#else
391 serverLog(LL_WARNING, "Unable to dynamically set maxmemory, please set maxmemory and maxmemory-policy if you are using a storage provier");
392#endif
393 }
394 else if (g_pserver->maxmemory_policy == MAXMEMORY_NO_EVICTION)
395 {
396 g_pserver->maxmemory_policy = MAXMEMORY_ALLKEYS_LRU;
397 }
398 }
399 else
400 {
401 *err = "Unknown storage provider";
402 }
403 return g_pserver->m_pstorageFactory != nullptr;
404 }
405 catch(std::string str)
406 {
407 serverLog(LL_WARNING, "ERROR: Failed to initialize %s storage provider. Details to follow below.", g_sdsProvider);
408 serverLog(LL_WARNING, "\t%s", str.c_str());

Callers 2

mainFunction · 0.85
debugCommandFunction · 0.85

Calls 4

serverLogFunction · 0.85
adjustOpenFilesLimitFunction · 0.85
sysinfoClass · 0.70

Tested by

no test coverage detected