[ https://issues.apache.org/jira/browse/CLOUDSTACK-252?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13469819#comment-13469819 ]
Alena Prokharchyk commented on CLOUDSTACK-252: ---------------------------------------------- It's a bug in Network usage for External Devices code. Happens when account owns more than 1 network; each network has External Device, and public IP address was first assigned to network1, and then re-assigned to network2 at some point. For developer to fix, here is the explanation. UserStatisticsVO userStats = _userStatsDao.findBy(accountId, zoneId, networkId, publicIp, hostId, host.getType().toString()); - we try to locate usage stats record based on networkId and publicIpId. Then if it can't be found, we insert it. if (userStats == null) { return (_userStatsDao.persist(new UserStatisticsVO(accountId, zoneId, publicIp, hostId, host.getType().toString(), networkId)) != null); } else { return true; } But in the DB we have a following constraint; and the networkId is missing here. UNIQUE KEY `account_id` (`account_id`,`data_center_id`,`public_ip_address`,`device_id`,`device_type`), So when the same public IP address is used by diff networks in diff times (first assigned to network1, then to network2), the constraint will break once you try to insert usage record for the second network. > UpdateNetwork Operation on a guest network that is currently using Virtual > Router for Lb services to a network offering that uses "F5" for Lb services > Fails due to MySQLIntegrityConstraintViolationException. > --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > > Key: CLOUDSTACK-252 > URL: https://issues.apache.org/jira/browse/CLOUDSTACK-252 > Project: CloudStack > Issue Type: Bug > Components: Management Server > Affects Versions: pre-4.0.0 > Reporter: Chandan Purushothama > Fix For: pre-4.0.0 > > Attachments: managementserverlog_mysqldumps.zip > > > =============== > Steps to Reproduce: > =============== > 1. On an Advanced Zone with two physical networks, create a guest network > from a network offering with services as mentioned below > mysql> select * from network_offerings where id=13 \G > *************************** 1. row *************************** > id: 13 > name: Network-SNAT-guest1 > uuid: 277b7b7a-8aeb-46f8-94e9-e83de34912a8 > unique_name: Network-SNAT-guest1 > display_text: Network-SNAT-guest1 > nw_rate: 500 > mc_rate: 10 > traffic_type: Guest > tags: guest1 > system_only: 0 > specify_vlan: 0 > service_offering_id: NULL > conserve_mode: 0 > created: 2012-09-26 18:43:35 > removed: NULL > default: 0 > availability: Optional > dedicated_lb_service: 1 > shared_source_nat_service: 0 > sort_key: 0 > redundant_router_service: 0 > state: Enabled > guest_type: Isolated > elastic_ip_service: 0 > elastic_lb_service: 0 > specify_ip_ranges: 0 > 1 row in set (0.00 sec) > mysql> select * from ntwk_offering_service_map where network_offering_id=13; > +----+---------------------+----------------+---------------+---------------------+ > | id | network_offering_id | service | provider | created > | > +----+---------------------+----------------+---------------+---------------------+ > | 48 | 13 | Dhcp | VirtualRouter | 2012-09-26 > 18:43:35 | > | 51 | 13 | Dns | VirtualRouter | 2012-09-26 > 18:43:35 | > | 52 | 13 | Firewall | VirtualRouter | 2012-09-26 > 18:43:35 | > | 49 | 13 | Lb | VirtualRouter | 2012-09-26 > 18:43:35 | > | 50 | 13 | PortForwarding | VirtualRouter | 2012-09-26 > 18:43:35 | > | 53 | 13 | SourceNat | VirtualRouter | 2012-09-26 > 18:43:35 | > | 46 | 13 | StaticNat | VirtualRouter | 2012-09-26 > 18:43:35 | > | 54 | 13 | UserData | VirtualRouter | 2012-09-26 > 18:43:35 | > | 47 | 13 | Vpn | VirtualRouter | 2012-09-26 > 18:43:35 | > +----+---------------------+----------------+---------------+---------------------+ > 9 rows in set (0.00 sec) > mysql> > 2, Deploy three VMs on a guest network that is created from the above > mentioned network offering. > 3. Create a Load balancing rule servicing the VMs on the guest network. > 4. Stop All the VMs and UpdateNetwork to the Network offering with services > as mentioned below. Notice that the LB Service is provided by F5 in the new > network offering. > mysql> select * from network_offerings where id=18 \G > *************************** 1. row *************************** > id: 18 > name: Network-F5-guest1 > uuid: 5c7746b8-e29f-4a74-8369-e88647081053 > unique_name: Network-F5-guest1 > display_text: Network-F5-guest1 > nw_rate: 535 > mc_rate: 10 > traffic_type: Guest > tags: guest1 > system_only: 0 > specify_vlan: 0 > service_offering_id: NULL > conserve_mode: 0 > created: 2012-09-27 01:13:38 > removed: NULL > default: 0 > availability: Optional > dedicated_lb_service: 0 > shared_source_nat_service: 0 > sort_key: 0 > redundant_router_service: 0 > state: Enabled > guest_type: Isolated > elastic_ip_service: 0 > elastic_lb_service: 0 > specify_ip_ranges: 0 > 1 row in set (0.00 sec) > mysql> select * from ntwk_offering_service_map where network_offering_id=18; > +----+---------------------+----------------+---------------+---------------------+ > | id | network_offering_id | service | provider | created > | > +----+---------------------+----------------+---------------+---------------------+ > | 81 | 18 | Dhcp | VirtualRouter | 2012-09-27 > 01:13:38 | > | 86 | 18 | Dns | VirtualRouter | 2012-09-27 > 01:13:38 | > | 83 | 18 | Firewall | VirtualRouter | 2012-09-27 > 01:13:38 | > | 85 | 18 | Lb | F5BigIp | 2012-09-27 > 01:13:38 | > | 80 | 18 | PortForwarding | VirtualRouter | 2012-09-27 > 01:13:38 | > | 84 | 18 | SourceNat | VirtualRouter | 2012-09-27 > 01:13:38 | > | 82 | 18 | StaticNat | VirtualRouter | 2012-09-27 > 01:13:38 | > | 79 | 18 | UserData | VirtualRouter | 2012-09-27 > 01:13:38 | > | 87 | 18 | Vpn | VirtualRouter | 2012-09-27 > 01:13:38 | > +----+---------------------+----------------+---------------+---------------------+ > 9 rows in set (0.00 sec) > 5. Observe the Exception mentioned below. > =========== > Observations: > =========== > ================================== > MySQLIntegrityConstraintViolationException: > ================================== > 2012-10-03 17:36:57,449 DEBUG [db.Transaction.Transaction] > (ExternalNetworkMonitor-1:null) Rolling back the transaction: Time = 4 Name = > > -ExternalLoadBalancerUsageManagerImpl$ExternalLoadBalancerDeviceNetworkUsageTask.manageStatsEntries:537-ExternalLoadBalancerUsageManagerImpl$ExternalLoadBalancerDeviceNetworkUsageTask.runExternalLoadBalancerNetworkUsageTask:403-ExternalLoadBalancerUsageManagerImpl$ExternalLoadBalancerDeviceNetworkUsageTask.run:323-Executors$RunnableAdapter.call:471-FutureTask$Sync.innerRunAndReset:351-FutureTask.runAndReset:178-ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201:165-ScheduledThreadPoolExecutor$ScheduledFutureTask.run:267-ThreadPoolExecutor.runWorker:1110-ThreadPoolExecutor$Worker.run:603-Thread.run:679; > called by > -Transaction.rollback:887-Transaction.removeUpTo:830-Transaction.close:649-DatabaseCallback.interceptComplete:71-DatabaseCallback.intercept:36-ExternalLoadBalancerUsageManagerImpl$ExternalLoadBalancerDeviceNetworkUsageTask.createStatsEntry:442-ExternalLoadBalancerUsageManagerImpl$ExternalLoadBalancerDeviceNetworkUsageTask.createOrUpdateStatsEntry:523-ExternalLoadBalancerUsageManagerImpl$ExternalLoadBalancerDeviceNetworkUsageTask.manageStatsEntries:547-ExternalLoadBalancerUsageManagerImpl$ExternalLoadBalancerDeviceNetworkUsageTask.runExternalLoadBalancerNetworkUsageTask:403-ExternalLoadBalancerUsageManagerImpl$ExternalLoadBalancerDeviceNetworkUsageTask.run:323-Executors$RunnableAdapter.call:471-FutureTask$Sync.innerRunAndReset:351 > 2012-10-03 17:36:57,451 WARN > [cloud.network.ExternalLoadBalancerUsageManagerImpl] > (ExternalNetworkMonitor-1:null) Exception: > javax.persistence.EntityExistsException: Entity already exists: > at com.cloud.utils.db.GenericDaoBase.persist(GenericDaoBase.java:1309) > at > com.cloud.utils.db.DatabaseCallback.intercept(DatabaseCallback.java:34) > at > com.cloud.network.ExternalLoadBalancerUsageManagerImpl$ExternalLoadBalancerDeviceNetworkUsageTask.createStatsEntry(ExternalLoadBalancerUsageManagerImpl.java:442) > at > com.cloud.network.ExternalLoadBalancerUsageManagerImpl$ExternalLoadBalancerDeviceNetworkUsageTask.createOrUpdateStatsEntry(ExternalLoadBalancerUsageManagerImpl.java:523) > at > com.cloud.network.ExternalLoadBalancerUsageManagerImpl$ExternalLoadBalancerDeviceNetworkUsageTask.manageStatsEntries(ExternalLoadBalancerUsageManagerImpl.java:547) > at > com.cloud.network.ExternalLoadBalancerUsageManagerImpl$ExternalLoadBalancerDeviceNetworkUsageTask.runExternalLoadBalancerNetworkUsageTask(ExternalLoadBalancerUsageManagerImpl.java:403) > at > com.cloud.network.ExternalLoadBalancerUsageManagerImpl$ExternalLoadBalancerDeviceNetworkUsageTask.run(ExternalLoadBalancerUsageManagerImpl.java:323) > at > java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) > at > java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351) > at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178) > at > java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:165) > at > java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267) > at > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) > at > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) > at java.lang.Thread.run(Thread.java:679) > Caused by: > com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: > Duplicate entry '3-1-10.223.139.12-6-ExternalLoadBalancer' for key > 'account_id' > at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native > Method) > at > sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) > at > sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) > at java.lang.reflect.Constructor.newInstance(Constructor.java:532) > at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) > at com.mysql.jdbc.Util.getInstance(Util.java:386) > at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1040) > at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3597) > at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529) > at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990) > at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151) > at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2625) > at > com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2119) > at > com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2415) > at > com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2333) > at > com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2318) > at > org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:106) > at com.cloud.utils.db.GenericDaoBase.persist(GenericDaoBase.java:1274) > ... 18 more > 2012-10-03 17:36:57,455 DEBUG > [cloud.network.ExternalLoadBalancerUsageManagerImpl] > (ExternalNetworkMonitor-1:null) Network 205 is not configured for external > networking, so skipping usage check. > 2012-10-03 17:36:57,457 DEBUG > [cloud.network.ExternalLoadBalancerUsageManagerImpl] > (ExternalNetworkMonitor-1:null) Network 206 is not configured for external > networking, so skipping usage check. > 2012-10-03 17:36:57,468 DEBUG > [cloud.network.ExternalLoadBalancerUsageManagerImpl] > (ExternalNetworkMonitor-1:null) Successfully updated stats for account atoms, > zone ZONE-ASF, network ID 209, host ID 200-F5BigIpLoadBalancer-10.223.60.3, > public IP: 10.223.139.8 > ======= > Git Info: > ======= > Git Revision: 61e1cf3c44863b5104364ccb27c43a45708f2b57 > Git URL: https://git-wip-us.apache.org/repos/asf/incubator-cloudstack.git -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira