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

Add map of database ID -> table name separator; No longer pass table name separator when constructing Table objects #190

Merged
merged 8 commits into from
Apr 10, 2018

Conversation

jleveque
Copy link
Contributor

Previously, SubscriberStateTable was hardcoded to use CONFIGDB_TABLE_NAME_SEPARATOR, which meant that one could only subscribe to notifications from databases which used "|" as a table name separator. If you subscribed to a database which used ":" as a table name separator, you would never receive notifications.

This change creates a constant map of database ID to table name separator, and chooses the appropriate table name separator for a table based on the DB one is connecting to. While fixing the above problem, I also simplified the method calls for instantiating Table objects, as one no longer needs to pass in the table separator. This will also prevent table name separator mismatches in the future.

Also changed name of DEFAULT_TABLE_NAME_SEPARATOR to LEGACY_TABLE_NAME_SEPARATOR and CONFIGDB_TABLE_NAME_SEPARATOR to NEW_TABLE_NAME_SEPARATOR

Also define TEST_DB at index 15, the largest index supported by default Redis config, for use in unit tests.

NOTE: This PR will require related changes in sonic-swss, sonic-sairedis and sonic-buildimage repos. I will submit those PRs shortly.

@qiluo-msft
Copy link
Contributor

qiluo-msft commented Mar 22, 2018

Please check the unit test failure. #Closed

@@ -92,6 +92,11 @@ class RedisPipeline {
return m_remaining;
}

DBConnector *getDbConnector()
Copy link
Contributor

@qiluo-msft qiluo-msft Mar 22, 2018

Choose a reason for hiding this comment

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

getDbConnector [](start = 17, length = 14)

The m_db is for internal use by design. It is carefully appended and popped to make pipeline working. Do not let outside use interleaves with internal use. #Closed

Copy link
Contributor Author

@jleveque jleveque Mar 23, 2018

Choose a reason for hiding this comment

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

Latest commit now exposes the DB ID of m_db, not m_db itself. #Closed

Copy link
Contributor

Choose a reason for hiding this comment

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

m_db should never be NULL. you may use assert, if you want.


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

Copy link
Contributor Author

@jleveque jleveque Mar 23, 2018

Choose a reason for hiding this comment

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

Removed NULL check. #Closed

common/schema.h Outdated
@@ -13,6 +13,7 @@ namespace swss {
#define PFC_WD_DB 5
#define FLEX_COUNTER_DB 5
#define STATE_DB 6
#define TEST_DB 15
Copy link
Contributor

@qiluo-msft qiluo-msft Mar 22, 2018

Choose a reason for hiding this comment

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

15 [](start = 24, length = 2)

Is there a redis constant we could refer? #Closed

Copy link
Contributor Author

@jleveque jleveque Mar 23, 2018

Choose a reason for hiding this comment

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

No constant that I could find, but I found that you can query the number of databases using the CONFIG GET databases command:

# redis-cli CONFIG GET databases
1) "databases"
2) "16"

However, with this info, we can't define a constant like TEST_DB. We would need a getter method which returns the test DB id as (num_databases -1).

I still believe defining TEST_DB here with the other DB IDs is an improvement over the previous solution of #define TEST_VIEW (7) in tests/redis_ut.cpp. Having to remember to increment that value when adding a new DB is onerous.

Copy link
Contributor

Choose a reason for hiding this comment

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

Originally TEST_VIEW is only used in unit test. So please leave any related constant there.


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

Copy link
Contributor Author

@jleveque jleveque Mar 23, 2018

Choose a reason for hiding this comment

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

It needs to be known here because it needs to be included in the table name separator map. Otherwise, the TableBase constructor will throw an exception, unless we simply use an existing DB ID for unit tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

As we discussed, other developers may need the freedom to experiment in new DB id without it's allocated formally in swss-common library. So the requirement for out-of-range DB id should be supported.

common/table.h Outdated
#define DEFAULT_TABLE_NAME_SEPARATOR ":"
#define CONFIGDB_TABLE_NAME_SEPARATOR "|"
#define LEGACY_TABLE_NAME_SEPARATOR ":"
#define NEW_TABLE_NAME_SEPARATOR "|"
Copy link
Contributor

@qiluo-msft qiluo-msft Mar 22, 2018

Choose a reason for hiding this comment

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

NEW_TABLE_NAME_SEPARATOR [](start = 8, length = 24)

