Added support for setting TTL on a Table managed entry.#526
Added support for setting TTL on a Table managed entry.#526qiluo-msft merged 15 commits intosonic-net:masterfrom
Conversation
…aged entry. * Updated table.h with a new set() routine capable of also setting TTL on an entry. * Updated rediscommand.h with the EXPIRE command Signed-off-by: Cosmin Jinga <[email protected]>
|
@qiluo-msft could you review this PR please? |
common/table.cpp
Outdated
| } | ||
|
|
||
| void Table::set(const string &key, const vector<FieldValueTuple> &values, | ||
| const int32_t &ttl, const string& /*op*/, const string& /*prefix*/) |
There was a problem hiding this comment.
why op and prefix are omitted ? set should work exactly the same as with or without ttl, otherwise should be named differently
There was a problem hiding this comment.
op and prefix are also omitted in the existing set() routine for Table
I've overloaded set() with the extra ttl argument to have a distinction between it and the existing one.
I'm adding a reworked version of the code with the ttl is set directly in the existing routine.
common/rediscommand.h
Outdated
| void formatHDEL(const std::string& key, const std::vector<std::string>& fields); | ||
|
|
||
| /* Format EXPIRE key field command */ | ||
| void formatEXPIRE(const std::string& key, const int32_t& ttl); |
There was a problem hiding this comment.
Agreed, changing the type to int.
There was a problem hiding this comment.
Redis documentation on expire does not actually provide a range for the ttl values https://redis.io/commands/expire
Having manually tried an in-range and an out-of-range int64 value it does indeed need to be int64.
127.0.0.1:6379> EXPIRE ISIS_ROUTER_LSP_STATE:localhost:1 9223372036854775801
(integer) 1
127.0.0.1:6379> EXPIRE ISIS_ROUTER_LSP_STATE:localhost:1 9223372036854775809
(error) ERR value is not an integer or out of range
I'll update the code momentarily.
Updated code to integrate ttl configuration into existing set() routine, thus preventing code duplication.
Updated set() header to allow ttl configuration. Moved DEFAULT_DB_TTL define outside of Table class for it to be visible in test code.
Changed ttl type to int
Changed ttl type to int
Cosmin-Jinga-MS
left a comment
There was a problem hiding this comment.
Addressed comments;
Main update is removal of the new overloaded set() and moving of the ttl configuration inside the existing routine.
Changed to int64 to fit full range of redis accepted input.
Changed to int64 to fit full range of redis accepted input.
Changing set() ttl param placement to fix compilation error.
Changing ttl param order in set() to fix compilation errors
Changed order of ttl param to fix compilation error
Cosmin-Jinga-MS
left a comment
There was a problem hiding this comment.
Updated ttl to int64_type and changed its position in the set() params to fix overlooked compilation errors in existing calls for set()
common/rediscommand.cpp
Outdated
| /* Format EXPIRE key field command */ | ||
| void RedisCommand::formatEXPIRE(const std::string& key, const int64_t& ttl) | ||
| { | ||
| return format("EXPIRE %s %d", key.c_str(), ttl); |
There was a problem hiding this comment.
hiredis internally implement some int length. ref: https://github.com/redis/hiredis/blob/2d9d77518d012a54ae34f9822e4b4d19823c4b75/hiredis.c#L434
Seems like %lld is for int64_t. Could you check and add unit test? #Closed
There was a problem hiding this comment.
yes, I will update it to %lld and add/extend an UT to also issue a set with configured TTL
There was a problem hiding this comment.
return in void function? formta() also is void?
common/table.cpp
Outdated
|
|
||
| if (!m_buffered) | ||
| { | ||
| m_pipe->flush(); |
There was a problem hiding this comment.
Does RedisPipeline support enqueuing of more than one command without it being flushed inbetween?
i.e.:
cmd.formatHMSET(getKeyName(key), values.begin(), values.end()); m_pipe->push(cmd, REDIS_REPLY_STATUS); cmd.formatEXPIRE(getKeyName(key), ttl); m_pipe->push(cmd, REDIS_REPLY_INTEGER); if (!m_buffered) { m_pipe->flush(); }
If it does the code can be changed to:
if (ttl != DEFAULT_DB_TTL) { // Configure the expire time for the entry that was just added cmd.formatEXPIRE(getKeyName(key), ttl); m_pipe->push(cmd, REDIS_REPLY_INTEGER); if (!m_buffered) { m_pipe->flush(); } } else { if (!m_buffered) { m_pipe->flush(); } }
There was a problem hiding this comment.
By design, yes. In your proposed code, you can further improve by move flush out of if-else.
|
@qiluo-msft Updating set() with an extra param for ttl rather than overloading it has raised compilation dependencies in sonic-swss's mock_table.cpp which I've missed during the local build of swss-common but have been uncovered by the pipeline now. |
|
I see this is painful. Seems overloading
In reply to: 915814243 |
Updated logic to call pipeline->flush() only once
Updated format type to long long int.
common/table.cpp
Outdated
| if (ttl != DEFAULT_DB_TTL) | ||
| { | ||
| // Configure the expire time for the entry that was just added | ||
| cmd.formatEXPIRE(getKeyName(key), ttl); |
There was a problem hiding this comment.
[](http://example.com/codeflow?start=0&length=6)
Please indent with 4x spaces #Closed
There was a problem hiding this comment.
updated indents in last commit
3d32f3c to
7304f02
Compare
Cosmin-Jinga-MS
left a comment
There was a problem hiding this comment.
Added new set() as the driving routine for set OPs
|
Hi @qiluo-msft, |
|
/azpw run |
|
The PR owner could use |
|
/azpw run |
|
/AzurePipelines run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@qiluo-msft |
|
You can check master branch, other branches or PR on https://dev.azure.com/mssonic/build/_build?definitionId=9&_a=summary&view=branches I just trigged a new build on master branch. |
|
One of the ones that's failed on the latest run fails on a large percentage of pipelines, and the other one sometimes, so worth keeping on trying until it works |
|
/azpw run |
|
/AzurePipelines run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@qiluo-msft I see the master run has also failed on the test_recirc_port UT(it's now running a 2nd attempt). My PR retry also failed that UT again. Should I keep retrying too? |
|
/azpw run |
|
/AzurePipelines run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
[table.h/rediscommand.h] * Updated table.h with a new set() routine capable of also setting TTL on an entry. * Updated rediscommand.h with the EXPIRE command
Added support for setting TTL on a Table managed entry. (sonic-net#526)
The following fixes are included:
b502743 [gearbox] Since ASIC_DB, as well its COUNTER_DB, FLEX_COUNTER_DB use separator ':', GB_ASIC_DB
should use same ((sonic-net/sonic-swss-common#532)
81182ec Added support for setting TTL on a Table managed entry. ((sonic-net/sonic-swss-common#526)
[table.h/rediscommand.h] * Updated table.h with a new set() routine capable of also setting TTL on an entry. * Updated rediscommand.h with the EXPIRE command


[table.h/rediscommand.h]
Signed-off-by: Cosmin Jinga [email protected]