Add map of database ID -> table name separator; No longer pass table name separator when constructing Table objects#190
Add map of database ID -> table name separator; No longer pass table name separator when constructing Table objects#190jleveque merged 8 commits intosonic-net:masterfrom jleveque:table_name_separators
Conversation
…name separator when constructing table objects
|
Please check the unit test failure. #Closed |
common/redispipeline.h
Outdated
| return m_remaining; | ||
| } | ||
|
|
||
| DBConnector *getDbConnector() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Latest commit now exposes the DB ID of m_db, not m_db itself. #Closed
There was a problem hiding this comment.
m_db should never be NULL. you may use assert, if you want.
In reply to: 176623397 [](ancestors = 176623397)
There was a problem hiding this comment.
Removed NULL check. #Closed
common/schema.h
Outdated
| #define PFC_WD_DB 5 | ||
| #define FLEX_COUNTER_DB 5 | ||
| #define STATE_DB 6 | ||
| #define TEST_DB 15 |
There was a problem hiding this comment.
15 [](start = 24, length = 2)
Is there a redis constant we could refer? #Closed
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Originally TEST_VIEW is only used in unit test. So please leave any related constant there.
In reply to: 176849657 [](ancestors = 176849657)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 "|" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Suggest to move into class constant member, and add a getter function.
In reply to: 176601615 [](ancestors = 176601615)
common/table.h
Outdated
|
|
||
| #define DEFAULT_TABLE_NAME_SEPARATOR ":" | ||
| #define CONFIGDB_TABLE_NAME_SEPARATOR "|" | ||
| #define LEGACY_TABLE_NAME_SEPARATOR ":" |
There was a problem hiding this comment.
LEGACY_TABLE_NAME_SEPARATOR [](start = 8, length = 27)
Is it possible to migrate from legacy to new completely? How much effort needed? #Closed
There was a problem hiding this comment.
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.
| #define NEW_TABLE_NAME_SEPARATOR "|" | ||
|
|
||
| // Mapping of DB ID to table name separator string | ||
| typedef std::map<int, std::string> TableNameSeparatorMap; |
There was a problem hiding this comment.
TableNameSeparatorMap [](start = 35, length = 21)
suggest to keep it as a class private member. #Closed
|
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 |
|
@kcudnik: This PR shouldn't cause any issues with existing hardcoded strings containing a colon as a separator (like FYI, there was only one reference in sairedis that explicitly referenced |
common/dbconnector.h
Outdated
| private: | ||
| redisContext *m_conn; | ||
| int m_db; | ||
| int m_id; |
There was a problem hiding this comment.
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 = "|"; |
There was a problem hiding this comment.
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.
|
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? |
|
I think it is better merge this after March release. |
|
in current db, do we have cases that use different separator in one table db? If not, i think this approach is ok. |
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.
From my investigation, it appears as though there is no mixing of separators within any DBs. Each database consistently uses only one separator. |
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_SEPARATORtoLEGACY_TABLE_NAME_SEPARATORandCONFIGDB_TABLE_NAME_SEPARATORtoNEW_TABLE_NAME_SEPARATORAlso define
TEST_DBat 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.