NEW_ is not a good prefix for long term project. How about SAFE_TABLE_NAME_SEPARATOR, or DEFAULT_ if it is default for future. #Closed

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest to move into class constant member, and add a getter function.


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

common/table.h Outdated
@@ -18,8 +18,11 @@

namespace swss {

#define DEFAULT_TABLE_NAME_SEPARATOR ":"
#define CONFIGDB_TABLE_NAME_SEPARATOR "|"
#define LEGACY_TABLE_NAME_SEPARATOR ":"
Copy link
Contributor

@qiluo-msft qiluo-msft Mar 22, 2018

Choose a reason for hiding this comment

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

LEGACY_TABLE_NAME_SEPARATOR [](start = 8, length = 27)

Is it possible to migrate from legacy to new completely? How much effort needed? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree we should migrate completely to using only one separator (new) everywhere. I'm not sure of the total amount of work required for that. This is a question for @lguohan.

However, the changes I've made in this PR will help make that transition easier, by greatly reducing the number of references that will need to be updated.

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.

common/table.h Outdated
#define NEW_TABLE_NAME_SEPARATOR "|"

// Mapping of DB ID to table name separator string
typedef std::map<int, std::string> TableNameSeparatorMap;
Copy link
Contributor

@qiluo-msft qiluo-msft Mar 23, 2018

Choose a reason for hiding this comment

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

TableNameSeparatorMap [](start = 35, length = 21)

suggest to keep it as a class private member. #Closed

@kcudnik
Copy link
Contributor

kcudnik commented Mar 23, 2018

This will probably break a lot of stuff in sairedis since sairedis is using hardcoded table separator also, but as string, for example "Table:*" when its lists all the tables, and it may be not easy task to fix all those places
maybe tests will catch some of those which will be used

@jleveque
Copy link
Contributor Author

@kcudnik: This PR shouldn't cause any issues with existing hardcoded strings containing a colon as a separator (like Table:*), as I haven't changed which DBs use which separators. However, those will be an issue once we decide to change all separators across all DBs to use the pipe character instead. It sounds like that will be a big job.

FYI, there was only one reference in sairedis that explicitly referenced DEFAULT_TABLE_NAME_SEPARATOR, and I have removed that to work with this PR here: https://github.com/Azure/sonic-sairedis/pull/309/files

@@ -35,7 +35,7 @@ class DBConnector

private:
redisContext *m_conn;
int m_db;
int m_id;
Copy link
Contributor

Choose a reason for hiding this comment

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

rename it as m_dbid to align with your function name getDbId()

common/table.cpp Outdated
Table::Table(DBConnector *db, string tableName, string tableSeparator)
: Table(new RedisPipeline(db, 1), tableName, tableSeparator, false)
const std::string TableBase::LEGACY_TABLE_NAME_SEPARATOR = ":";
const std::string TableBase::NEW_TABLE_NAME_SEPARATOR = "|";
Copy link
Contributor

Choose a reason for hiding this comment

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

We do not need classify them as legacy or new, can we use TABLE_NAME_SEPARATOR_COLON, TABLE_NAME_SEPARATOR_VBAR. We can add comments to to say we are going to deprecate the COLON separator.

@lguohan
Copy link
Contributor

lguohan commented Mar 24, 2018

how do you plan to deal with swsssdk the python version? If we incorporate your changes, do we need any change in swsssdk or we are good?

@lguohan
Copy link
Contributor

lguohan commented Mar 24, 2018

I think it is better merge this after March release.

@lguohan
Copy link
Contributor

lguohan commented Mar 24, 2018

in current db, do we have cases that use different separator in one table db? If not, i think this approach is ok.

Copy link
Contributor

@lguohan lguohan 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.

@jleveque
Copy link
Contributor Author

jleveque commented Mar 26, 2018

@lguohan:

how do you plan to deal with swsssdk the python version? If we incorporate your changes, do we need any change in swsssdk or we are good?

This change should have no impact on swsssdk, as swsssdk doesn't reference swss-common. It uses the Python Redis library directly, and thus is completely independent of swss-common.

However, this change will make it possible to use the new Python bindings of swss-common everywhere we currently use swsssdk, effectively allowing us to deprecate and eventually remove swsssdk altogether.

in current db, do we have cases that use different separator in one table db? If not, i think this approach is ok.

From my investigation, it appears as though there is no mixing of separators within any DBs. Each database consistently uses only one separator.

@jleveque jleveque merged commit 8213777 into sonic-net:master Apr 10, 2018
@jleveque jleveque deleted the table_name_separators branch April 10, 2018 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants