<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Hello All.</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">I have a question about the patch `Add unique constraint to FixedIp` (see <a href="https://review.openstack.org/#/c/29364/" target="_blank" style="color:rgb(17,85,204)">https://review.openstack.org/#/c/29364/</a>), which is a part of blueprint `Complete db unique key enforcement on all tables dbs` (<a href="https://blueprints.launchpad.net/nova/+spec/db-enforce-unique-keys" target="_blank" style="color:rgb(17,85,204)">https://blueprints.launchpad.net/nova/+spec/db-enforce-unique-keys</a>).</div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
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.</div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
Currently we can get only one duplicate IP error message per request.</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">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.</div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
A few ways of modifying of this function have been proposed:</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><div>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.</div>
<div>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).</div>
<div><div><br></div><div>2) we can add all unique IPs to database and write duplicate IPs to log.</div></div><div>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).</div>
<div>On the other hand, this allows us to save valid IPs to database and provide the caller with a list of duplicate IPs.</div><div><br></div><div>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.</div>
<div>(A separate transaction is needed for each IP. The rollback must be done manually by issuing of DELETE FROM matching duplicate IPs).</div></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Whatever option we choose, the floating_ip_bulk_create() function should be modified the same way.</div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
I would like to receive some comments on what is the preferred option.</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
Thanks, Victor</div>