33#include < sstream>
44#include < utility>
55#include < algorithm>
6+ #include " redispipeline.h"
67#include " redisreply.h"
78#include " table.h"
89#include " redisapi.h"
@@ -13,40 +14,37 @@ using namespace std;
1314
1415namespace swss {
1516
16- ProducerStateTable::ProducerStateTable (DBConnector *db, const string &tableName)
17- : ProducerStateTable(new RedisPipeline(db, 1 ), tableName, false )
17+ ProducerStateTable::ProducerStateTable (DBConnector *db, const string &tableName, bool flushPub )
18+ : ProducerStateTable(new RedisPipeline(db, 1 ), tableName, false , flushPub )
1819{
1920 m_pipeowned = true ;
2021}
2122
22- ProducerStateTable::ProducerStateTable (RedisPipeline *pipeline, const string &tableName, bool buffered)
23+ ProducerStateTable::ProducerStateTable (RedisPipeline *pipeline, const string &tableName, bool buffered, bool flushPub )
2324 : TableBase(tableName, SonicDBConfig::getSeparator(pipeline->getDBConnector ()))
2425 , TableName_KeySet(tableName)
26+ , m_flushPub(flushPub)
2527 , m_buffered(buffered)
2628 , m_pipeowned(false )
2729 , m_tempViewActive(false )
2830 , m_pipe(pipeline)
2931{
32+ if (m_flushPub) {
33+ m_pipe->addChannel (getChannelName (m_pipe->getDbId ()));
34+ }
35+
3036 // num in luaSet and luaDel means number of elements that were added to the key set,
3137 // not including all the elements already present into the set.
3238 string luaSet =
3339 " local added = redis.call('SADD', KEYS[2], ARGV[2])\n "
3440 " for i = 0, #KEYS - 3 do\n "
3541 " redis.call('HSET', KEYS[3 + i], ARGV[3 + i * 2], ARGV[4 + i * 2])\n "
3642 " end\n "
37- " if added > 0 then \n "
38- " redis.call('PUBLISH', KEYS[1], ARGV[1])\n "
39- " end\n " ;
40- m_shaSet = m_pipe->loadRedisScript (luaSet);
4143
4244 string luaDel =
4345 " local added = redis.call('SADD', KEYS[2], ARGV[2])\n "
4446 " redis.call('SADD', KEYS[4], ARGV[2])\n "
4547 " redis.call('DEL', KEYS[3])\n "
46- " if added > 0 then \n "
47- " redis.call('PUBLISH', KEYS[1], ARGV[1])\n "
48- " end\n " ;
49- m_shaDel = m_pipe->loadRedisScript (luaDel);
5048
5149 string luaBatchedSet =
5250 " local added = 0\n "
@@ -60,10 +58,6 @@ ProducerStateTable::ProducerStateTable(RedisPipeline *pipeline, const string &ta
6058 " end\n "
6159 " idx = idx + tonumber(ARGV[idx]) * 2 + 1\n "
6260 " end\n "
63- " if added > 0 then \n "
64- " redis.call('PUBLISH', KEYS[1], ARGV[1])\n "
65- " end\n " ;
66- m_shaBatchedSet = m_pipe->loadRedisScript (luaBatchedSet);
6761
6862 string luaBatchedDel =
6963 " local added = 0\n "
@@ -72,10 +66,6 @@ ProducerStateTable::ProducerStateTable(RedisPipeline *pipeline, const string &ta
7266 " redis.call('SADD', KEYS[3], KEYS[5 + i])\n "
7367 " redis.call('DEL', KEYS[4] .. KEYS[5 + i])\n "
7468 " end\n "
75- " if added > 0 then \n "
76- " redis.call('PUBLISH', KEYS[1], ARGV[1])\n "
77- " end\n " ;
78- m_shaBatchedDel = m_pipe->loadRedisScript (luaBatchedDel);
7969
8070 string luaClear =
8171 " redis.call('DEL', KEYS[1])\n "
@@ -84,6 +74,21 @@ ProducerStateTable::ProducerStateTable(RedisPipeline *pipeline, const string &ta
8474 " redis.call('DEL', k)\n "
8575 " end\n "
8676 " redis.call('DEL', KEYS[3])\n " ;
77+
78+ if (!m_flushPub) {
79+ string luaPub =
80+ " if added > 0 then \n "
81+ " redis.call('PUBLISH', KEYS[1], ARGV[1])\n "
82+ " end\n " ;
83+ luaSet += luaPub;
84+ luaDel += luaPub;
85+ luaBatchedSet += luaPub;
86+ luaBatchedDel += luaPub;
87+ }
88+ m_shaSet = m_pipe->loadRedisScript (luaSet);
89+ m_shaDel = m_pipe->loadRedisScript (luaDel);
90+ m_shaBatchedSet = m_pipe->loadRedisScript (luaBatchedSet);
91+ m_shaBatchedDel = m_pipe->loadRedisScript (luaBatchedDel);
8792 m_shaClear = m_pipe->loadRedisScript (luaClear);
8893
8994 string luaApplyView = loadLuaScript (" producer_state_table_apply_view.lua" );
0 commit comments