77#include < utility>
88
99#include < hiredis/hiredis.h>
10- #define EMPTY_NAMESPACE std::string ()
1110
1211namespace swss {
1312
1413class DBConnector ;
1514
16- class RedisInstInfo
17- {
18- public:
19- std::string unixSocketPath;
20- std::string hostname;
21- int port;
22- };
23-
2415class SonicDBInfo
2516{
2617public:
@@ -33,35 +24,25 @@ class SonicDBConfig
3324{
3425public:
3526 static void initialize (const std::string &file = DEFAULT_SONIC_DB_CONFIG_FILE);
36- static void initializeGlobalConfig (const std::string &file = DEFAULT_SONIC_DB_GLOBAL_CONFIG_FILE);
37- static void validateNamespace (const std::string &nameSpace);
38- static std::string getDbInst (const std::string &dbName, const std::string &nameSpace = EMPTY_NAMESPACE);
39- static int getDbId (const std::string &dbName, const std::string &nameSpace = EMPTY_NAMESPACE);
40- static std::string getSeparator (const std::string &dbName, const std::string &nameSpace = EMPTY_NAMESPACE);
41- static std::string getSeparator (int dbId, const std::string &nameSpace = EMPTY_NAMESPACE);
27+ static std::string getDbInst (const std::string &dbName);
28+ static int getDbId (const std::string &dbName);
29+ static std::string getSeparator (const std::string &dbName);
30+ static std::string getSeparator (int dbId);
4231 static std::string getSeparator (const DBConnector* db);
43- static std::string getDbSock (const std::string &dbName, const std::string &nameSpace = EMPTY_NAMESPACE);
44- static std::string getDbHostname (const std::string &dbName, const std::string &nameSpace = EMPTY_NAMESPACE);
45- static int getDbPort (const std::string &dbName, const std::string &nameSpace = EMPTY_NAMESPACE);
46- static std::vector<std::string> getNamespaces ();
32+ static std::string getDbSock (const std::string &dbName);
33+ static std::string getDbHostname (const std::string &dbName);
34+ static int getDbPort (const std::string &dbName);
4735 static bool isInit () { return m_init; };
48- static bool isGlobalInit () { return m_global_init; };
4936
5037private:
5138 static constexpr const char *DEFAULT_SONIC_DB_CONFIG_FILE = " /var/run/redis/sonic-db/database_config.json" ;
52- static constexpr const char *DEFAULT_SONIC_DB_GLOBAL_CONFIG_FILE = " /var/run/redis/sonic-db/database_global.json" ;
53- // { namespace { instName, { unix_socket_path, hostname, port } } }
54- static std::unordered_map<std::string, std::unordered_map<std::string, RedisInstInfo>> m_inst_info;
55- // { namespace, { dbName, {instName, dbId, separator} } }
56- static std::unordered_map<std::string, std::unordered_map<std::string, SonicDBInfo>> m_db_info;
57- // { namespace, { dbId, separator } }
58- static std::unordered_map<std::string, std::unordered_map<int , std::string>> m_db_separator;
39+ // { instName, { unix_socket_path, {hostname, port} } }
40+ static std::unordered_map<std::string, std::pair<std::string, std::pair<std::string, int >>> m_inst_info;
41+ // { dbName, {instName, dbId} }
42+ static std::unordered_map<std::string, SonicDBInfo> m_db_info;
43+ // { dbIp, separator }
44+ static std::unordered_map<int , std::string> m_db_separator;
5945 static bool m_init;
60- static bool m_global_init;
61- static void parseDatabaseConfig (const std::string &file,
62- std::unordered_map<std::string, RedisInstInfo> &inst_entry,
63- std::unordered_map<std::string, SonicDBInfo> &db_entry,
64- std::unordered_map<int , std::string> &separator_entry);
6546};
6647
6748class DBConnector
@@ -79,14 +60,12 @@ class DBConnector
7960 DBConnector (int dbId, const std::string &hostname, int port, unsigned int timeout);
8061 DBConnector (int dbId, const std::string &unixPath, unsigned int timeout);
8162 DBConnector (const std::string &dbName, unsigned int timeout, bool isTcpConn = false );
82- DBConnector (const std::string &dbName, unsigned int timeout, bool isTcpConn, const std::string &nameSpace);
8363
8464 ~DBConnector ();
8565
8666 redisContext *getContext () const ;
8767 int getDbId () const ;
8868 std::string getDbName () const ;
89- std::string getNamespace () const ;
9069
9170 static void select (DBConnector *db);
9271
@@ -105,7 +84,6 @@ class DBConnector
10584 redisContext *m_conn;
10685 int m_dbId;
10786 std::string m_dbName;
108- std::string m_namespace;
10987};
11088
11189}
0 commit comments