X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=lib%2Fovsdb-idl.c;h=fd15ea96f3f13103431ecdfeeda55720ca26e1d9;hb=c8544aa15f8811e9d6329d4a5e612ff7acb926c9;hp=df5aff52960217ddea1edd41dd7d3b81b61349de;hpb=ee21cfa751d9233a686d1a1c0c7ee6a3d6dac651;p=openvswitch diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index df5aff52..fd15ea96 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009, 2010 Nicira Networks. +/* Copyright (c) 2009, 2010, 2011 Nicira Networks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -282,7 +282,7 @@ ovsdb_idl_run(struct ovsdb_idl *idl) assert(!idl->txn); jsonrpc_session_run(idl->session); for (i = 0; jsonrpc_session_is_connected(idl->session) && i < 50; i++) { - struct jsonrpc_msg *msg, *reply; + struct jsonrpc_msg *msg; unsigned int seqno; seqno = jsonrpc_session_get_seqno(idl->session); @@ -298,7 +298,6 @@ ovsdb_idl_run(struct ovsdb_idl *idl) break; } - reply = NULL; if (msg->type == JSONRPC_NOTIFY && !strcmp(msg->method, "update") && msg->params->type == JSON_ARRAY @@ -313,8 +312,7 @@ ovsdb_idl_run(struct ovsdb_idl *idl) idl->monitor_request_id = NULL; ovsdb_idl_clear(idl); ovsdb_idl_parse_update(idl, msg->result); - } else if (msg->type == JSONRPC_REPLY - && msg->id && msg->id->type == JSON_STRING + } else if (msg->type == JSONRPC_REPLY && msg->id->type == JSON_STRING && !strcmp(msg->id->u.string, "echo")) { /* It's a reply to our echo request. Ignore it. */ } else if ((msg->type == JSONRPC_ERROR @@ -329,9 +327,6 @@ ovsdb_idl_run(struct ovsdb_idl *idl) jsonrpc_session_get_name(idl->session), jsonrpc_msg_type_to_string(msg->type)); } - if (reply) { - jsonrpc_session_send(idl->session, reply); - } jsonrpc_msg_destroy(msg); } @@ -1113,6 +1108,15 @@ ovsdb_idl_get(const struct ovsdb_idl_row *row, return ovsdb_idl_read(row, column); } + +/* Returns false if 'row' was obtained from the IDL, true if it was initialized + * to all-zero-bits by some other entity. If 'row' was set up some other way + * then the return value is indeterminate. */ +bool +ovsdb_idl_row_is_synthetic(const struct ovsdb_idl_row *row) +{ + return row->table == NULL; +} /* Transactions. */ @@ -1402,12 +1406,16 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn) if (row->old == row->new) { continue; } else if (!row->new) { - struct json *op = json_object_create(); - json_object_put_string(op, "op", "delete"); - json_object_put_string(op, "table", class->name); - json_object_put(op, "where", where_uuid_equals(&row->uuid)); - json_array_add(operations, op); - any_updates = true; + if (class->is_root) { + struct json *op = json_object_create(); + json_object_put_string(op, "op", "delete"); + json_object_put_string(op, "table", class->name); + json_object_put(op, "where", where_uuid_equals(&row->uuid)); + json_array_add(operations, op); + any_updates = true; + } else { + /* Let ovsdb-server decide whether to really delete it. */ + } } else { struct json *row_json; struct json *op; @@ -1441,9 +1449,7 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn) &class->columns[idx]; if (row->old - ? !ovsdb_datum_equals(&row->old[idx], &row->new[idx], - &column->type) - : !ovsdb_datum_is_default(&row->new[idx], + || !ovsdb_datum_is_default(&row->new[idx], &column->type)) { json_object_put(row_json, column->name, substitute_uuids( @@ -1638,6 +1644,21 @@ ovsdb_idl_txn_write(const struct ovsdb_idl_row *row_, assert(row->old == NULL || row->table->modes[column_idx] & OVSDB_IDL_MONITOR); + /* If this is a write-only column and the datum being written is the same + * as the one already there, just skip the update entirely. This is worth + * optimizing because we have a lot of columns that get periodically + * refreshed into the database but don't actually change that often. + * + * We don't do this for read/write columns because that would break + * atomicity of transactions--some other client might have written a + * different value in that column since we read it. */ + if (row->table->modes[column_idx] == OVSDB_IDL_MONITOR + && ovsdb_datum_equals(ovsdb_idl_read(row, column), + datum, &column->type)) { + ovsdb_datum_destroy(datum, &column->type); + return; + } + if (hmap_node_is_null(&row->txn_node)) { hmap_insert(&row->table->idl->txn->txn_rows, &row->txn_node, uuid_hash(&row->uuid));