1818
1919namespace swss {
2020
21- # define DEFAULT_TABLE_NAME_SEPARATOR " : "
22- # define CONFIGDB_TABLE_NAME_SEPARATOR " | "
21+ // Mapping of DB ID to table name separator string
22+ typedef std::map< int , std::string> TableNameSeparatorMap;
2323
2424typedef std::pair<std::string, std::string> FieldValueTuple;
2525#define fvField std::get<0 >
@@ -34,17 +34,26 @@ typedef std::map<std::string,TableMap> TableDump;
3434
3535class TableBase {
3636public:
37- TableBase (std::string tableName , std::string tableSeparator = DEFAULT_TABLE_NAME_SEPARATOR )
38- : m_tableName(tableName), m_tableSeparator(tableSeparator)
37+ TableBase (int dbId , std::string tableName )
38+ : m_tableName(tableName)
3939 {
40- const std::string legalSeparators = " :|" ;
41- if (legalSeparators.find (tableSeparator) == std::string::npos)
42- throw std::invalid_argument (" Invalid table name separator" );
40+ /* Look up table separator for the provided DB */
41+ auto it = tableNameSeparatorMap.find (dbId);
42+
43+ if (it != tableNameSeparatorMap.end ())
44+ {
45+ m_tableSeparator = it->second ;
46+ }
47+ else
48+ {
49+ SWSS_LOG_NOTICE (" Unrecognized database ID. Using default table name separator ('%s')" , TABLE_NAME_SEPARATOR_VBAR.c_str ());
50+ m_tableSeparator = TABLE_NAME_SEPARATOR_VBAR;
51+ }
4352 }
4453
4554 std::string getTableName () const { return m_tableName; }
4655
47- /* Return the actual key name as a comibation of tableName: key */
56+ /* Return the actual key name as a combination of tableName<table_separator> key */
4857 std::string getKeyName (std::string key)
4958 {
5059 if (key == " " ) return m_tableName;
@@ -59,6 +68,10 @@ class TableBase {
5968
6069 std::string getChannelName () { return m_tableName + " _CHANNEL" ; }
6170private:
71+ static const std::string TABLE_NAME_SEPARATOR_COLON;
72+ static const std::string TABLE_NAME_SEPARATOR_VBAR;
73+ static const TableNameSeparatorMap tableNameSeparatorMap;
74+
6275 std::string m_tableName;
6376 std::string m_tableSeparator;
6477};
@@ -95,7 +108,7 @@ class TableConsumable : public TableBase, public TableEntryPoppable, public Redi
95108 /* The default value of pop batch size is 128 */
96109 static constexpr int DEFAULT_POP_BATCH_SIZE = 128 ;
97110
98- TableConsumable (std::string tableName) : TableBase(tableName) { }
111+ TableConsumable (int dbId, std::string tableName) : TableBase(dbId, tableName) { }
99112};
100113
101114class TableEntryEnumerable {
@@ -115,8 +128,8 @@ class TableEntryEnumerable {
115128
116129class Table : public TableBase , public TableEntryEnumerable {
117130public:
118- Table (DBConnector *db, std::string tableName, std::string tableSeparator = DEFAULT_TABLE_NAME_SEPARATOR );
119- Table (RedisPipeline *pipeline, std::string tableName, std::string tableSeparator, bool buffered);
131+ Table (DBConnector *db, std::string tableName);
132+ Table (RedisPipeline *pipeline, std::string tableName, bool buffered);
120133 virtual ~Table ();
121134
122135 /* Set an entry in the DB directly (op not in use) */
0 commit comments