@@ -13,39 +13,37 @@ using namespace std;
1313
1414namespace swss {
1515
16- ProducerStateTable::ProducerStateTable (DBConnector *db, const string &tableName)
17- : ProducerStateTable(new RedisPipeline(db, 1 ), tableName, false )
16+ ProducerStateTable::ProducerStateTable (DBConnector *db, const string &tableName, bool flushPub )
17+ : ProducerStateTable(new RedisPipeline(db, 1 ), tableName, false , flushPub )
1818{
1919 m_pipeowned = true ;
2020}
2121
22- ProducerStateTable::ProducerStateTable (RedisPipeline *pipeline, const string &tableName, bool buffered)
22+ ProducerStateTable::ProducerStateTable (RedisPipeline *pipeline, const string &tableName, bool buffered, bool flushPub )
2323 : TableBase(tableName, SonicDBConfig::getSeparator(pipeline->getDBConnector ()))
2424 , TableName_KeySet(tableName)
25+ , m_flushPub(flushPub)
2526 , m_buffered(buffered)
2627 , m_pipeowned(false )
2728 , m_tempViewActive(false )
2829 , m_pipe(pipeline)
2930{
31+ if (m_flushPub) {
32+ m_pipe->addChannel (getChannelName (m_pipe->getDbId ()));
33+ }
3034 // num in luaSet and luaDel means number of elements that were added to the key set,
3135 // not including all the elements already present into the set.
3236 string luaSet =
3337 " local added = redis.call('SADD', KEYS[2], ARGV[2])\n "
3438 " for i = 0, #KEYS - 3 do\n "
3539 " redis.call('HSET', KEYS[3 + i], ARGV[3 + i * 2], ARGV[4 + i * 2])\n "
36- " end\n "
37- " if added > 0 then \n "
38- " redis.call('PUBLISH', KEYS[1], ARGV[1])\n "
3940 " end\n " ;
4041 m_shaSet = m_pipe->loadRedisScript (luaSet);
4142
4243 string luaDel =
4344 " local added = redis.call('SADD', KEYS[2], ARGV[2])\n "
4445 " redis.call('SADD', KEYS[4], ARGV[2])\n "
45- " redis.call('DEL', KEYS[3])\n "
46- " if added > 0 then \n "
47- " redis.call('PUBLISH', KEYS[1], ARGV[1])\n "
48- " end\n " ;
46+ " redis.call('DEL', KEYS[3])\n " ;
4947 m_shaDel = m_pipe->loadRedisScript (luaDel);
5048
5149 string luaBatchedSet =
@@ -59,9 +57,6 @@ ProducerStateTable::ProducerStateTable(RedisPipeline *pipeline, const string &ta
5957 " redis.call('HSET', KEYS[3] .. KEYS[4 + i], attr, val)\n "
6058 " end\n "
6159 " idx = idx + tonumber(ARGV[idx]) * 2 + 1\n "
62- " end\n "
63- " if added > 0 then \n "
64- " redis.call('PUBLISH', KEYS[1], ARGV[1])\n "
6560 " end\n " ;
6661 m_shaBatchedSet = m_pipe->loadRedisScript (luaBatchedSet);
6762
@@ -71,9 +66,6 @@ ProducerStateTable::ProducerStateTable(RedisPipeline *pipeline, const string &ta
7166 " added = added + redis.call('SADD', KEYS[2], KEYS[5 + i])\n "
7267 " redis.call('SADD', KEYS[3], KEYS[5 + i])\n "
7368 " redis.call('DEL', KEYS[4] .. KEYS[5 + i])\n "
74- " end\n "
75- " if added > 0 then \n "
76- " redis.call('PUBLISH', KEYS[1], ARGV[1])\n "
7769 " end\n " ;
7870 m_shaBatchedDel = m_pipe->loadRedisScript (luaBatchedDel);
7971
@@ -88,6 +80,21 @@ ProducerStateTable::ProducerStateTable(RedisPipeline *pipeline, const string &ta
8880
8981 string luaApplyView = loadLuaScript (" producer_state_table_apply_view.lua" );
9082 m_shaApplyView = m_pipe->loadRedisScript (luaApplyView);
83+
84+ if (!m_flushPub) {
85+ string luaPub =
86+ " if added > 0 then \n "
87+ " redis.call('PUBLISH', KEYS[1], ARGV[1])\n "
88+ " end\n " ;
89+ luaSet += luaPub;
90+ luaDel += luaPub;
91+ luaBatchedSet += luaPub;
92+ luaBatchedDel += luaPub;
93+ m_shaSet = m_pipe->loadRedisScript (luaSet);
94+ m_shaDel = m_pipe->loadRedisScript (luaDel);
95+ m_shaBatchedSet = m_pipe->loadRedisScript (luaBatchedSet);
96+ m_shaBatchedDel = m_pipe->loadRedisScript (luaBatchedDel);
97+ }
9198}
9299
93100ProducerStateTable::~ProducerStateTable ()
0 commit comments