@@ -1525,6 +1525,7 @@ ovsdb_cs_db_add_update(struct ovsdb_cs_db *db,
struct ovsdb_cs_event *event = ovsdb_cs_db_add_event(
db, OVSDB_CS_EVENT_TYPE_UPDATE);
event->update = (struct ovsdb_cs_update_event) {
+ .last_id = db->last_id,
.table_updates = json_clone(table_updates),
.clear = clear,
.monitor_reply = monitor_reply,
@@ -97,6 +97,7 @@ struct ovsdb_cs_event {
struct ovsdb_cs_update_event {
bool clear;
bool monitor_reply;
+ struct uuid last_id;
struct json *table_updates;
int version;
} update;
@@ -683,6 +683,7 @@ open_db(struct server_config *config, const char *filename)
struct ovsdb_error *error;
bool is_relay;
char *name;
+ bool need_txn_history;
is_relay = !strncmp(filename, relay_prefix, relay_prefix_len);
if (!is_relay) {
@@ -731,7 +732,8 @@ open_db(struct server_config *config, const char *filename)
/* Enable txn history for clustered mode. It is not enabled for other mode
* for now, since txn id is available for clustered mode only. */
- ovsdb_txn_history_init(db->db, ovsdb_storage_is_clustered(storage));
+ need_txn_history = (is_relay || ovsdb_storage_is_clustered(storage));
+ ovsdb_txn_history_init(db->db, need_txn_history);;
read_db(config, db);
@@ -222,7 +222,9 @@ ovsdb_relay_process_row_update(struct ovsdb_table *table,
static struct ovsdb_error *
ovsdb_relay_parse_update__(struct ovsdb *db,
- const struct ovsdb_cs_db_update *du)
+ const struct ovsdb_cs_db_update *du,
+ bool txn_add_to_history,
+ const struct uuid *last_id)
{
struct ovsdb_error *error = NULL;
struct ovsdb_txn *txn;
@@ -254,8 +256,19 @@ exit:
ovsdb_txn_abort(txn);
return error;
} else {
+ /*add transaction to history*/
+ if (txn_add_to_history) {
+ ovsdb_txn_set_txnid(last_id, txn);
+ VLOG_DBG("last_id = "UUID_FMT, UUID_ARGS(last_id));
+ ovsdb_txn_add_to_history(txn);
+ }
+
/* Commit transaction. */
error = ovsdb_txn_propose_commit_block(txn, false);
+ if (error && txn_add_to_history) {
+ VLOG_DBG("remove history");
+ ovsdb_txn_history_remove_back(db);
+ }
}
return error;
@@ -304,7 +317,12 @@ ovsdb_relay_parse_update(struct relay_ctx *ctx,
error = ovsdb_relay_clear(ctx->db);
}
if (!error) {
- error = ovsdb_relay_parse_update__(ctx->db, du);
+ bool txn_add_to_history = false;
+ txn_add_to_history = (update->version == 3
+ && !uuid_is_zero(&update->last_id));
+ error = ovsdb_relay_parse_update__(ctx->db, du,
+ txn_add_to_history,
+ &update->last_id);
}
}
ovsdb_cs_db_update_destroy(du);
@@ -1114,7 +1114,7 @@ ovsdb_txn_destroy_cloned(struct ovsdb_txn *txn)
free(txn);
}
-static void
+void
ovsdb_txn_add_to_history(struct ovsdb_txn *txn)
{
if (txn->db->need_txn_history) {
@@ -1122,7 +1122,20 @@ ovsdb_txn_add_to_history(struct ovsdb_txn *txn)
node->txn = ovsdb_txn_clone(txn);
ovs_list_push_back(&txn->db->txn_history, &node->node);
txn->db->n_txn_history++;
- txn->db->n_txn_history_atoms += txn->n_atoms;
+ }
+}
+
+void
+ovsdb_txn_history_remove_back(struct ovsdb *db)
+{
+ if (db->need_txn_history) {
+ struct ovsdb_txn_history_node *txn_h_node = CONTAINER_OF(
+ ovs_list_pop_back(&db->txn_history),
+ struct ovsdb_txn_history_node, node);
+
+ ovsdb_txn_destroy_cloned(txn_h_node->txn);
+ free(txn_h_node);
+ db->n_txn_history--;
}
}
@@ -68,5 +68,7 @@ const char *ovsdb_txn_get_comment(const struct ovsdb_txn *);
void ovsdb_txn_history_run(struct ovsdb *);
void ovsdb_txn_history_init(struct ovsdb *, bool need_txn_history);
void ovsdb_txn_history_destroy(struct ovsdb *);
+void ovsdb_txn_add_to_history(struct ovsdb_txn *);
+void ovsdb_txn_history_remove_back(struct ovsdb *);
#endif /* ovsdb/transaction.h */
relay server inherit transaction historys from cluster source server Signed-off-by: Wentao Jia <wentao.jia@easystack.cn> --- lib/ovsdb-cs.c | 1 + lib/ovsdb-cs.h | 1 + ovsdb/ovsdb-server.c | 4 +++- ovsdb/relay.c | 22 ++++++++++++++++++++-- ovsdb/transaction.c | 17 +++++++++++++++-- ovsdb/transaction.h | 2 ++ 6 files changed, 42 insertions(+), 5 deletions(-)