ovsdb-idl: Support for readonly columns that are fetched on-demand
authorShad Ansari <shad.ansari@hp.com>
Thu, 22 Oct 2015 21:35:24 +0000 (14:35 -0700)
committerBen Pfaff <blp@ovn.org>
Mon, 23 Nov 2015 16:34:54 +0000 (08:34 -0800)
commit80c12152f30b0598a36198d9ec67a85f2357e623
tree0e3b346ad94f9b5f48dc8a8b6f75ec63fc84ad20
parent89108874d59364313f9e5e192ba8ca00a2771d93
ovsdb-idl: Support for readonly columns that are fetched on-demand

There is currently no mechanism in IDL to fetch specific column values
on-demand without having to register them for monitoring. In the case
where the column represent a frequently changing entity (e.g. counter),
and the reads are relatively infrequent (e.g. CLI client), there is a
significant overhead in replication.

This patch adds support in the Python IDL to register a subset of the
columns of a table as "readonly". Readonly columns are not replicated.
Users may "fetch" the readonly columns of a row on-demand. Once fetched,
the columns are not updated until the next fetch by the user. Writes by
the user to readonly columns does not change the value (both locally or
on the server).

The two main user visible changes in this patch are:
  - The SchemaHelper.register_columns() method now takes an optionaly
    argument to specify the subset of readonly column(s)
  - A new Row.fetch(columns) method to fetch values of readonly columns(s)

Usage:
------

    # Schema file includes all columns, including readonly
    schema_helper = ovs.db.idl.SchemaHelper(schema_file)

    # Register interest in columns with 'r' and 's' as readonly
    schema_helper.register_columns("simple", [i, r, s], [r, s])

    # Create Idl and jsonrpc, and wait for update, as usual
    ...

    # Fetch value of column 'r' for a specific row
    row.fetch('r')
    txn.commit_block()

    print row.r
    print getattr(row, 'r')

    # Writing to readonly column has no effect (locally or on server)
    row.r = 3
    print row.r     # prints fetched value not 3

Signed-off-by: Shad Ansari <shad.ansari@hp.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
python/ovs/db/idl.py
tests/ovsdb-idl.at
tests/test-ovsdb.py