summaryrefslogtreecommitdiff
path: root/ovsdb/execution.c
Commit message (Collapse)AuthorAgeFilesLines
* ovsdb: relay: Add support for transaction forwarding.Ilya Maximets2021-07-151-8/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Current version of ovsdb relay allows to scale out read-only access to the primary database. However, many clients are not read-only but read-mostly. For example, ovn-controller. In order to scale out database access for this case ovsdb-server need to process transactions that are not read-only. Relay is not allowed to do that, i.e. not allowed to modify the database, but it can act like a proxy and forward transactions that includes database modifications to the primary server and forward replies back to a client. At the same time it may serve read-only transactions and monitor requests by itself greatly reducing the load on primary server. This configuration will slightly increase transaction latency, but it's not very important for read-mostly use cases. Implementation details: With this change instead of creating a trigger to commit the transaction, ovsdb-server will create a trigger for transaction forwarding. Later, ovsdb_relay_run() will send all new transactions to the relay source. Once transaction reply received from the relay source, ovsdb-relay module will update the state of the transaction forwarding with the reply. After that, trigger_run() will complete the trigger and jsonrpc_server_run() will send the reply back to the client. Since transaction reply from the relay source will be received after all the updates, client will receive all the updates before receiving the transaction reply as it is in a normal scenario with other database models. Acked-by: Mark D. Gray <mark.d.gray@redhat.com> Acked-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* ovsdb: New ovsdb 'relay' service model.Ilya Maximets2021-07-151-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | New database service model 'relay' that is needed to scale out read-mostly database access, e.g. ovn-controller connections to OVN_Southbound. In this service model ovsdb-server connects to existing OVSDB server and maintains in-memory copy of the database. It serves read-only transactions and monitor requests by its own, but forwards write transactions to the relay source. Key differences from the active-backup replication: - support for "write" transactions (next commit). - no on-disk storage. (probably, faster operation) - support for multiple remotes (connect to the clustered db). - doesn't try to keep connection as long as possible, but faster reconnects to other remotes to avoid missing updates. - No need to know the complete database schema beforehand, only the schema name. - can be used along with other standalone and clustered databases by the same ovsdb-server process. (doesn't turn the whole jsonrpc server to read-only mode) - supports modern version of monitors (monitor_cond_since), because based on ovsdb-cs. - could be chained, i.e. multiple relays could be connected one to another in a row or in a tree-like form. - doesn't increase availability. - cannot be converted to other service models or become a main active server. Some performance test results can be found here: https://mail.openvswitch.org/pipermail/ovs-dev/2021-July/385825.html Acked-by: Mark D. Gray <mark.d.gray@redhat.com> Acked-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* ovsdb: row: Add support for xor-based row updates.Ilya Maximets2021-07-151-2/+3
| | | | | | | | | | | | This will be used to apply update3 type updates to ovsdb tables while processing updates for future ovsdb 'relay' service model. 'ovsdb_datum_apply_diff' is allowed to fail, so adding support to return this error. Acked-by: Mark D. Gray <mark.d.gray@redhat.com> Acked-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* ovsdb: Fix timeout type for wait operation.Ilya Maximets2020-06-011-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | According to RFC 7047, 'timeout' is an integer field: 5.2.6. Wait The "wait" object contains the following members: "op": "wait" required "timeout": <integer> optional ... For some reason initial implementation treated it as a real number. This causes a build issue with clang that complains that LLONG_MAX could not be represented as double: ovsdb/execution.c:733:32: error: implicit conversion from 'long long' to 'double' changes value from 9223372036854775807 to 9223372036854775808 timeout_msec = MIN(LLONG_MAX, json_real(timeout)); ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/sys/limits.h:69:19: note: expanded from macro 'LLONG_MAX' #define LLONG_MAX __LLONG_MAX /* max for a long long */ ^~~~~~~~~~~ /usr/include/x86/_limits.h:74:21: note: expanded from macro '__LLONG_MAX' #define __LLONG_MAX 0x7fffffffffffffffLL /* max value for a long long */ ^~~~~~~~~~~~~~~~~~~~ ./lib/util.h:90:21: note: expanded from macro 'MIN' #define MIN(X, Y) ((X) < (Y) ? (X) : (Y)) ^ ~ Fix that by changing parser to treat 'timeout' as integer. Fixes clang build on FreeBSD 12.1 in CirrusCI. Fixes: f85f8ebbfac9 ("Initial implementation of OVSDB.") Acked-by: Han Zhou <hzhou@ovn.org> Acked-by: Numan Siddique <numans@ovn.org> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* ovsdb-server: Allow OVSDB clients to specify the UUID for inserted rows.Ben Pfaff2020-01-161-4/+22
| | | | | | Acked-by: Han Zhou <hzhou@ovn.org> Requested-by: Leonid Ryzhyk <lryzhyk@vmware.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* ovsdb-execute: Remove unused variable from ovsdb_execute_mutate().Damijan Skvarc2019-10-301-2/+0
| | | | | Signed-off-by: Damijan Skvarc <damjan.skvarc@gmail.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Embrace anonymous unions.Ben Pfaff2018-05-251-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Several OVS structs contain embedded named unions, like this: struct { ... union { ... } u; }; C11 standardized a feature that many compilers already implemented anyway, where an embedded union may be unnamed, like this: struct { ... union { ... }; }; This is more convenient because it allows the programmer to omit "u." in many places. OVS already used this feature in several places. This commit embraces it in several others. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Justin Pettit <jpettit@ovn.org> Tested-by: Alin Gabriel Serdean <aserdean@ovn.org> Acked-by: Alin Gabriel Serdean <aserdean@ovn.org>
* ovsdb: Introduce experimental support for clustered databases.Ben Pfaff2018-03-241-35/+60
| | | | | | | | | | | | | | | | | | | This commit adds support for OVSDB clustering via Raft. Please read ovsdb(7) for information on how to set up a clustered database. It is simple and boils down to running "ovsdb-tool create-cluster" on one server and "ovsdb-tool join-cluster" on each of the others and then starting ovsdb-server in the usual way on all of them. One you have a clustered database, you configure ovn-controller and ovn-northd to use it by pointing them to all of the servers, e.g. where previously you might have said "tcp:1.2.3.4" was the database server, now you say that it is "tcp:1.2.3.4,tcp:5.6.7.8,tcp:9.10.11.12". This also adds support for database clustering to ovs-sandbox. Acked-by: Justin Pettit <jpettit@ovn.org> Tested-by: aginwala <aginwala@asu.edu> Signed-off-by: Ben Pfaff <blp@ovn.org>
* ovsdb-server: Forbid user-specified databases with reserved names.Ben Pfaff2017-12-221-5/+12
| | | | | | | | | | | | | | Names that begin with "_" are reserved, but ovsdb-server didn't previously enforce this. At the same time, make ovsdb-client ignore databases with reserved names for the purpose of selecting a default database to work on. This is in preparation for ovsdb-server starting to serve a new database, full of meta-information, called _Server. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Justin Pettit <jpettit@ovn.org>
* ovsdb-error: New function ovsdb_error_to_json_free().Ben Pfaff2017-12-131-3/+1
| | | | | | | | This simplifies little bits of code here and there. Signed-off-by: Ben Pfaff <blp@ovn.org> Tested-by: Yifeng Sun <pkusunyifeng@gmail.com> Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com>
* execution: Fix bug that leaks ovsdb_rowYifeng Sun2017-11-291-1/+2
| | | | | | | | If there is an error after ovsdb_rbac_insert, 'row' is leaked. So move the existing ovsdb_row_destroy to the function end. Signed-off-by: Yifeng Sun <pkusunyifeng@gmail.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* ovsdb: add support for role-based access controlsLance Richardson2017-06-081-3/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add suport for ovsdb RBAC (role-based access control). This includes: - Support for "RBAC_Role" table. A db schema containing a table by this name will enable role-based access controls using this table for RBAC role configuration. The "RBAC_Role" table has one row per role, with each row having a "name" column (role name) and a "permissions" column (map of table name to UUID of row in separate permission table.) The permission table has one row per access control configuration, with the following columns: "name" - name of table to which this row applies "authorization" - set of column names and column:key pairs to be compared against client ID to determine authorization status "insert_delete" - boolean, true if insertions and authorized deletions are allowed. "update" - Set of columns and column:key pairs for which authorized updates are allowed. - Support for a new "role" column in the remote configuration table. - Logic for applying the RBAC role and permission tables, in combination with session role from the remote connection table and client id, to determine whether operations modifying database contents should be permitted. - Support for specifying RBAC role string as a command-line option to ovsdb-tool (Ben Pfaff). Signed-off-by: Lance Richardson <lrichard@redhat.com> Co-authored-by: Ben Pfaff <blp@ovn.org> Signed-off-by: Ben Pfaff <blp@ovn.org>
* ovsdb: Make OVSDB backup sever read onlyAndy Zhou2016-08-141-15/+27
| | | | | | | | | | | | | When ovsdb-sever is running in the backup state, it would be nice to make sure there is no un-intended changes to the backup database. This patch makes the ovsdb server only accepts 'read' transactions as a backup server. When the server role is changed into an active server, all existing client connections will be reset. After reconnect, all clinet transactions will then be accepted. Signed-off-by: Andy Zhou <azhou@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* ovsdb: Use better error message for "timeout" without waiting.Ryan Moats2016-08-131-1/+2
| | | | | | | | | | | | | When setting a where clause, if the timeout is set to a value of 0, the clause is tested once and if it fails, a message of '"wait" timed out' is returned. This can be misleading because there wasn't any real time, so change the message to '"where" clause test failed'. Signed-off-by: Ryan Moats <rmoats@us.ibm.com> Reported-by: Ryan Moats <rmoats@us.ibm.com> Reported-at: http://openvswitch.org/pipermail/dev/2016-August/077083.html Fixes: f85f8ebb ("Initial implementation of OVSDB.") Signed-off-by: Ben Pfaff <blp@ovn.org>
* json: Move from lib to include/openvswitch.Terry Wilson2016-07-221-1/+1
| | | | | | | | | | | | | | | To easily allow both in- and out-of-tree building of the Python wrapper for the OVS JSON parser (e.g. w/ pip), move json.h to include/openvswitch. This also requires moving lib/{hmap,shash}.h. Both hmap.h and shash.h were #include-ing "util.h" even though the headers themselves did not use anything from there, but rather from include/openvswitch/util.h. Fixing that required including util.h in several C files mostly due to OVS_NOT_REACHED and things like xmalloc. Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* ovsdb: optimize match_any_clause() condition evaluationLiran Schour2016-07-181-5/+5
| | | | | | | | Optimize ovsdb_condition_match_any_clause() to be in O(#columns in condition) and not O(#clauses) in case condition's caluses function is boolean or "==". Signed-off-by: Liran Schour <lirans@il.ibm.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* lib: Move compiler.h to <openvswitch/compiler.h>Thomas Graf2014-12-151-1/+1
| | | | | | | | | | The following macros are renamed to avoid conflicts with other headers: * WARN_UNUSED_RESULT to OVS_WARN_UNUSED_RESULT * PRINTF_FORMAT to OVS_PRINTF_FORMAT * NO_RETURN to OVS_NO_RETURN Signed-off-by: Thomas Graf <tgraf@noironetworks.com> Acked-by: Ben Pfaff <blp@nicira.com>
* ovsdb: Fix error leak for negative timeout and invalid until caseThomas Graf2014-08-281-0/+2
| | | | | | | | | | Although the check for negative timeout is present, the error string is overwritten if an invalid "until" is found right after. This leaks an error string and results in not reporting the negative timeout back to the user even though it is encountered first. Signed-off-by: Thomas Graf <tgraf@noironetworks.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* Fix memory leaks in error paths.yinpeijun2014-08-271-0/+1
| | | | | | | Found by Fortify. Signed-off-by: yinpeijun <yinpeijun@huawei.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* Avoid printf type modifiers not supported by MSVC C runtime library.Alin Serdean2013-11-251-2/+2
| | | | | | | | | | | | | The MSVC C library printf() implementation does not support the 'z', 't', 'j', or 'hh' format specifiers. This commit changes the Open vSwitch code to avoid those format specifiers, switching to standard macros from <inttypes.h> where available and inventing new macros resembling them where necessary. It also updates CodingStyle to specify the macros' use and adds a Makefile rule to report violations. Signed-off-by: Alin Serdean <aserdean@cloudbasesolutions.com> Co-authored-by: Ben Pfaff <blp@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* Replace most uses of assert by ovs_assert.Ben Pfaff2013-01-161-2/+1
| | | | | | | | This is a straight search-and-replace, except that I also removed #include <assert.h> from each file where there were no assert calls left. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
* ovsdb: Enforce immutability of immutable columns.Ben Pfaff2012-09-051-1/+17
| | | | | | | | | | | OVSDB has always had the ability to mark a column as "immutable", so that its value cannot be changed in a given row after that row is initially inserted. However, we discovered recently that ovsdb-server has never enforced this constraint. This commit implements enforcement. Reported-by: Paul Ingram <paul@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Kyle Mestery <kmestery@cisco.com>
* Global replace of Nicira Networks.Raju Subramanian2012-05-021-1/+1
| | | | | | | | Replaced all instances of Nicira Networks(, Inc) to Nicira, Inc. Feature #10593 Signed-off-by: Raju Subramanian <rsubramanian@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* ovsdb: Correct specification inconsistency between "lock" and "assert".Ben Pfaff2011-08-081-1/+1
| | | | | | | | | | | The "lock" request requires the lock name to be an <id> but it is shown as <string> in the "assert" operation. This corrects the "assert" specification and fixes the suggested naming convention (since ":" is not valid in an <id>). This commit also updates the implementation to match the specification. Reported-by: Jeremy Stribling <strib@nicira.com>
* ovsdb: Implement a "lock" feature in the database protocol.Ben Pfaff2011-07-261-1/+32
| | | | | | | | | | | This provides clients a way to coordinate their access to the database. This is a voluntary, not mandatory, locking protocols, that is, clients are not prevented from modifying the database unless they cooperate with the locking protocol. It is also not related to any of the ACID properties of database transactions. It is strictly a way for clients to coordinate among themselves. The following commit will introduce one user.
* ovsdb: Make ovsdb_column_set_from_json() take table schema instead of table.Ben Pfaff2011-06-061-3/+5
| | | | | | | This function took a struct ovsdb_table but only used the 'schema' member. An upcoming patch needs to parse a column set when only the schema is available, so to prepare for that this patch changes ovsdb_column_set_from_json() to only take the schema that it really needs.
* ovsdb: Check ovsdb_mutation_set_execute() return value in transactions.Ben Pfaff2011-05-311-4/+5
| | | | | | | | | Errors from this function were being ignored, which meant that transactions could use "mutate" to bypass number-of-elements constraints on sets and maps. This fixes the problem and adds a test to prevent the problem from recurring. Bug #5781.
* Add missing "static" keywords.Ben Pfaff2011-05-161-6/+6
| | | | Found by sparse.
* ovsdb-data: Rename 'used' to 'created' in struct ovsdb_symbol.Ben Pfaff2011-03-101-2/+2
| | | | | | The name 'created' better reflects the actual meaning of this member: in both ovsdb and ovs-vsctl, it is true if a row has been created with the symbol's UUID and false otherwise.
* ovsdb: Improve error message for duplicate uuid-name.Ben Pfaff2011-03-101-11/+12
| | | | | | | | | | | | ovsdb_execute_insert() tried to return a helpful error message when there was a duplicate uuid-name, but ovsdb_execute() (its caller) makes any parse error override a parse error. Since ovsdb_execute_insert() would skip parsing the row when the uuid-name was a duplicate, this meant that the error actually reported would be that "row" was not allowed here, which wasn't at all helpful (since "row" is in fact mandatory). This commit clears up the problem by always retrieving the "row" member, which required a small amount of refactoring, and adds a test.
* ovsdb: Free "error" string in ovsdb_execute_insert().Justin Pettit2011-02-221-0/+1
| | | | Coverity #10723
* Avoid shadowing local variable names.Ben Pfaff2010-09-201-2/+0
| | | | | | | | | | | All of these changes avoid using the same name for two local variables within a same function. None of them are actual bugs as far as I can tell, but any of them could be confusing to the casual reader. The one in lib/ovsdb-idl.c is particularly brilliant: inner and outer loops both using (different) variables named 'i'. Found with GCC -Wshadow.
* ovsdb: Fix bug in "wait" command implementation.Ben Pfaff2010-09-201-1/+0
| | | | | | | | The declaration of "error" that this commit removes shadowed an outer local declaration of "error", which caused errors detected by this code not to be propagated up to the outer level. Found with GCC -Wshadow.
* ovsdb: Fix error message when parsing an operation fails.Ben Pfaff2010-03-181-1/+1
| | | | | Otherwise you get errors with text like "ovsdb operation 2 of 1", which is confusing.
* Merge "master" into "next".Ben Pfaff2010-02-111-6/+6
| | | | | The main change here is the need to update all of the uses of UNUSED in the next branch to OVS_UNUSED as it is now spelled on "master".
* ovsdb: Add support for multiple databases to the protocol.Ben Pfaff2010-02-091-4/+13
| | | | | | This also adds protocol compatibility to the database itself and to ovsdb-client. It doesn't actually add multiple database support to ovsdb-server, since we don't really need that yet.
* ovsdb: Get rid of "declare" operation.Ben Pfaff2010-02-081-45/+8
| | | | | | It's more elegant, and just as easy to implement, if we allow a "named-uuid" to be a forward reference to a "uuid-name" in a later "insert" operation.
* ovsdb: Add simple constraints.Ben Pfaff2010-02-081-1/+25
|
* ovsdb: Fix result object for "declare" operation.Ben Pfaff2010-02-081-2/+5
| | | | | | | | | The "declare" operation is specified to return a <uuid>, e.g.: ["uuid", "7b703002-f7b6-45c6-bfd6-7619b21a1a5f"] It was actually just returning the second part, e.g. "7b703002-f7b6-45c6-bfd6-7619b21a1a5f" This commit makes the result match the specification.
* ovsdb-server: Fix various memory leaks.Ben Pfaff2010-02-021-3/+6
| | | | | | | Some of these are serious leaks, in that they could leak some amount of memory for every transaction processed by the database server. Found with valgrind.
* ovsdb: Add "comment" feature to transactions and make ovs-vsctl use them.Ben Pfaff2009-12-161-0/+17
| | | | | | The idea here is that transaction comments get copied to the ovsdb-server's transaction log, which can then make it clear later why a particular change was made to the database, to ease debugging.
* ovsdb: Add new "mutation" operation to transactions.Ben Pfaff2009-12-161-0/+61
|
* ovsdb: Implement new "declare" operation.Ben Pfaff2009-12-071-2/+46
|
* ovsdb: Allow a named-uuid to be used within the operation that creates it.Ben Pfaff2009-12-021-5/+8
| | | | | | | | | | | | This allows a transaction like this: [{"op": "insert", "table": "mytable", "row": {"i": 0, "k": ["named-uuid", "self"]}, "uuid-name": "self"}] It was already possible to do this by following up on the "insert" with an "update", but since this was easy to implement I did it.
* ovsdb: Add replication support and refactor files in terms of replication.Ben Pfaff2009-11-161-36/+2
| | | | | | | An upcoming commit will add support for replicating tables across JSON-RPC connection. As a prerequisite ovsdb itself must support basic replication. This commit adds that support and then reimplements the ovsdb file storage in terms of that replication.
* ovsdb: Rename ovsdb_file to ovsdb_log.Ben Pfaff2009-11-161-4/+4
| | | | | This prepares for introducing a new, higher-level ovsdb_file that encapsulates ovsdb storage in a file.
* ovsdb: Improve error message for transaction that uses unknown operation.Ben Pfaff2009-11-061-2/+2
| | | | | Without this commit, misspelling an operation name provokes a mysterious error message.
* Initial implementation of OVSDB.Ben Pfaff2009-11-041-0/+613