Skip to content

Commit

Permalink
Without debugs
Browse files Browse the repository at this point in the history
  • Loading branch information
divyagayathri-hcl committed Jan 6, 2025
1 parent 45f805b commit 1c2c16b
Show file tree
Hide file tree
Showing 13 changed files with 13 additions and 256 deletions.
4 changes: 0 additions & 4 deletions common/c-api/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ template <class T> static inline T &getReference(std::shared_ptr<T> &t) {
// T is anything that has a .size() method and which can be iterated over for
// swss::KeyOpFieldValuesTuple, eg vector or deque
template <class T> static inline SWSSKeyOpFieldValuesArray makeKeyOpFieldValuesArray(T &&in) {
SWSS_LOG_DEBUG("Entering makeKeyOpFieldValuesArray method");
SWSSKeyOpFieldValues *data = new SWSSKeyOpFieldValues[in.size()];

size_t i = 0;
Expand All @@ -212,7 +211,6 @@ template <class T> static inline SWSSKeyOpFieldValuesArray makeKeyOpFieldValuesA
SWSSKeyOpFieldValuesArray out;
out.len = (uint64_t)in.size();
out.data = data;
// SWSS_LOG_DEBUG("2::: out.len value is: %ld", out.len);
return out;
}

Expand Down Expand Up @@ -257,11 +255,9 @@ static inline std::vector<swss::KeyOpFieldsValuesTuple>
takeKeyOpFieldValuesArray(SWSSKeyOpFieldValuesArray in) {
std::vector<swss::KeyOpFieldsValuesTuple> out;
for (uint64_t i = 0; i < in.len; i++) {
// SWSS_LOG_DEBUG("i value is: %ld", i);
SWSSKeyOpFieldValues kfv = in.data[i];
out.push_back(takeKeyOpFieldValues(std::move(kfv)));
}
// SWSS_LOG_DEBUG("out.len value is: %ld", out.size());
return out;
}

Expand Down
1 change: 0 additions & 1 deletion common/c-api/zmqclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ void SWSSZmqClient_connect(SWSSZmqClient zmqc) {

void SWSSZmqClient_sendMsg(SWSSZmqClient zmqc, const char *dbName, const char *tableName,
SWSSKeyOpFieldValuesArray arr) {
SWSS_LOG_DEBUG("Inside SWSSZmqClient_sendMsg");
SWSSTry({
vector<KeyOpFieldsValuesTuple> kcos = takeKeyOpFieldValuesArray(arr);
((ZmqClient *)zmqc)
Expand Down
32 changes: 7 additions & 25 deletions common/zmqclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ namespace swss {
ZmqClient::ZmqClient(const std::string& endpoint)
:ZmqClient(endpoint, "")
{
initialize(endpoint);
}

ZmqClient::ZmqClient(const std::string& endpoint, const std::string& vrf)
{
initialize(endpoint, vrf);
}

ZmqClient::ZmqClient(const std::string& endpoint, uint32_t waitTimeMs) :
m_waitTimeMs(waitTimeMs)
ZmqClient::ZmqClient(const std::string& endpoint, uint32_t waitTimeMs)
: m_waitTimeMs(waitTimeMs)
{
initialize(endpoint);
}
Expand Down Expand Up @@ -63,25 +62,13 @@ void ZmqClient::initialize(const std::string& endpoint, const std::string& vrf)
connect();
}

void ZmqClient::initialize(const std::string& endpoint)
{
m_connected = false;
m_endpoint = endpoint;
m_context = nullptr;
m_socket = nullptr;
m_sendbuffer.resize(MQ_RESPONSE_MAX_COUNT);

connect();
}

bool ZmqClient::isConnected()
{
return m_connected;
}

void ZmqClient::connect()
{
SWSS_LOG_ERROR("DIV:: Inside function client connect");
if (m_connected)
{
SWSS_LOG_DEBUG("Already connected to endpoint: %s", m_endpoint.c_str());
Expand All @@ -107,7 +94,6 @@ SWSS_LOG_ERROR("DIV:: Inside function client connect");
m_context = zmq_ctx_new();
m_socket = zmq_socket(m_context, ZMQ_PUSH);

SWSS_LOG_DEBUG("m_socket in client connect() is: %p\n", m_socket);
// timeout all pending send package, so zmq will not block in dtor of this class: http://api.zeromq.org/master:zmq-setsockopt
int linger = 0;
zmq_setsockopt(m_socket, ZMQ_LINGER, &linger, sizeof(linger));
Expand Down Expand Up @@ -139,7 +125,6 @@ void ZmqClient::sendMsg(
const std::string& tableName,
const std::vector<KeyOpFieldsValuesTuple>& kcos)
{
SWSS_LOG_ERROR("DIV:: Inside function client sendMsg");
int serializedlen = (int)BinarySerializer::serializeBuffer(
m_sendbuffer.data(),
m_sendbuffer.size(),
Expand All @@ -165,11 +150,8 @@ SWSS_LOG_ERROR("DIV:: Inside function client sendMsg");
std::lock_guard<std::mutex> lock(m_socketMutex);

// Use none block mode to use all bandwidth: http://api.zeromq.org/2-1%3Azmq-send
rc = zmq_send(m_socket, m_sendbuffer.data(), serializedlen, ZMQ_NOBLOCK);
rc = zmq_send(m_socket, m_sendbuffer.data(), serializedlen, ZMQ_NOBLOCK);
}
//SWSS_LOG_DEBUG("Before Sleep() in client sendmsg");
// usleep(10 * 1000);
//SWSS_LOG_DEBUG("After Sleep() in client sendmsg");
if (rc >= 0)
{
SWSS_LOG_DEBUG("zmq sended %d bytes", serializedlen);
Expand All @@ -187,7 +169,7 @@ SWSS_LOG_ERROR("DIV:: Inside function client sendMsg");
// For example when ZMQ socket still not receive reply message from last sended package.
// There was state machine inside ZMQ socket, when the socket is not in ready to send state, this error will happen.
// for more detail, please check: http://api.zeromq.org/2-1:zmq-send
SWSS_LOG_WARN("zmq send retry, endpoint: %s, error: %d", m_endpoint.c_str(), zmq_err);
SWSS_LOG_DEBUG("zmq send retry, endpoint: %s, error: %d", m_endpoint.c_str(), zmq_err);

retry_delay = 0;
}
Expand All @@ -206,7 +188,7 @@ SWSS_LOG_ERROR("DIV:: Inside function client sendMsg");
else
{
// for other error, send failed immediately.
auto message = "cli: zmq send failed, endpoint: " + m_endpoint + ", error: " + to_string(rc);
auto message = "zmq send failed, endpoint: " + m_endpoint + ", error: " + to_string(rc);
SWSS_LOG_ERROR("%s", message.c_str());
throw system_error(make_error_code(errc::io_error), message);
}
Expand All @@ -215,16 +197,16 @@ SWSS_LOG_ERROR("DIV:: Inside function client sendMsg");
}

// failed after retry
auto message = "cli: zmq send failed, endpoint: " + m_endpoint + ", zmqerrno: " + to_string(zmq_err) + ":" + zmq_strerror(zmq_err) + ", msg length:" + to_string(serializedlen);
auto message = "zmq send failed, endpoint: " + m_endpoint + ", zmqerrno: " + to_string(zmq_err) + ":" + zmq_strerror(zmq_err) + ", msg length:" + to_string(serializedlen);
SWSS_LOG_ERROR("%s", message.c_str());
throw system_error(make_error_code(errc::io_error), message);
}

//TODO: To implement the wait() method later.
bool ZmqClient::wait(const std::string& dbName,
const std::string& tableName,
const std::vector<std::shared_ptr<KeyOpFieldsValuesTuple>>& kcos)
{
SWSS_LOG_ERROR("DIV:: Inside function wait");
SWSS_LOG_ENTER();

return false;
Expand Down
5 changes: 2 additions & 3 deletions common/zmqclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class ZmqClient
const std::vector<std::shared_ptr<KeyOpFieldsValuesTuple>>& kcos);

private:
void initialize(const std::string& endpoint, const std::string& vrf);
void initialize(const std::string& endpoint);
void initialize(const std::string& endpoint, const std::string& vrf = "");

std::string m_endpoint;

Expand All @@ -48,7 +47,7 @@ class ZmqClient

std::mutex m_socketMutex;

std::vector<char> m_sendbuffer;
std::vector<char> m_sendbuffer;
};

}
4 changes: 0 additions & 4 deletions common/zmqconsumerstatetable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ ZmqConsumerStateTable::ZmqConsumerStateTable(DBConnector *db, const std::string

void ZmqConsumerStateTable::handleReceivedData(const std::vector<std::shared_ptr<KeyOpFieldsValuesTuple>> &kcos)
{
SWSS_LOG_DEBUG("Entering ZmqConsumerStateTable::handleReceivedData");
for (auto kco : kcos)
{
std::shared_ptr<KeyOpFieldsValuesTuple> clone = nullptr;
Expand All @@ -54,7 +53,6 @@ void ZmqConsumerStateTable::handleReceivedData(const std::vector<std::shared_ptr
{
std::lock_guard<std::mutex> lock(m_receivedQueueMutex);
m_receivedOperationQueue.push(kco);
SWSS_LOG_DEBUG("Called m_receivedOperationQueue.push in handleReceivedData()");
}

if (m_asyncDBUpdater != nullptr)
Expand All @@ -75,7 +73,6 @@ void ZmqConsumerStateTable::pops(std::deque<KeyOpFieldsValuesTuple> &vkco, const

// For new data append to m_dataQueue during pops, will not be include in result.
count = m_receivedOperationQueue.size();
//SWSS_LOG_DEBUG("count value: %ld", count);
if (!count)
{
return;
Expand All @@ -85,7 +82,6 @@ void ZmqConsumerStateTable::pops(std::deque<KeyOpFieldsValuesTuple> &vkco, const
vkco.clear();
for (size_t ie = 0; ie < count; ie++)
{
//SWSS_LOG_DEBUG("count inside for loop: %ld", count);
auto& kco = *(m_receivedOperationQueue.front());
vkco.push_back(std::move(kco));

Expand Down
2 changes: 0 additions & 2 deletions common/zmqproducerstatetable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ void ZmqProducerStateTable::del(const std::vector<std::string> &keys)

void ZmqProducerStateTable::send(const std::vector<KeyOpFieldsValuesTuple> &kcos)
{
SWSS_LOG_DEBUG("DIV:: Inside function ZmqProducerStateTable::send");
m_zmqClient.sendMsg(
m_dbName,
m_tableNameStr,
Expand All @@ -169,7 +168,6 @@ bool ZmqProducerStateTable::wait(const std::string& dbName,
const std::string& tableName,
const std::vector<std::shared_ptr<KeyOpFieldsValuesTuple>>& kcos)
{
SWSS_LOG_DEBUG("DIV:: Inside function ZmqProducerStateTable::wait");
return m_zmqClient.wait(dbName, tableName, kcos);
}

Expand Down
4 changes: 1 addition & 3 deletions common/zmqproducerstatetable.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class ZmqProducerStateTable : public ProducerStateTable
public:
ZmqProducerStateTable(DBConnector *db, const std::string &tableName, ZmqClient &zmqClient, bool dbPersistence = true);
ZmqProducerStateTable(RedisPipeline *pipeline, const std::string &tableName, ZmqClient &zmqClient, bool buffered = false, bool dbPersistence = true);
// ~ZmqProducerStateTable() = default;

/* Implements set() and del() commands using notification messages */
virtual void set(const std::string &key,
Expand All @@ -38,8 +37,7 @@ class ZmqProducerStateTable : public ProducerStateTable
// Batched send that can include both SET and DEL requests.
virtual void send(const std::vector<KeyOpFieldsValuesTuple> &kcos);

// This method should only be used if the ZmqClient enables one-to-one sync.

// To wait for the response from the peer.
virtual bool wait(const std::string& dbName,
const std::string& tableName,
const std::vector<std::shared_ptr<KeyOpFieldsValuesTuple>>& kcos);
Expand Down
Loading

0 comments on commit 1c2c16b

Please sign in to comment.