-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Populating m_dbName in dbConnector constructor. #589
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -209,7 +209,7 @@ void SonicDBConfig::validateNamespace(const string &netns) | |
} | ||
} | ||
|
||
SonicDBInfo& SonicDBConfig::getDbInfo(const std::string &dbName, const std::string &netns) | ||
const std::unordered_map<std::string, SonicDBInfo>& SonicDBConfig::getDbEntryMap(const std::string &netns) | ||
{ | ||
std::lock_guard<std::recursive_mutex> guard(m_db_info_mutex); | ||
|
||
|
@@ -232,7 +232,16 @@ SonicDBInfo& SonicDBConfig::getDbInfo(const std::string &dbName, const std::stri | |
SWSS_LOG_ERROR("%s", msg.c_str()); | ||
throw out_of_range(msg); | ||
} | ||
auto& infos = foundNetns->second; | ||
return foundNetns->second; | ||
} | ||
|
||
const SonicDBInfo& SonicDBConfig::getDbInfo(const std::string &dbName, const std::string &netns) | ||
{ | ||
std::lock_guard<std::recursive_mutex> guard(m_db_info_mutex); | ||
|
||
SWSS_LOG_ENTER(); | ||
|
||
auto const& infos = getDbEntryMap(netns); | ||
auto foundDb = infos.find(dbName); | ||
if (foundDb == infos.end()) | ||
{ | ||
|
@@ -287,6 +296,24 @@ int SonicDBConfig::getDbId(const string &dbName, const string &netns) | |
return getDbInfo(dbName, netns).dbId; | ||
} | ||
|
||
string SonicDBConfig::getDbName(int dbId, const string &netns) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like a mostly copy-paste of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can extract the common part from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
std::lock_guard<std::recursive_mutex> guard(m_db_info_mutex); | ||
|
||
SWSS_LOG_ENTER(); | ||
|
||
string db_name; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above.
|
||
auto const& infos = getDbEntryMap(netns); | ||
for ( auto it = infos.begin(); it != infos.end(); ++it ) { | ||
auto& db_info = it->second; | ||
if (db_info.dbId == dbId) { | ||
db_name = it->first; | ||
break; | ||
} | ||
} | ||
return db_name; | ||
} | ||
|
||
string SonicDBConfig::getSeparator(const string &dbName, const string &netns) | ||
{ | ||
return getDbInfo(dbName, netns).separator; | ||
|
@@ -510,6 +537,7 @@ void DBConnector::select(DBConnector *db) | |
DBConnector::DBConnector(const DBConnector &other) | ||
: RedisContext(other) | ||
, m_dbId(other.m_dbId) | ||
, m_dbName(other.m_dbName) | ||
ntoorchi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
, m_namespace(other.m_namespace) | ||
{ | ||
select(this); | ||
|
@@ -518,6 +546,7 @@ DBConnector::DBConnector(const DBConnector &other) | |
DBConnector::DBConnector(int dbId, const RedisContext& ctx) | ||
: RedisContext(ctx) | ||
, m_dbId(dbId) | ||
, m_dbName(SonicDBConfig::getDbName(dbId)) | ||
, m_namespace(EMPTY_NAMESPACE) | ||
{ | ||
select(this); | ||
|
@@ -526,6 +555,7 @@ DBConnector::DBConnector(int dbId, const RedisContext& ctx) | |
DBConnector::DBConnector(int dbId, const string& hostname, int port, | ||
unsigned int timeout) | ||
: m_dbId(dbId) | ||
, m_dbName(SonicDBConfig::getDbName(dbId)) | ||
, m_namespace(EMPTY_NAMESPACE) | ||
{ | ||
struct timeval tv = {0, (suseconds_t)timeout * 1000}; | ||
|
@@ -537,6 +567,7 @@ DBConnector::DBConnector(int dbId, const string& hostname, int port, | |
|
||
DBConnector::DBConnector(int dbId, const string& unixPath, unsigned int timeout) | ||
: m_dbId(dbId) | ||
, m_dbName(SonicDBConfig::getDbName(dbId)) | ||
, m_namespace(EMPTY_NAMESPACE) | ||
{ | ||
struct timeval tv = {0, (suseconds_t)timeout * 1000}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to hold the lock while we are accessing the
m_db_info
structure. Also, the convention is to log entry into the method.