added createMetadataDb to IStorageFactory + implementations

Former-commit-id: a2acf75484d2af93aad9d03a20bd402893044860
This commit is contained in:
christianEQ 2021-11-01 03:17:13 +00:00
parent 595a2315f6
commit c195ee4453
7 changed files with 19 additions and 0 deletions

View File

@ -9,6 +9,7 @@ public:
virtual ~IStorageFactory() {}
virtual class IStorage *create(int db, key_load_iterator itr, void *privdata) = 0;
virtual class IStorage *createMetadataDb() = 0;
virtual const char *name() const = 0;
virtual size_t totalDiskspaceUsed() const = 0;
virtual bool FSlow() const = 0;

View File

@ -3984,6 +3984,10 @@ void initServer(void) {
slowlogInit();
latencyMonitorInit();
if (g_pserver->m_pstorageFactory) {
g_pserver->metadataDb = g_pserver->m_pstorageFactory->createMetadataDb();
}
/* We have to initialize storage providers after the cluster has been initialized */
for (int idb = 0; idb < cserver.dbnum; ++idb)
{

View File

@ -2170,6 +2170,7 @@ struct redisServer {
mode_t umask; /* The umask value of the process on startup */
std::atomic<int> hz; /* serverCron() calls frequency in hertz */
int in_fork_child; /* indication that this is a fork child */
IStorage *metadataDb = nullptr;
redisDb **db = nullptr;
dict *commands; /* Command table */
dict *orig_commands; /* Command table before command renaming. */

View File

@ -14,6 +14,7 @@ public:
~RocksDBStorageFactory();
virtual IStorage *create(int db, key_load_iterator iter, void *privdata) override;
virtual IStorage *createMetadataDb() override;
virtual const char *name() const override;
virtual size_t totalDiskspaceUsed() const override;

View File

@ -32,6 +32,7 @@ IStorageFactory *CreateRocksDBStorageFactory(const char *path, int dbnum, const
RocksDBStorageFactory::RocksDBStorageFactory(const char *dbfile, int dbnum, const char *rgchConfig, size_t cchConfig)
: m_path(dbfile)
{
dbnum++; // create an extra db for metadata
// Get the count of column families in the actual database
std::vector<std::string> vecT;
auto status = rocksdb::DB::ListColumnFamilies(rocksdb::Options(), dbfile, &vecT);
@ -134,6 +135,11 @@ std::string RocksDBStorageFactory::getTempFolder()
return path;
}
IStorage *RocksDBStorageFactory::createMetadataDb()
{
return this->create(-1, nullptr, nullptr);
}
IStorage *RocksDBStorageFactory::create(int db, key_load_iterator iter, void *privdata)
{
++db; // skip default col family

View File

@ -6,6 +6,11 @@ IStorage *TestStorageFactory::create(int, key_load_iterator, void *)
return new (MALLOC_LOCAL) TestStorageProvider();
}
IStorage *TestStorageFactory::createMetadataDb()
{
return new (MALLOC_LOCAL) TestStorageProvider();
}
const char *TestStorageFactory::name() const
{
return "TEST Storage Provider";

View File

@ -5,6 +5,7 @@
class TestStorageFactory : public IStorageFactory
{
virtual class IStorage *create(int db, key_load_iterator itr, void *privdata) override;
virtual class IStorage *createMetadataDb() override;
virtual const char *name() const override;
virtual size_t totalDiskspaceUsed() const override { return 0; }
virtual bool FSlow() const { return false; }