Skip to content

Added support for setting TTL on a Table managed entry.#526

Merged
qiluo-msft merged 15 commits intosonic-net:masterfrom
Metaswitch:expire_ttl_in_Table
Sep 19, 2021
Merged

Added support for setting TTL on a Table managed entry.#526
qiluo-msft merged 15 commits intosonic-net:masterfrom
Metaswitch:expire_ttl_in_Table

Conversation

@Cosmin-Jinga-MS
Copy link
Copy Markdown
Contributor

[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

Signed-off-by: Cosmin Jinga [email protected]

…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]>
@ghost
Copy link
Copy Markdown

ghost commented Sep 6, 2021

CLA assistant check
All CLA requirements met.

@Cosmin-Jinga-MS Cosmin-Jinga-MS marked this pull request as draft September 6, 2021 06:46
@Cosmin-Jinga-MS Cosmin-Jinga-MS marked this pull request as ready for review September 6, 2021 06:50
@TACappleman
Copy link
Copy Markdown
Contributor

@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*/)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why op and prefix are omitted ? set should work exactly the same as with or without ttl, otherwise should be named differently

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@qiluo-msft what do you think here?

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);
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Sep 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const int32_t&

int is good enough.
How do you know it's 32 bits? It seems supporting 64 bits. #Closed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, changing the type to int.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is int64_t better?

Copy link
Copy Markdown
Contributor Author

@Cosmin-Jinga-MS Cosmin-Jinga-MS Sep 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor Author

@Cosmin-Jinga-MS Cosmin-Jinga-MS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor Author

@Cosmin-Jinga-MS Cosmin-Jinga-MS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated ttl to int64_type and changed its position in the set() params to fix overlooked compilation errors in existing calls for set()

/* 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);
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Sep 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%d

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I will update it to %lld and add/extend an UT to also issue a set with configured TTL

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return in void function? formta() also is void?

common/table.cpp Outdated

if (!m_buffered)
{
m_pipe->flush();
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Sep 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flush

Is it possible to flush only once in this function? #Closed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
   }
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By design, yes. In your proposed code, you can further improve by move flush out of if-else.

@Cosmin-Jinga-MS
Copy link
Copy Markdown
Contributor Author

@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.
What would be the best approach here? Update sonic-swss as well with the extra ttl param? Not sure how to integrate it in the same PR as it's from a different submodule.
Should I revert back to overloading set()?

@qiluo-msft
Copy link
Copy Markdown
Contributor

I see this is painful. Seems overloading set() is better approach. If you choose this way, please make sure

  1. reuse code as much as possible, for example, rewrite old function by calling your new function
  2. Add TODO comment to remove the overloading and use default parameter

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);
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Sep 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  [](http://example.com/codeflow?start=0&length=6)

Please indent with 4x spaces #Closed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated indents in last commit

Copy link
Copy Markdown
Contributor Author

@Cosmin-Jinga-MS Cosmin-Jinga-MS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added new set() as the driving routine for set OPs

@Cosmin-Jinga-MS
Copy link
Copy Markdown
Contributor Author

Hi @qiluo-msft,
About the remaining failing UT from the current pipeline. https://dev.azure.com/mssonic/build/_build/results?buildId=35308&view=ms.vss-test-web.build-test-results-tab
I'm not seeing anything wrong with the set operation in it(it calls the old set() implementation, nothing touches the new ttl code in this scenario) and it seems it's not a particularly stable UT(looking into its history)
image
Is there a chance a retry of this pipeline would fix it?(I don't have enough rights on my account to re-run failed UTs from the gitlab pipeline interface)

@TACappleman
Copy link
Copy Markdown
Contributor

/azpw run

@qiluo-msft
Copy link
Copy Markdown
Contributor

The PR owner could use /azpw run to retrigger checkers.

@Cosmin-Jinga-MS
Copy link
Copy Markdown
Contributor Author

/azpw run

@mssonicbld
Copy link
Copy Markdown
Collaborator

/AzurePipelines run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@Cosmin-Jinga-MS
Copy link
Copy Markdown
Contributor Author

Looks like the failure is still present.
I've ran the UT in question locally and managed to repro the issue both with my changes from swss-common in place and with a fresh build from master. Currently looking a bit at the failure to see if I can spot the problem but it does not look to be caused by my changes.
Syslog err output from the sonic-swss-common master run(without my changes):
image
Looks like a failure to program those interfaces due to confilct on the lane/ids to me which leads to a orchagent crash.

@Cosmin-Jinga-MS
Copy link
Copy Markdown
Contributor Author

@qiluo-msft
I did not manage to get very far with the investigation into this as orchagent logs are rate-limited before the failure occurs once it's set to DEBUG level. Are there any overnight/on-demand runs we can check to confirm this tests failure reproduces on master as well?(as said before, I'm seeing this failure on my local master ut run too)
If it does repro on a master pipeline as well, it would be better to defer the investigation to someone more familiar with recirc ports, in my opinion.

@qiluo-msft
Copy link
Copy Markdown
Contributor

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.

@TACappleman
Copy link
Copy Markdown
Contributor

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

@Cosmin-Jinga-MS
Copy link
Copy Markdown
Contributor Author

/azpw run

@mssonicbld
Copy link
Copy Markdown
Collaborator

/AzurePipelines run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@Cosmin-Jinga-MS
Copy link
Copy Markdown
Contributor Author

@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?

@Cosmin-Jinga-MS
Copy link
Copy Markdown
Contributor Author

/azpw run

@mssonicbld
Copy link
Copy Markdown
Collaborator

/AzurePipelines run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@qiluo-msft
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@qiluo-msft qiluo-msft merged commit 81182ec into sonic-net:master Sep 19, 2021
Cosmin-Jinga-MS added a commit to Metaswitch/sonic-swss-common that referenced this pull request Sep 20, 2021
[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
Cosmin-Jinga-MS added a commit to Metaswitch/sonic-swss-common that referenced this pull request Sep 20, 2021
Added support for setting TTL on a Table managed entry. (sonic-net#526)
jimmyzhai added a commit to sonic-net/sonic-buildimage that referenced this pull request Sep 24, 2021
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)
TACappleman pushed a commit to Metaswitch/sonic-swss-common that referenced this pull request Oct 1, 2021
[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
prgeor pushed a commit to prgeor/sonic-swss-common that referenced this pull request Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants