Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 4D88B200B6B for ; Thu, 25 Aug 2016 12:08:47 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 4C3BB160ABD; Thu, 25 Aug 2016 10:08:47 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 9BE90160AC8 for ; Thu, 25 Aug 2016 12:08:46 +0200 (CEST) Received: (qmail 99853 invoked by uid 500); 25 Aug 2016 10:08:44 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 99405 invoked by uid 99); 25 Aug 2016 10:08:44 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 Aug 2016 10:08:44 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 41D97E69B0; Thu, 25 Aug 2016 10:08:44 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: bhaisaab@apache.org To: commits@cloudstack.apache.org Date: Thu, 25 Aug 2016 10:08:48 -0000 Message-Id: In-Reply-To: <6b9be48402a94893abd31208cad792b8@git.apache.org> References: <6b9be48402a94893abd31208cad792b8@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [05/11] git commit: updated refs/heads/4.9-systemdubuntupkging to 7bc8046 archived-at: Thu, 25 Aug 2016 10:08:47 -0000 CLOUDSTACK-9466: Fix fk constraint failure in upgrade path In the 4.1.0-4.2.0 db upgrade path, it creates new tables to store secondary (nfs) storage in image_store table and volumes in volume_store_ref table. In the upgrade path, it first tries to migrate NFS storage pool where it excludes storage pools which have been removed, but it migrates all the volumes without checking if their storage pools have been removed. This causes fk constraint failure as the volume/row being inserted refers to a storage pool which does not exist in the image_store table. The fix migrates all the nfs storage pools to image_store including removed storage pools and in doing so migrates with the 'removed' field. This fixes db upgrade for old pre-4.0 and 4.0/4.1 CloudStack clouds. Signed-off-by: Rohit Yadav Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/7530f4b6 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/7530f4b6 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/7530f4b6 Branch: refs/heads/4.9-systemdubuntupkging Commit: 7530f4b6dd98c18bceda3e1bf7790c0689ff5441 Parents: 740bd45 Author: Rohit Yadav Authored: Tue Aug 23 13:23:18 2016 +0530 Committer: Rohit Yadav Committed: Wed Aug 24 12:03:46 2016 +0530 ---------------------------------------------------------------------- engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7530f4b6/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java index b816fdc..80dbb55 100644 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java @@ -1759,9 +1759,9 @@ public class Upgrade410to420 implements DbUpgrade { PreparedStatement pstmtSelectSwiftCount = conn.prepareStatement(sqlSelectSwiftCount); PreparedStatement storeDetailInsert = conn.prepareStatement(sqlInsertStoreDetail); PreparedStatement storeInsert = - conn.prepareStatement("INSERT INTO `cloud`.`image_store` (id, uuid, name, image_provider_name, protocol, url, data_center_id, scope, role, parent, total_size, created) values(?, ?, ?, 'NFS', 'nfs', ?, ?, 'ZONE', ?, ?, ?, ?)"); + conn.prepareStatement("INSERT INTO `cloud`.`image_store` (id, uuid, name, image_provider_name, protocol, url, data_center_id, scope, role, parent, total_size, created, removed) values(?, ?, ?, 'NFS', 'nfs', ?, ?, 'ZONE', ?, ?, ?, ?, ?)"); PreparedStatement nfsQuery = - conn.prepareStatement("select id, uuid, url, data_center_id, parent, total_size, created from `cloud`.`host` where type = 'SecondaryStorage' and removed is null"); + conn.prepareStatement("select id, uuid, url, data_center_id, parent, total_size, created, removed from `cloud`.`host` where type = 'SecondaryStorage'"); PreparedStatement pstmtUpdateHostAsRemoved = conn.prepareStatement(sqlUpdateHostAsRemoved); ResultSet rsSelectS3Count = pstmtSelectS3Count.executeQuery(); ResultSet rsSelectSwiftCount = pstmtSelectSwiftCount.executeQuery(); @@ -1796,6 +1796,7 @@ public class Upgrade410to420 implements DbUpgrade { int nfs_dcid = rsNfs.getInt("data_center_id"); Long nfs_totalsize = rsNfs.getObject("total_size") != null ? rsNfs.getLong("total_size") : null; Date nfs_created = rsNfs.getDate("created"); + Date nfs_removed = rsNfs.getDate("removed"); // insert entry in image_store table and image_store_details // table and store host_id and store_id mapping @@ -1812,6 +1813,7 @@ public class Upgrade410to420 implements DbUpgrade { storeInsert.setNull(8, Types.BIGINT); } storeInsert.setDate(9, nfs_created); + storeInsert.setDate(10, nfs_removed); storeInsert.executeUpdate(); }