Skip to content

Commit b4938a5

Browse files
authoredSep 18, 2020
Replace RedisClient with DBConnector (sonic-net#1439)
After this PR: sonic-net/sonic-swss-common#382
1 parent 5b0f7be commit b4938a5

9 files changed

+23
-36
lines changed
 

‎mclagsyncd/mclaglink.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ using namespace std;
3838
void MclagLink::getOidToPortNameMap(std::unordered_map<std::string, std:: string> & port_map)
3939
{
4040
std::unordered_map<std::string, std:: string>::iterator it;
41-
auto hash = p_redisClient_to_counters->hgetall("COUNTERS_PORT_NAME_MAP");
41+
auto hash = p_counters_db->hgetall("COUNTERS_PORT_NAME_MAP");
4242

4343
for (it = hash.begin(); it != hash.end(); ++it)
4444
port_map.insert(pair<string, string>(it->second, it->first));
@@ -53,14 +53,14 @@ void MclagLink::getBridgePortIdToAttrPortIdMap(std::map<std::string, std:: strin
5353

5454
std::unordered_map<string, string>::iterator attr_port_id;
5555

56-
auto keys = p_redisClient_to_asic->keys("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:*");
56+
auto keys = p_asic_db->keys("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:*");
5757

5858
for (auto& key : keys)
5959
{
6060
pos1 = key.find("oid:", 0);
6161
bridge_port_id = key.substr(pos1);
6262

63-
auto hash = p_redisClient_to_asic->hgetall(key);
63+
auto hash = p_asic_db->hgetall(key);
6464
attr_port_id = hash.find("SAI_BRIDGE_PORT_ATTR_PORT_ID");
6565
if (attr_port_id == hash.end())
6666
{
@@ -81,7 +81,7 @@ void MclagLink::getVidByBvid(std::string &bvid, std::string &vlanid)
8181
std::string pre = "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:";
8282
std::string key = pre + bvid;
8383

84-
auto hash = p_redisClient_to_asic->hgetall(key.c_str());
84+
auto hash = p_asic_db->hgetall(key.c_str());
8585

8686
attr_vlan_id = hash.find("SAI_VLAN_ATTR_VLAN_ID");
8787
if (attr_vlan_id == hash.end())
@@ -109,7 +109,7 @@ void MclagLink::getFdbSet(std::set<mclag_fdb> *fdb_set)
109109
std::map<std::string, std::string>::iterator brPortId_to_attrPortId_it;
110110
std::unordered_map<std::string, std::string>::iterator oid_to_portName_it;
111111

112-
auto keys = p_redisClient_to_asic->keys("ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:*");
112+
auto keys = p_asic_db->keys("ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:*");
113113

114114
for (auto& key : keys)
115115
{
@@ -136,7 +136,7 @@ void MclagLink::getFdbSet(std::set<mclag_fdb> *fdb_set)
136136
mac = key.substr(pos1, pos2 - pos1 + 1);
137137

138138
/*get type*/
139-
auto hash = p_redisClient_to_asic->hgetall(key);
139+
auto hash = p_asic_db->hgetall(key);
140140
type_it = hash.find("SAI_FDB_ENTRY_ATTR_TYPE");
141141
if (type_it == hash.end())
142142
{

‎mclagsyncd/mclaglink.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ class MclagLink : public Selectable {
102102
ProducerStateTable *p_acl_table_tbl;
103103
ProducerStateTable *p_acl_rule_tbl;
104104
DBConnector *p_appl_db;
105-
RedisClient *p_redisClient_to_asic;/*redis client access to ASIC_DB*/
106-
RedisClient *p_redisClient_to_counters;/*redis client access to COUNTERS_DB*/
105+
DBConnector *p_asic_db; /*redis client access to ASIC_DB*/
106+
DBConnector *p_counters_db; /*redis client access to COUNTERS_DB*/
107107
std::set <mclag_fdb> *p_old_fdb;
108108

109109
MclagLink(uint16_t port = MCLAG_DEFAULT_PORT);

‎mclagsyncd/mclagsyncd.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ int main(int argc, char **argv)
4141
ProducerStateTable fdb_tbl(&appl_db, APP_FDB_TABLE_NAME);
4242
ProducerStateTable acl_table_tbl(&appl_db, APP_ACL_TABLE_TABLE_NAME);
4343
ProducerStateTable acl_rule_tbl(&appl_db, APP_ACL_RULE_TABLE_NAME);
44-
RedisClient redisClient_to_asicDb(&asic_db);
45-
RedisClient redisClient_to_countersDb(&counters_db);
4644
map <string, string> isolate;
4745
RedisPipeline pipeline(&appl_db);
4846
set <mclag_fdb> old_fdb;
@@ -62,8 +60,8 @@ int main(int argc, char **argv)
6260
mclag.p_acl_table_tbl = &acl_table_tbl;
6361
mclag.p_acl_rule_tbl = &acl_rule_tbl;
6462
mclag.p_appl_db = &appl_db;
65-
mclag.p_redisClient_to_asic = &redisClient_to_asicDb;
66-
mclag.p_redisClient_to_counters = &redisClient_to_countersDb;
63+
mclag.p_asic_db = &asic_db;
64+
mclag.p_counters_db = &counters_db;
6765
mclag.p_old_fdb = &old_fdb;
6866

6967
cout << "Waiting for connection..." << endl;

‎orchagent/bufferorch.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ BufferOrch::BufferOrch(DBConnector *db, vector<string> &tableNames) :
3939
m_flexCounterDb(new DBConnector("FLEX_COUNTER_DB", 0)),
4040
m_flexCounterTable(new ProducerTable(m_flexCounterDb.get(), FLEX_COUNTER_TABLE)),
4141
m_flexCounterGroupTable(new ProducerTable(m_flexCounterDb.get(), FLEX_COUNTER_GROUP_TABLE)),
42-
m_countersDb(new DBConnector("COUNTERS_DB", 0)),
43-
m_countersDbRedisClient(m_countersDb.get())
42+
m_countersDb(new DBConnector("COUNTERS_DB", 0))
4443
{
4544
SWSS_LOG_ENTER();
4645
initTableHandlers();
@@ -358,7 +357,7 @@ task_process_status BufferOrch::processBufferPool(Consumer &consumer)
358357
// Specifically, we push the buffer pool name to oid mapping upon the creation of the oid
359358
// In pg and queue case, this mapping installment is deferred to FlexCounterOrch at a reception of field
360359
// "FLEX_COUNTER_STATUS"
361-
m_countersDbRedisClient.hset(COUNTERS_BUFFER_POOL_NAME_MAP, object_name, sai_serialize_object_id(sai_object));
360+
m_countersDb->hset(COUNTERS_BUFFER_POOL_NAME_MAP, object_name, sai_serialize_object_id(sai_object));
362361
}
363362
}
364363
else if (op == DEL_COMMAND)
@@ -372,7 +371,7 @@ task_process_status BufferOrch::processBufferPool(Consumer &consumer)
372371
SWSS_LOG_NOTICE("Removed buffer pool %s with type %s", object_name.c_str(), map_type_name.c_str());
373372
auto it_to_delete = (m_buffer_type_maps[map_type_name])->find(object_name);
374373
(m_buffer_type_maps[map_type_name])->erase(it_to_delete);
375-
m_countersDbRedisClient.hdel(COUNTERS_BUFFER_POOL_NAME_MAP, object_name);
374+
m_countersDb->hdel(COUNTERS_BUFFER_POOL_NAME_MAP, object_name);
376375
}
377376
else
378377
{

‎orchagent/bufferorch.h

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ class BufferOrch : public Orch
6464
unique_ptr<ProducerTable> m_flexCounterTable;
6565

6666
unique_ptr<DBConnector> m_countersDb;
67-
RedisClient m_countersDbRedisClient;
6867

6968
bool m_isBufferPoolWatermarkCounterIdListGenerated = false;
7069
};

‎orchagent/countercheckorch.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,12 @@ QueueMcCounters CounterCheckOrch::getQueueMcCounters(
193193

194194
vector<FieldValueTuple> fieldValues;
195195
QueueMcCounters counters;
196-
RedisClient redisClient(m_countersDb.get());
197196

198197
for (uint8_t prio = 0; prio < port.m_queue_ids.size(); prio++)
199198
{
200199
sai_object_id_t queueId = port.m_queue_ids[prio];
201200
auto queueIdStr = sai_serialize_object_id(queueId);
202-
auto queueType = redisClient.hget(COUNTERS_QUEUE_TYPE_MAP, queueIdStr);
201+
auto queueType = m_countersDb->hget(COUNTERS_QUEUE_TYPE_MAP, queueIdStr);
203202

204203
if (queueType.get() == nullptr || *queueType != "SAI_QUEUE_TYPE_MULTICAST" || !m_countersTable->get(queueIdStr, fieldValues))
205204
{

‎orchagent/pfcwdorch.cpp

+8-13
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,8 @@ void PfcWdSwOrch<DropHandler, ForwardHandler>::disableBigRedSwitchMode()
364364
}
365365

366366
auto queueId = entry.first;
367-
RedisClient redisClient(this->getCountersDb().get());
368367
string countersKey = this->getCountersTable()->getTableName() + this->getCountersTable()->getTableNameSeparator() + sai_serialize_object_id(queueId);
369-
redisClient.hdel(countersKey, "BIG_RED_SWITCH_MODE");
368+
this->getCountersDb()->hdel(countersKey, "BIG_RED_SWITCH_MODE");
370369
}
371370

372371
m_brsEntryMap.clear();
@@ -633,9 +632,8 @@ void PfcWdSwOrch<DropHandler, ForwardHandler>::unregisterFromWdDb(const Port& po
633632
m_entryMap.erase(queueId);
634633

635634
// Clean up
636-
RedisClient redisClient(this->getCountersDb().get());
637635
string countersKey = this->getCountersTable()->getTableName() + this->getCountersTable()->getTableNameSeparator() + sai_serialize_object_id(queueId);
638-
redisClient.hdel(countersKey, {"PFC_WD_DETECTION_TIME", "PFC_WD_RESTORATION_TIME", "PFC_WD_ACTION", "PFC_WD_STATUS"});
636+
this->getCountersDb()->hdel(countersKey, {"PFC_WD_DETECTION_TIME", "PFC_WD_RESTORATION_TIME", "PFC_WD_ACTION", "PFC_WD_STATUS"});
639637
}
640638

641639
}
@@ -657,8 +655,7 @@ PfcWdSwOrch<DropHandler, ForwardHandler>::PfcWdSwOrch(
657655
c_queueAttrIds(queueAttrIds),
658656
m_pollInterval(pollInterval),
659657
m_applDb(make_shared<DBConnector>("APPL_DB", 0)),
660-
m_applTable(make_shared<Table>(m_applDb.get(), APP_PFC_WD_TABLE_NAME "_INSTORM")),
661-
m_applDbRedisClient(m_applDb.get())
658+
m_applTable(make_shared<Table>(m_applDb.get(), APP_PFC_WD_TABLE_NAME "_INSTORM"))
662659
{
663660
SWSS_LOG_ENTER();
664661

@@ -934,7 +931,7 @@ bool PfcWdSwOrch<DropHandler, ForwardHandler>::startWdActionOnQueue(const string
934931
entry->second.handler->initCounters();
935932
// Log storm event to APPL_DB for warm-reboot purpose
936933
string key = m_applTable->getTableName() + m_applTable->getTableNameSeparator() + entry->second.portAlias;
937-
m_applDbRedisClient.hset(key, to_string(entry->second.index), PFC_WD_IN_STORM);
934+
m_applDb->hset(key, to_string(entry->second.index), PFC_WD_IN_STORM);
938935
}
939936
}
940937
else if (entry->second.action == PfcWdAction::PFC_WD_ACTION_DROP)
@@ -956,7 +953,7 @@ bool PfcWdSwOrch<DropHandler, ForwardHandler>::startWdActionOnQueue(const string
956953
entry->second.handler->initCounters();
957954
// Log storm event to APPL_DB for warm-reboot purpose
958955
string key = m_applTable->getTableName() + m_applTable->getTableNameSeparator() + entry->second.portAlias;
959-
m_applDbRedisClient.hset(key, to_string(entry->second.index), PFC_WD_IN_STORM);
956+
m_applDb->hset(key, to_string(entry->second.index), PFC_WD_IN_STORM);
960957
}
961958
}
962959
else if (entry->second.action == PfcWdAction::PFC_WD_ACTION_FORWARD)
@@ -978,7 +975,7 @@ bool PfcWdSwOrch<DropHandler, ForwardHandler>::startWdActionOnQueue(const string
978975
entry->second.handler->initCounters();
979976
// Log storm event to APPL_DB for warm-reboot purpose
980977
string key = m_applTable->getTableName() + m_applTable->getTableNameSeparator() + entry->second.portAlias;
981-
m_applDbRedisClient.hset(key, to_string(entry->second.index), PFC_WD_IN_STORM);
978+
m_applDb->hset(key, to_string(entry->second.index), PFC_WD_IN_STORM);
982979
}
983980
}
984981
else
@@ -1002,7 +999,7 @@ bool PfcWdSwOrch<DropHandler, ForwardHandler>::startWdActionOnQueue(const string
1002999
entry->second.handler = nullptr;
10031000
// Remove storm status in APPL_DB for warm-reboot purpose
10041001
string key = m_applTable->getTableName() + m_applTable->getTableNameSeparator() + entry->second.portAlias;
1005-
m_applDbRedisClient.hdel(key, to_string(entry->second.index));
1002+
m_applDb->hdel(key, to_string(entry->second.index));
10061003
}
10071004
}
10081005
else
@@ -1019,8 +1016,6 @@ bool PfcWdSwOrch<DropHandler, ForwardHandler>::bake()
10191016
{
10201017
// clean all *_last and *_LEFT fields in COUNTERS_TABLE
10211018
// to allow warm-reboot pfc detect & restore state machine to enter the same init state as cold-reboot
1022-
RedisClient redisClient(this->getCountersDb().get());
1023-
10241019
vector<string> cKeys;
10251020
this->getCountersTable()->getKeys(cKeys);
10261021
for (const auto &key : cKeys)
@@ -1037,7 +1032,7 @@ bool PfcWdSwOrch<DropHandler, ForwardHandler>::bake()
10371032
}
10381033
if (!wLasts.empty())
10391034
{
1040-
redisClient.hdel(
1035+
this->getCountersDb()->hdel(
10411036
this->getCountersTable()->getTableName()
10421037
+ this->getCountersTable()->getTableNameSeparator()
10431038
+ key,

‎orchagent/pfcwdorch.h

-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ class PfcWdSwOrch: public PfcWdOrch<DropHandler, ForwardHandler>
135135
shared_ptr<DBConnector> m_applDb = nullptr;
136136
// Track queues in storm
137137
shared_ptr<Table> m_applTable = nullptr;
138-
// used for hset and hdel
139-
RedisClient m_applDbRedisClient;
140138
};
141139

142140
#endif

‎orchagent/portsorch.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1894,8 +1894,7 @@ void PortsOrch::deInitPort(string alias, sai_object_id_t port_id)
18941894
port_stat_manager.clearCounterIdList(p.m_port_id);
18951895

18961896
/* remove port name map from counter table */
1897-
RedisClient redisClient(m_counter_db.get());
1898-
redisClient.hdel(COUNTERS_PORT_NAME_MAP, alias);
1897+
m_counter_db->hdel(COUNTERS_PORT_NAME_MAP, alias);
18991898

19001899
m_portList[alias].m_init = false;
19011900
SWSS_LOG_NOTICE("De-Initialized port %s", alias.c_str());

0 commit comments

Comments
 (0)