-
Notifications
You must be signed in to change notification settings - Fork 291
Add map of database ID -> table name separator; No longer pass table name separator when constructing Table objects #190
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
Changes from 6 commits
d5e438f
89c6c72
fcac4e2
81dfbb0
b47ace8
b248e96
c42167a
5247f13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,14 +12,28 @@ using namespace std; | |
using namespace swss; | ||
using json = nlohmann::json; | ||
|
||
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. Choose a reason for hiding this commentThe 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. |
||
|
||
const TableNameSeparatorMap TableBase::tableNameSeparatorMap = { | ||
{ APPL_DB, LEGACY_TABLE_NAME_SEPARATOR }, | ||
{ ASIC_DB, LEGACY_TABLE_NAME_SEPARATOR }, | ||
{ COUNTERS_DB, LEGACY_TABLE_NAME_SEPARATOR }, | ||
{ LOGLEVEL_DB, LEGACY_TABLE_NAME_SEPARATOR }, | ||
{ CONFIG_DB, NEW_TABLE_NAME_SEPARATOR }, | ||
{ PFC_WD_DB, LEGACY_TABLE_NAME_SEPARATOR }, | ||
{ FLEX_COUNTER_DB, LEGACY_TABLE_NAME_SEPARATOR }, | ||
{ STATE_DB, NEW_TABLE_NAME_SEPARATOR } | ||
}; | ||
|
||
Table::Table(DBConnector *db, string tableName) | ||
: Table(new RedisPipeline(db, 1), tableName, false) | ||
{ | ||
m_pipeowned = true; | ||
} | ||
|
||
Table::Table(RedisPipeline *pipeline, string tableName, string tableSeparator, bool buffered) | ||
: TableBase(tableName, tableSeparator) | ||
Table::Table(RedisPipeline *pipeline, string tableName, bool buffered) | ||
: TableBase(pipeline->getDbId(), tableName) | ||
, m_buffered(buffered) | ||
, m_pipeowned(false) | ||
, m_pipe(pipeline) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,8 @@ | |
|
||
namespace swss { | ||
|
||
#define DEFAULT_TABLE_NAME_SEPARATOR ":" | ||
#define CONFIGDB_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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
suggest to keep it as a class private member. #Closed |
||
|
||
typedef std::pair<std::string, std::string> FieldValueTuple; | ||
#define fvField std::get<0> | ||
|
@@ -34,17 +34,26 @@ typedef std::map<std::string,TableMap> TableDump; | |
|
||
class TableBase { | ||
public: | ||
TableBase(std::string tableName, std::string tableSeparator = DEFAULT_TABLE_NAME_SEPARATOR) | ||
: m_tableName(tableName), m_tableSeparator(tableSeparator) | ||
TableBase(int dbId, std::string tableName) | ||
: m_tableName(tableName) | ||
{ | ||
const std::string legalSeparators = ":|"; | ||
if (legalSeparators.find(tableSeparator) == std::string::npos) | ||
throw std::invalid_argument("Invalid table name separator"); | ||
/* Look up table separator for the provided DB */ | ||
auto it = tableNameSeparatorMap.find(dbId); | ||
|
||
if (it != tableNameSeparatorMap.end()) | ||
{ | ||
m_tableSeparator = it->second; | ||
} | ||
else | ||
{ | ||
SWSS_LOG_NOTICE("Unrecognized database ID. Using default table name separator ('%s')", NEW_TABLE_NAME_SEPARATOR.c_str()); | ||
m_tableSeparator = NEW_TABLE_NAME_SEPARATOR; | ||
} | ||
} | ||
|
||
std::string getTableName() const { return m_tableName; } | ||
|
||
/* Return the actual key name as a comibation of tableName:key */ | ||
/* Return the actual key name as a combination of tableName<table_separator>key */ | ||
std::string getKeyName(std::string key) | ||
{ | ||
if (key == "") return m_tableName; | ||
|
@@ -59,6 +68,10 @@ class TableBase { | |
|
||
std::string getChannelName() { return m_tableName + "_CHANNEL"; } | ||
private: | ||
static const std::string LEGACY_TABLE_NAME_SEPARATOR; | ||
static const std::string NEW_TABLE_NAME_SEPARATOR; | ||
static const TableNameSeparatorMap tableNameSeparatorMap; | ||
|
||
std::string m_tableName; | ||
std::string m_tableSeparator; | ||
}; | ||
|
@@ -95,7 +108,7 @@ class TableConsumable : public TableBase, public TableEntryPoppable, public Redi | |
/* The default value of pop batch size is 128 */ | ||
static constexpr int DEFAULT_POP_BATCH_SIZE = 128; | ||
|
||
TableConsumable(std::string tableName) : TableBase(tableName) { } | ||
TableConsumable(int dbId, std::string tableName) : TableBase(dbId, tableName) { } | ||
}; | ||
|
||
class TableEntryEnumerable { | ||
|
@@ -115,8 +128,8 @@ class TableEntryEnumerable { | |
|
||
class Table : public TableBase, public TableEntryEnumerable { | ||
public: | ||
Table(DBConnector *db, std::string tableName, std::string tableSeparator = DEFAULT_TABLE_NAME_SEPARATOR); | ||
Table(RedisPipeline *pipeline, std::string tableName, std::string tableSeparator, bool buffered); | ||
Table(DBConnector *db, std::string tableName); | ||
Table(RedisPipeline *pipeline, std::string tableName, bool buffered); | ||
virtual ~Table(); | ||
|
||
/* Set an entry in the DB directly (op not in use) */ | ||
|
There was a problem hiding this comment.
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()