-
Notifications
You must be signed in to change notification settings - Fork 283
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
[dbconnect]: Support DPU database schema #845
Conversation
5cd8953
to
3e8c1b5
Compare
Signed-off-by: Ze Gan <[email protected]>
3e8c1b5
to
f74928d
Compare
Signed-off-by: Ze Gan <[email protected]>
return containerName.empty() && netns.empty(); | ||
} | ||
|
||
std::string toString() const |
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.
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.
I believe it is a tradeoff, align to the STL convertion or align to this file's convertion .
So, I choose to align to this file.
{ | ||
buffer.push_back(netns); | ||
} | ||
return boost::algorithm::join(buffer, ":"); |
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.
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.
Yes, it's a problem. Fixed it.
@@ -62,14 +110,21 @@ class SonicDBConfig | |||
static void reset(); | |||
|
|||
static void validateNamespace(const std::string &netns); | |||
static std::string getDbInst(const std::string &dbName, const std::string &netns = EMPTY_NAMESPACE); |
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.
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.
I don't feel that adding more parameters is better. Because I have introduced a new class SonicDBKey
, I believe we should prefer to use this new class's object to identify a database instance instead of the old style API in the following code. This function is just for adapting the existing reference.
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.
The suggested function is like
static std::string getDbInst(const std::string &dbName, const std::string &netns = EMPTY_NAMESPACE, containerName=DEFAULT_CONTAINERNAME);
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.
Done
@@ -80,27 +135,29 @@ class SonicDBConfig | |||
%} | |||
#endif | |||
|
|||
static std::vector<std::string> getDbList(const std::string &netns = EMPTY_NAMESPACE); |
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.
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.
reply as above.
@@ -158,6 +215,7 @@ class DBConnector : public RedisContext | |||
DBConnector(int dbId, const std::string &unixPath, unsigned int timeout); | |||
DBConnector(const std::string &dbName, unsigned int timeout, bool isTcpConn = false); | |||
DBConnector(const std::string &dbName, unsigned int timeout, bool isTcpConn, const std::string &netns); |
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.
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.
reply as above.
Signed-off-by: Ze Gan <[email protected]>
2ebf48e
to
314dbf5
Compare
Signed-off-by: Ze Gan <[email protected]>
314dbf5
to
4fe98b0
Compare
Signed-off-by: Ze Gan <[email protected]>
bb54c55
to
57d09d3
Compare
common/dbconnector.cpp
Outdated
string socket; | ||
if (it.value().find("unix_socket_path") != it.value().end()) | ||
{ | ||
socket = it.value().at("unix_socket_path"); |
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.
we should be able to directly get the value from the iterator that returned by find(), according to nlohmann/json code here: https://github.com/nlohmann/json/blob/a259ecc51e1951e12f757ce17db958e9881e9c6c/include/nlohmann/detail/iterators/iter_impl.hpp#L280C21-L280C21.
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.
Done
common/dbconnector.cpp
Outdated
m_db_info[EMPTY_NAMESPACE] = db_entry; | ||
m_db_separator[EMPTY_NAMESPACE] = separator_entry; | ||
m_inst_info[empty_key] = inst_entry; | ||
m_db_info[empty_key] = db_entry; |
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.
use .emplace(empty_key, std::move(db_entry))
will be faster if it is supported in our dev env.
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.
Done
common/dbconnector.cpp
Outdated
|
||
if(element["namespace"].empty()) | ||
if (!element["database_name"].empty()) |
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.
have we decided the name to be database_name? I remember Qi had concern on this name, since redis also has a database concepts, but not sure if this is closed or not.
if not, maybe database_instance_name or something like this might help with the concern.
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.
It has been changed to container_name
, please check it again.
Signed-off-by: Ze Gan <[email protected]>
2d9f885
to
bf7af35
Compare
Hi @qiluo-msft Please help to review or approve/merge this PR? |
Signed-off-by: Ze Gan <[email protected]>
{ | ||
struct timeval tv = {0, (suseconds_t)timeout * 1000}; | ||
struct timeval *ptv = timeout ? &tv : NULL; | ||
if (isTcpConn) | ||
{ | ||
initContext(SonicDBConfig::getDbHostname(dbName, netns).c_str(), SonicDBConfig::getDbPort(dbName, netns), ptv); | ||
initContext(SonicDBConfig::getDbHostname(dbName, m_key).c_str(), SonicDBConfig::getDbPort(dbName, m_key), ptv); |
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.
This PR is for expanding the capability of dbconnect to adapt the new DPU DB schema introduced by PR: sonic-net/sonic-buildimage#17443