MXS-1881: Add TableCreateEvent JSON serialization

Serializing the object allows replicated events to be processed even if
the CREATE TABLE statement is not in the binary logs.
This commit is contained in:
Markus Mäkelä
2018-06-11 20:28:06 +03:00
parent 3417842e75
commit a3a4bb3da6
2 changed files with 110 additions and 1 deletions

View File

@ -66,8 +66,14 @@ struct Column
std::string name;
std::string type;
int length;
json_t* to_json() const;
static Column from_json(json_t* json);
};
struct TableCreateEvent;
typedef std::tr1::shared_ptr<TableCreateEvent> STableCreateEvent;
/** A CREATE TABLE abstraction */
struct TableCreateEvent
{
@ -80,11 +86,32 @@ struct TableCreateEvent
{
}
/**
* Get the table identifier i.e. `database.table`
*
* @return The table identifier
*/
std::string id() const
{
return database + '.' + table;
}
/**
* Convert to JSON
*
* @return JSON representation of this object
*/
json_t* to_json() const;
/**
* Convert from JSON
*
* @param json JSON to convert from
*
* @return Object representation of JSON if it is valid or empty pointer if invalid.
*/
static STableCreateEvent from_json(json_t* json);
std::vector<Column> columns;
std::string table;
std::string database;
@ -124,7 +151,6 @@ struct TableMapEvent
Bytes column_metadata;
};
typedef std::tr1::shared_ptr<TableCreateEvent> STableCreateEvent;
typedef std::tr1::shared_ptr<TableMapEvent> STableMapEvent;
// Containers for the replication events