-
Notifications
You must be signed in to change notification settings - Fork 552
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
New p4orch development changes #3066
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 |
---|---|---|
@@ -1,7 +1,11 @@ | ||
#pragma once | ||
|
||
#include <condition_variable> | ||
#include <memory> | ||
#include <mutex> | ||
#include <queue> | ||
#include <string> | ||
#include <thread> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
|
@@ -17,9 +21,9 @@ | |
class ResponsePublisher : public ResponsePublisherInterface | ||
{ | ||
public: | ||
explicit ResponsePublisher(bool buffered = false); | ||
explicit ResponsePublisher(const std::string &dbName, bool buffered = false, bool db_write_thread = false); | ||
|
||
virtual ~ResponsePublisher() = default; | ||
virtual ~ResponsePublisher(); | ||
|
||
// Intent attributes are the attributes sent in the notification into the | ||
// redis channel. | ||
|
@@ -57,8 +61,39 @@ class ResponsePublisher : public ResponsePublisherInterface | |
void setBuffered(bool buffered); | ||
|
||
private: | ||
struct entry | ||
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. This is just internal implementation details. We don't have HLD for this. The overall design is to put the DB update operation into a different thread for the response publisher. In the detailed implementation here, we use a FIFO queue to store the DB update events. The main thread will queue up the event into the queue, and the "DB update thread" will read from the queue and process the DB update. Let me know if you need more details on this. |
||
{ | ||
std::string table; | ||
std::string key; | ||
std::vector<swss::FieldValueTuple> values; | ||
std::string op; | ||
bool replace; | ||
bool flush; | ||
bool shutdown; | ||
|
||
entry() | ||
{ | ||
} | ||
|
||
entry(const std::string &table, const std::string &key, const std::vector<swss::FieldValueTuple> &values, | ||
const std::string &op, bool replace, bool flush, bool shutdown) | ||
: table(table), key(key), values(values), op(op), replace(replace), flush(flush), shutdown(shutdown) | ||
{ | ||
} | ||
}; | ||
|
||
void dbUpdateThread(); | ||
void writeToDBInternal(const std::string &table, const std::string &key, | ||
const std::vector<swss::FieldValueTuple> &values, const std::string &op, bool replace); | ||
|
||
std::unique_ptr<swss::DBConnector> m_db; | ||
std::unique_ptr<swss::RedisPipeline> m_pipe; | ||
std::unique_ptr<swss::RedisPipeline> m_ntf_pipe; | ||
std::unique_ptr<swss::RedisPipeline> m_db_pipe; | ||
|
||
bool m_buffered{false}; | ||
// Thread to write to DB. | ||
std::unique_ptr<std::thread> m_update_thread; | ||
std::queue<entry> m_queue; | ||
mutable std::mutex m_lock; | ||
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. That is a common practice for mutex object. The key word "mutable" means that the variable can be changed in a const method. In this case, we might not really need it to be mutable. But we should follow the common practice. 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 might not really need it to be mutable -> let's just remove it. Thanks for the explanation! (not a blocking issue) |
||
std::condition_variable m_signal; | ||
}; |
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.
Can you please provide the details of response_publisher in the description? What was the behavior before and whats the new change? Is it breaking any previous implementation?
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.
Updated the PR description.