Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reintroducing PR #364 - DBconnector to support namespaces. #371

Merged
merged 3 commits into from
Aug 11, 2020

Conversation

judyjoseph
Copy link
Collaborator

Adding PR #364 back.

It was reverted earlier as there was a build failure with sonic-swss/tests/mock_tests/mock_dbconnector.cpp failing to build due to DBConnnector constructor being redefined there (Issue mentioned in sonic-net/sonic-swss#1363).
I have addressed it now by keeping the old constructor and delegating that to the new constructor which has "namespace" as additional argument.

This PR, I have included the changes to further align the dbConnector class here in sonic-swss-common with one present in sonic-py-swssdk
1. Ignore ( don't throw exception ) if the database_global.json file is not present.
2. validate the namespace before using it.

…-swss#1363

Also changes to allign the dbConnector class here with that of sonic-py-swssdk
   1. Ignore if the database_global.json file is not present.
   2. validate the namespace before using it.
@judyjoseph
Copy link
Collaborator Author

retest this please

@lguohan lguohan requested a review from qiluo-msft August 3, 2020 15:31
m_global_init = true;

// Make regular init also done
m_init = true;
Copy link
Contributor

@qiluo-msft qiluo-msft Aug 3, 2020

Choose a reason for hiding this comment

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

Please make the logic same as python version #Closed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, @qiluo-msft I was thinking about this yesterday, I finally moved it here as I thought this is logical to set the init flags to TRUE only if the database_global.json file exists and we have parsed it correct ?
Let me know what you think , I could change it back in python version if you too feel the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

If there is a bug in python version, we need to fix it first.
If not, make the C++ version behaves the same as python version.


In reply to: 464586440 [](ancestors = 464586440)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have updated so that it matches the python version. I agree that setting the flag m_global_init is ok here -- because this is an API which is invoked by user and he should provide the valid database_global.json file as input.

}
}

void SonicDBConfig::initialize(const string &file, const string &nameSpace)
Copy link
Contributor

@qiluo-msft qiluo-msft Aug 3, 2020

Choose a reason for hiding this comment

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

const string &nameSpace [](start = 51, length = 23)

Why this function has extra parameter than the python version load_sonic_db_config ? They should be the same. #Closed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will update - thanks !

Copy link
Contributor

@qiluo-msft qiluo-msft left a comment

Choose a reason for hiding this comment

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

As comments

@judyjoseph judyjoseph requested a review from abdosi August 4, 2020 22:57
@abdosi
Copy link
Contributor

abdosi commented Aug 5, 2020

Is this comment on previous PR is addressed:

a) why it has to be different ? It has be consistent . Any particular reason why it need to be different ? Application should be doing same irrespective of library being used.

b)Also it does not work if we don't call SonicDBConfig::initializeGlobalConfig.
DBConnector Constructor with particular asic namespace gives seg fault
as SonicDBConfig::getDbId will fail since m_init will be set when call for host/global namespace and when next time called
it will not go for else condition (since m_init is already set)

@judyjoseph
Copy link
Collaborator Author

Is this comment on previous PR is addressed:

a) why it has to be different ? It has be consistent . Any particular reason why it need to be different ? Application should be doing same irrespective of library being used.

b)Also it does not work if we don't call SonicDBConfig::initializeGlobalConfig.
DBConnector Constructor with particular asic namespace gives seg fault
as SonicDBConfig::getDbId will fail since m_init will be set when call for host/global namespace and when next time called
it will not go for else condition (since m_init is already set)

Yes @abdosi we don't fail now if we the database_global.json is not present

getContext()->unix_sock.path,
timeout);
ret->m_dbName = m_dbName;
ret = new DBConnector(getDbName(), timeout, (getContext()->connection_type == REDIS_CONN_TCP), getNamespace());
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There was a failure I was debugging in sonic-swss/tests/mock_tests, even with the change in the PR where we do constructor delegation.

The reason being in this line 418, when we create a newDBConnector we call the DBConnector API with namespace argument. Since we don't define DBConnector() constructor with the namespace argument in the sonic-swss/tests/mock_tests/mock_dbconnector.cpp .. it come to this actual non-mocked handler and fails .

make[3]: Entering directory '/sonic/src/sonic-swss/tests/mock_tests'
make[4]: Entering directory '/sonic/src/sonic-swss/tests/mock_tests'
../../config/test-driver: line 107: 12950 Aborted                 (core dumped) "$@" > $log_file 2>&1
FAIL: tests
============================================================================
Testsuite summary for sonic-swss 1.0
============================================================================
# TOTAL: 1
# PASS:  0
# SKIP:  0
# XFAIL: 0
# FAIL:  1
# XPASS: 0
# ERROR: 0
terminate called after throwing an instance of 'std::system_error'
  what():  Unable to connect to redis: Cannot assign requested address
FAIL tests (exit status: 134)

Two options to fix this

  1. Add the fix Update DBConnector definition in mock_dbconnector.cpp sonic-swss#1362. Though there are tests failing in swss, they are not related.

  2. Other option is to revert this function DBConnector::newConnector(unsigned int timeout) , to as it was before (https://github.com/Azure/sonic-swss-common/blob/00bcd1d0acfdb1fd33362beafaf41ea3f5c301aa/common/dbconnector.cpp#L243). So this API won't support the usage of namespace for now , can add it back later.

@abdosi
Copy link
Contributor

abdosi commented Aug 11, 2020

can you update submodule ? is it still blocked on sonic-swss ?

@abdosi abdosi deleted the db_connect_NS branch August 11, 2020 15:41
@judyjoseph
Copy link
Collaborator Author

can you update submodule ? is it still blocked on sonic-swss ?

Yes there is still a VS PR build failure .. though locally build went fine with the changes. To look at why the PR build fails

judyjoseph added a commit that referenced this pull request Aug 12, 2020
judyjoseph added a commit that referenced this pull request Aug 12, 2020
@@ -60,12 +79,14 @@ class DBConnector
DBConnector(int dbId, const std::string &hostname, int port, unsigned int timeout);
DBConnector(int dbId, const std::string &unixPath, unsigned int timeout);
DBConnector(const std::string &dbName, unsigned int timeout, bool isTcpConn = false);
DBConnector(const std::string &dbName, unsigned int timeout, bool isTcpConn, const std::string &nameSpace);
Copy link
Contributor

Choose a reason for hiding this comment

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

nameSpace [](start = 100, length = 9)

nameSpace -> namespace

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Qi cannot use namespace as this is a C++ keyword. may be namespaceName or name_space ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks! how about netns ?

@judyjoseph judyjoseph restored the db_connect_NS branch August 14, 2020 16:00
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.

3 participants