Skip to content

Commit

Permalink
ovsdb: Add/use partial set updates.
Browse files Browse the repository at this point in the history
This patchset mimics the changes introduced in

  f199df2 (ovsdb-idl: Add partial map updates functionality.)
  010fe7a (ovsdb-idlc.in: Autogenerate partial map updates functions.)
  7251075 (tests: Add test for partial map updates.)
  b1048e6 (ovsdb-idl: Fix issues detected in Partial Map Update feature)

but for columns that store sets of values rather than key-value
pairs.  These columns will now be able to use the OVSDB mutate
operation to transmit deltas on the wire rather than use
verify/update and transmit wait/update operations on the wire.

Side effect of modifying the comments in the partial map update
tests.

Signed-off-by: Ryan Moats <rmoats@us.ibm.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
  • Loading branch information
jayhawk87 authored and blp committed Aug 14, 2016
1 parent 33ac3c8 commit f1ab6e0
Show file tree
Hide file tree
Showing 11 changed files with 807 additions and 106 deletions.
2 changes: 2 additions & 0 deletions lib/automake.mk
Expand Up @@ -187,6 +187,8 @@ lib_libopenvswitch_la_SOURCES = \
lib/ovsdb-idl.h \
lib/ovsdb-map-op.c \
lib/ovsdb-map-op.h \
lib/ovsdb-set-op.c \
lib/ovsdb-set-op.h \
lib/ovsdb-condition.h \
lib/ovsdb-condition.c \
lib/ovsdb-parser.c \
Expand Down
3 changes: 3 additions & 0 deletions lib/ovsdb-idl-provider.h
Expand Up @@ -20,6 +20,7 @@
#include "openvswitch/list.h"
#include "ovsdb-idl.h"
#include "ovsdb-map-op.h"
#include "ovsdb-set-op.h"
#include "ovsdb-types.h"
#include "openvswitch/shash.h"
#include "uuid.h"
Expand All @@ -39,6 +40,8 @@ struct ovsdb_idl_row {
struct hmap_node txn_node; /* Node in ovsdb_idl_txn's list. */
unsigned long int *map_op_written; /* Bitmap of columns pending map ops. */
struct map_op_list **map_op_lists; /* Per-column map operations. */
unsigned long int *set_op_written; /* Bitmap of columns pending set ops. */
struct set_op_list **set_op_lists; /* Per-column set operations. */

/* Tracking data */
unsigned int change_seqno[OVSDB_IDL_CHANGE_MAX];
Expand Down
390 changes: 291 additions & 99 deletions lib/ovsdb-idl.c

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions lib/ovsdb-idl.h
Expand Up @@ -277,6 +277,12 @@ void ovsdb_idl_txn_write_partial_map(const struct ovsdb_idl_row *,
void ovsdb_idl_txn_delete_partial_map(const struct ovsdb_idl_row *,
const struct ovsdb_idl_column *,
struct ovsdb_datum *);
void ovsdb_idl_txn_write_partial_set(const struct ovsdb_idl_row *,
const struct ovsdb_idl_column *,
struct ovsdb_datum *);
void ovsdb_idl_txn_delete_partial_set(const struct ovsdb_idl_row *,
const struct ovsdb_idl_column *,
struct ovsdb_datum *);
void ovsdb_idl_txn_delete(const struct ovsdb_idl_row *);
const struct ovsdb_idl_row *ovsdb_idl_txn_insert(
struct ovsdb_idl_txn *, const struct ovsdb_idl_table_class *,
Expand Down
170 changes: 170 additions & 0 deletions lib/ovsdb-set-op.c
@@ -0,0 +1,170 @@
/* Copyright (C) 2016, IBM
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

#include <config.h>
#include "ovsdb-set-op.h"
#include "util.h"

/* Set Operation: a Partial Set Update */
struct set_op {
struct hmap_node node;
struct ovsdb_datum *datum;
enum set_op_type type;
};

/* List of Set Operations */
struct set_op_list {
struct hmap hmap;
};

static void set_op_destroy_datum(struct set_op *, const struct ovsdb_type *);
static struct set_op *set_op_list_find(struct set_op_list *, struct set_op *,
const struct ovsdb_type *, size_t);

struct set_op*
set_op_create(struct ovsdb_datum *datum, enum set_op_type type)
{
struct set_op *set_op = xmalloc(sizeof *set_op);
set_op->node.hash = 0;
set_op->node.next = HMAP_NODE_NULL;
set_op->datum = datum;
set_op->type = type;
return set_op;
}

static void
set_op_destroy_datum(struct set_op *set_op, const struct ovsdb_type *type)
{
if (set_op->type == SET_OP_DELETE){
struct ovsdb_type type_ = *type;
type_.value.type = OVSDB_TYPE_VOID;
ovsdb_datum_destroy(set_op->datum, &type_);
} else {
ovsdb_datum_destroy(set_op->datum, type);
}
free(set_op->datum);
set_op->datum = NULL;
}

void
set_op_destroy(struct set_op *set_op, const struct ovsdb_type *type)
{
set_op_destroy_datum(set_op, type);
free(set_op);
}

struct ovsdb_datum*
set_op_datum(const struct set_op *set_op)
{
return set_op->datum;
}

enum set_op_type
set_op_type(const struct set_op *set_op)
{
return set_op->type;
}

struct set_op_list*
set_op_list_create(void)
{
struct set_op_list *list = xmalloc(sizeof *list);
hmap_init(&list->hmap);
return list;
}

void
set_op_list_destroy(struct set_op_list *list, const struct ovsdb_type *type)
{
struct set_op *set_op, *next;
HMAP_FOR_EACH_SAFE (set_op, next, node, &list->hmap) {
set_op_destroy(set_op, type);
}
hmap_destroy(&list->hmap);
free(list);
}

static struct set_op*
set_op_list_find(struct set_op_list *list, struct set_op *set_op,
const struct ovsdb_type *type, size_t hash)
{
struct set_op *found = NULL;
struct set_op *old;
HMAP_FOR_EACH_WITH_HASH(old, node, hash, &list->hmap) {
if (ovsdb_atom_equals(&old->datum->keys[0], &set_op->datum->keys[0],
type->key.type)) {
found = old;
break;
}
}
return found;
}

/* Inserts 'set_op' into 'list'. Makes sure that any conflict with a previous
* set operation is resolved, so only one set operation is possible on each key
* per transactions. 'type' must be the type of the column over which the set
* operation will be applied. */
void
set_op_list_add(struct set_op_list *list, struct set_op *set_op,
const struct ovsdb_type *type)
{
/* Check if there is a previous update with the same key. */
size_t hash;
struct set_op *prev_set_op;

hash = ovsdb_atom_hash(&set_op->datum->keys[0], type->key.type, 0);
prev_set_op = set_op_list_find(list, set_op, type, hash);
if (prev_set_op == NULL){
hmap_insert(&list->hmap, &set_op->node, hash);
} else {
if (prev_set_op->type == SET_OP_INSERT &&
set_op->type == SET_OP_DELETE) {
/* These operations cancel each other out. */
hmap_remove(&list->hmap, &prev_set_op->node);
set_op_destroy(prev_set_op, type);
set_op_destroy(set_op, type);
} else {
/* For any other case, the new update operation replaces
* the previous update operation. */
set_op_destroy_datum(prev_set_op, type);
prev_set_op->type = set_op->type;
prev_set_op->datum = set_op->datum;
free(set_op);
}
}
}

struct set_op*
set_op_list_first(struct set_op_list *list)
{
struct hmap_node *node = hmap_first(&list->hmap);
if (node == NULL) {
return NULL;
}
struct set_op *set_op = CONTAINER_OF(node, struct set_op, node);
return set_op;
}

struct set_op*
set_op_list_next(struct set_op_list *list, struct set_op *set_op)
{
struct hmap_node *node = hmap_next(&list->hmap, &set_op->node);
if (node == NULL) {
return NULL;
}
struct set_op *next = CONTAINER_OF(node, struct set_op, node);
return next;
}
44 changes: 44 additions & 0 deletions lib/ovsdb-set-op.h
@@ -0,0 +1,44 @@
/* Copyright (C) 2016, IBM
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

#ifndef OVSDB_SET_OP_H
#define OVSDB_SET_OP_H 1

#include "ovsdb-data.h"

enum set_op_type {
SET_OP_INSERT,
SET_OP_DELETE
};

struct set_op; /* Set Operation: a Partial Set Update */
struct set_op_list; /* List of Set Operations */

/* Set Operation functions */
struct set_op *set_op_create(struct ovsdb_datum *, enum set_op_type);
void set_op_destroy(struct set_op *, const struct ovsdb_type *);
struct ovsdb_datum *set_op_datum(const struct set_op*);
enum set_op_type set_op_type(const struct set_op*);

/* Set Operation List functions */
struct set_op_list *set_op_list_create(void);
void set_op_list_destroy(struct set_op_list *, const struct ovsdb_type *);
void set_op_list_add(struct set_op_list *, struct set_op *,
const struct ovsdb_type *);
struct set_op *set_op_list_first(struct set_op_list *);
struct set_op *set_op_list_next(struct set_op_list *, struct set_op *);

#endif /* ovsdb-set-op.h */
65 changes: 64 additions & 1 deletion ovsdb/ovsdb-idlc.in
Expand Up @@ -233,7 +233,12 @@ bool %(s)s_is_updated(const struct %(s)s *, enum %(s)s_column_id);
print 'void %(s)s_update_%(c)s_setkey(const struct %(s)s *, ' % {'s': structName, 'c': columnName},
print '%(coltype)s, %(valtype)s);' % {'coltype':column.type.key.toCType(prefix), 'valtype':column.type.value.toCType(prefix)}
print 'void %(s)s_update_%(c)s_delkey(const struct %(s)s *, ' % {'s': structName, 'c': columnName},
print '%(coltype)s);' % {'coltype':column.type.key.toCType(prefix)},
print '%(coltype)s);' % {'coltype':column.type.key.toCType(prefix)}
if column.type.is_set():
print 'void %(s)s_update_%(c)s_addvalue(const struct %(s)s *, ' % {'s': structName, 'c': columnName},
print '%(valtype)s);' % {'valtype':column.type.key.toCType(prefix)}
print 'void %(s)s_update_%(c)s_delvalue(const struct %(s)s *, ' % {'s': structName, 'c': columnName},
print '%(valtype)s);' % {'valtype':column.type.key.toCType(prefix)}

print 'void %(s)s_add_clause_%(c)s(struct ovsdb_idl *idl, enum ovsdb_function function,' % {'s': structName, 'c': columnName},
if column.type.is_smap():
Expand Down Expand Up @@ -854,6 +859,64 @@ void
'valtype':column.type.value.toCType(prefix), 'S': structName.upper(),
'C': columnName.upper()}
# End Update/Delete of partial maps
# Update/Delete of partial set column functions
if type.is_set():
print '''
/* Adds the value 'new_value' to the "%(c)s" set column from the "%(t)s" table
* in 'row'.
*
*/
void
%(s)s_update_%(c)s_addvalue(const struct %(s)s *row, %(valtype)snew_value)
{
struct ovsdb_datum *datum;

ovs_assert(inited);

datum = xmalloc(sizeof *datum);
datum->n = 1;
datum->keys = xmalloc(datum->n * sizeof *datum->values);
datum->values = NULL;
''' % {'s': structName, 'c': columnName,
'valtype':column.type.key.toCType(prefix), 't': tableName}

print " "+ type.key.copyCValue("datum->keys[0].%s" % type.key.type.to_string(), "new_value")
print '''
ovsdb_idl_txn_write_partial_set(&row->header_,
&%(s)s_columns[%(S)s_COL_%(C)s],
datum);
}''' % {'s': structName, 'c': columnName,'coltype':column.type.key.toCType(prefix),
'valtype':column.type.key.toCType(prefix), 'S': structName.upper(),
'C': columnName.upper()}
print '''
/* Deletes the value 'delete_value' from the "%(c)s" set column from the
* "%(t)s" table in 'row'.
*
*/
void
%(s)s_update_%(c)s_delvalue(const struct %(s)s *row, %(valtype)sdelete_value)
{
struct ovsdb_datum *datum;

ovs_assert(inited);

datum = xmalloc(sizeof *datum);
datum->n = 1;
datum->keys = xmalloc(datum->n * sizeof *datum->values);
datum->values = NULL;
''' % {'s': structName, 'c': columnName,'coltype':column.type.key.toCType(prefix),
'valtype':column.type.key.toCType(prefix), 'S': structName.upper(),
'C': columnName.upper(), 't': tableName}

print " "+ type.key.copyCValue("datum->keys[0].%s" % type.key.type.to_string(), "delete_value")
print '''
ovsdb_idl_txn_delete_partial_set(&row->header_,
&%(s)s_columns[%(S)s_COL_%(C)s],
datum);
}''' % {'s': structName, 'c': columnName,'coltype':column.type.key.toCType(prefix),
'valtype':column.type.key.toCType(prefix), 'S': structName.upper(),
'C': columnName.upper()}
# End Update/Delete of partial set

# Add clause functions.
for columnName, column in sorted(table.columns.iteritems()):
Expand Down
30 changes: 30 additions & 0 deletions tests/idltest.ovsschema
Expand Up @@ -134,6 +134,36 @@
}
}
}
},
"simple3" : {
"columns" : {
"name" : {
"type": "string"
},
"uset": {
"type": {
"key": {"type": "uuid"},
"min": 0,
"max": "unlimited"
}
},
"uref": {
"type": {
"key": {"type": "uuid",
"refTable": "simple4",
"refType": "strong"},
"min": 0,
"max": "unlimited"
}
}
}
},
"simple4" : {
"columns" : {
"name" : {
"type": "string"
}
}
}
}
}

0 comments on commit f1ab6e0

Please sign in to comment.