[ovs-dev] [replication SMv2 3/7] ovsdb: Add request_ids

Ben Pfaff blp at ovn.org
Tue Aug 30 21:07:00 UTC 2016


On Fri, Aug 26, 2016 at 04:15:50PM -0700, Andy Zhou wrote:
> When starting, the replication logic may issue multiple requests at
> a time, for example, one monitor request for each databases. The
> request_ids keeps track of all outsanding request IDs that are used
> for matching reply message with. It also provides the 'db' context
> for the reply.
> 
> Future patches will make use of this facility.
> 
> Signed-off-by: Andy Zhou <azhou at ovn.org>

Seems like useful infrastructure, thanks.

Acked-by: Ben Pfaff <blp at ovn.org>

I have the following suggestions.

--8<--------------------------cut here-------------------------->8--

diff --git a/ovsdb/replication.c b/ovsdb/replication.c
index 815730d..0445221 100644
--- a/ovsdb/replication.c
+++ b/ovsdb/replication.c
@@ -789,16 +789,17 @@ request_ids_add(const struct json *id, struct ovsdb *db)
 
 /* Look up 'id' from 'request_ids', if found, remove the found id from
  * 'request_ids' and free its memory. If not found, 'request_ids' does
- * not change.  '*db' is only valid when return true.
+ * not change.  Sets '*db' to the database for the request (NULL if not
+ * found).
  *
- * Return ture if 'id' is found. False otherwise.
+ * Return true if 'id' is found, false otherwise.
  */
 bool
 request_ids_lookup_and_free(const struct json *id, struct ovsdb **db)
 {
     struct request_ids_hmap_node *node;
 
-    HMAP_FOR_EACH_IN_BUCKET (node, hmap, json_hash(id, 0), &request_ids) {
+    HMAP_FOR_EACH_WITH_HASH (node, hmap, json_hash(id, 0), &request_ids) {
         if (json_equal(id, node->request_id)) {
             hmap_remove(&request_ids, &node->hmap);
             *db = node->db;
@@ -808,6 +809,7 @@ request_ids_lookup_and_free(const struct json *id, struct ovsdb **db)
         }
     }
 
+    *db = NULL;
     return false;
 }
 
@@ -826,13 +828,7 @@ request_ids_destroy(void)
 void
 request_ids_clear(void)
 {
-    struct request_ids_hmap_node *node;
-
-    HMAP_FOR_EACH_POP (node, hmap, &request_ids) {
-        json_destroy(node->request_id);
-        free(node);
-    }
-    hmap_destroy(&request_ids);
+    request_ids_destroy();
     hmap_init(&request_ids);
 }
 



More information about the dev mailing list