[openstack-dev] [Nova] Question about fixed_ip_bulk_create() db.api function.

Victor Sergeyev vsergeyev at mirantis.com
Tue Jul 2 09:32:01 UTC 2013

Hello All.

I have a question about the patch `Add unique constraint to FixedIp` (see
https://review.openstack.org/#/c/29364/), which is a part of blueprint
`Complete db unique key enforcement on all tables dbs` (

There is a discussion about fixed_ip_bulk_create() behavior in this patch
review. At the moment this function receives a list of fixed_ips and tries
to insert these IPs to database one-by-one. If DBDuplicateEntry exception
raised, the function raises an exception with the first duplicate IP in
exception message. The same is true for floating_ip_bulk_create() function.

Currently we can get only one duplicate IP error message per request.
So, if we add 1000 IP addresses, including 100 duplicates, we have to call
this function 100 times to find out which IPs aren't unique.

A few ways of modifying of this function have been proposed:
1) we can try to add all IPs to database using a bulk insert. If one of
those IPs violates the unique constraint, the exception is raised
containing the first duplicate IP address, the transaction is rolled back
and no IPs are saved to DB.
This keeps current behavior, but is significantly faster when a large
number of rows are inserted (Oslo integrity error handling code should be
modified a bit to retrieve the duplicated value from an exception message).

2) we can add all unique IPs to database and write duplicate IPs to log.
This is much slower, because we have to create a separate transaction for
each IP (as the first integrity error would cancel the current transaction
until ROLLBACK was emitted).
On the other hand, this allows us to save valid IPs to database and provide
the caller with a list of duplicate IPs.

3) we can try to add all IPs to database. All duplicate IPs are collected.
If there is at least one duplicate, no IPs are saved to database, but the
caller receives a list with all duplicate IPs.
(A separate transaction is needed for each IP. The rollback must be done
manually by issuing of DELETE FROM matching duplicate IPs).

Whatever option we choose, the floating_ip_bulk_create() function should be
modified the same way.

I would like to receive some comments on what is the preferred option.

Thanks, Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20130702/456534dc/attachment.html>

More information about the OpenStack-dev mailing list