]> git.proxmox.com Git - mirror_ovs.git/blobdiff - ovsdb/replication.c
vconn: Allow timeout configuration for blocking connection.
[mirror_ovs.git] / ovsdb / replication.c
index 47b0af19bbf6720f29c8ab40c3028578cad769ec..752b3c89c5f6a1e1b1c6e0cdfe4d6cfcbbbbcd47 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * (c) Copyright 2016 Hewlett Packard Enterprise Development LP
+ * (c) Copyright 2016, 2017 Hewlett Packard Enterprise Development LP
  * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2016, 2017 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -118,10 +118,9 @@ replication_init(const char *sync_from_, const char *exclude_tables,
 {
     free(sync_from);
     sync_from = xstrdup(sync_from_);
-    char *err = set_blacklist_tables(exclude_tables, false);
     /* Caller should have verified that the 'exclude_tables' is
      * parseable. An error here is unexpected. */
-    ovs_assert(!err);
+    ovs_assert(!set_blacklist_tables(exclude_tables, false));
 
     replication_dbs_destroy();
 
@@ -148,8 +147,8 @@ replication_add_local_db(const char *database, struct ovsdb *db)
 static void
 send_schema_requests(const struct json *result)
 {
-    for (size_t i = 0; i < result->u.array.n; i++) {
-        const struct json *name = result->u.array.elems[i];
+    for (size_t i = 0; i < result->array.n; i++) {
+        const struct json *name = result->array.elems[i];
         if (name->type == JSON_STRING) {
             /* Send one schema request for each remote DB. */
             const char *db_name = json_string(name);
@@ -204,13 +203,13 @@ replication_run(void)
         if (msg->type == JSONRPC_NOTIFY && state != RPL_S_ERR
             && !strcmp(msg->method, "update")) {
             if (msg->params->type == JSON_ARRAY
-                && msg->params->u.array.n == 2
-                && msg->params->u.array.elems[0]->type == JSON_STRING) {
-                char *db_name = msg->params->u.array.elems[0]->u.string;
+                && msg->params->array.n == 2
+                && msg->params->array.elems[0]->type == JSON_STRING) {
+                char *db_name = msg->params->array.elems[0]->string;
                 struct ovsdb *db = find_db(db_name);
                 if (db) {
                     struct ovsdb_error *error;
-                    error = process_notification(msg->params->u.array.elems[1],
+                    error = process_notification(msg->params->array.elems[1],
                                                  db);
                     if (error) {
                         ovsdb_error_assert(error);
@@ -300,19 +299,7 @@ replication_run(void)
                 /* After receiving schemas, reset the local databases that
                  * will be monitored and send out monitor requests for them. */
                 if (hmap_is_empty(&request_ids)) {
-                    struct shash_node *node, *next;
-
-                    SHASH_FOR_EACH_SAFE (node, next, replication_dbs) {
-                        db = node->data;
-                        error = reset_database(db);
-                        if (error) {
-                            const char *db_name = db->schema->name;
-                            shash_find_and_delete(replication_dbs, db_name);
-                            ovsdb_error_assert(error);
-                            VLOG_WARN("Failed to reset database, "
-                                      "%s not replicated.", db_name);
-                        }
-                    }
+                    struct shash_node *node;
 
                     if (shash_is_empty(replication_dbs)) {
                         VLOG_WARN("Nothing to replicate.");
@@ -336,7 +323,16 @@ replication_run(void)
             case RPL_S_MONITOR_REQUESTED: {
                 /* Reply to monitor requests. */
                 struct ovsdb_error *error;
-                error = process_notification(msg->result, db);
+                VLOG_INFO("Monitor request received. Resetting the database");
+                /* Resetting the database here has few risks. If the
+                 * process_notification() fails, the database is completely
+                 * lost locally. In case that node becomes active, then
+                 * there is a chance of complete data loss in the active/standy
+                 * cluster. */
+                error = reset_database(db);
+                if (!error) {
+                    error = process_notification(msg->result, db);
+                }
                 if (error) {
                     ovsdb_error_assert(error);
                     state = RPL_S_ERR;
@@ -536,7 +532,7 @@ reset_database(struct ovsdb *db)
         }
     }
 
-    return ovsdb_txn_commit(txn, false);
+    return ovsdb_txn_propose_commit_block(txn, false);
 }
 
 /* Create a monitor request for 'db'. The monitor request will include
@@ -615,7 +611,7 @@ process_notification(struct json *table_updates, struct ovsdb *db)
             return error;
         } else {
             /* Commit transaction. */
-            error = ovsdb_txn_commit(txn, false);
+            error = ovsdb_txn_propose_commit_block(txn, false);
         }
     }
 
@@ -874,7 +870,6 @@ replication_status(void)
             break;
         default:
             OVS_NOT_REACHED();
-            break;
         }
     } else {
         ds_put_format(&ds, "not connected to %s", sync_from);