From d4bed852c8bd83b69ce627ef382246c1f20840c8 Mon Sep 17 00:00:00 2001 From: abhishek Date: Wed, 8 Sep 2010 13:41:50 -0700 Subject: [PATCH] bug 6139: Now we can add the same sp again, once deleted. I removed the unique key constraint on the uuid, and am making the check to ensure uniqueness based on uuid in the java layer. status 6139: resolved fixed --- core/src/com/cloud/storage/dao/StoragePoolDao.java | 2 ++ core/src/com/cloud/storage/dao/StoragePoolDaoImpl.java | 8 ++++++++ server/src/com/cloud/storage/StorageManagerImpl.java | 10 +++++++++- setup/db/create-schema.sql | 2 +- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/core/src/com/cloud/storage/dao/StoragePoolDao.java b/core/src/com/cloud/storage/dao/StoragePoolDao.java index 104f282d1f2..85b5b33b40e 100644 --- a/core/src/com/cloud/storage/dao/StoragePoolDao.java +++ b/core/src/com/cloud/storage/dao/StoragePoolDao.java @@ -101,5 +101,7 @@ public interface StoragePoolDao extends GenericDao { List searchForStoragePoolDetails(long poolId, String value); long countBy(long podId, Status... statuses); + + List findIfDuplicatePoolsExistByUUID(String uuid); } diff --git a/core/src/com/cloud/storage/dao/StoragePoolDaoImpl.java b/core/src/com/cloud/storage/dao/StoragePoolDaoImpl.java index 700dfccccab..456019f6874 100644 --- a/core/src/com/cloud/storage/dao/StoragePoolDaoImpl.java +++ b/core/src/com/cloud/storage/dao/StoragePoolDaoImpl.java @@ -61,6 +61,7 @@ public class StoragePoolDaoImpl extends GenericDaoBase imp protected final SearchBuilder DeleteLvmSearch; protected final GenericSearchBuilder MaintenanceCountSearch; + protected final StoragePoolDetailsDao _detailsDao; private final String DetailsSqlPrefix = "SELECT storage_pool.* from storage_pool LEFT JOIN storage_pool_details ON storage_pool.id = storage_pool_details.pool_id WHERE storage_pool.data_center_id = ? and (storage_pool.pod_id = ? or storage_pool.pod_id is null) and ("; @@ -144,6 +145,13 @@ public class StoragePoolDaoImpl extends GenericDaoBase imp return findOneBy(sc); } + @Override + public List findIfDuplicatePoolsExistByUUID(String uuid) { + SearchCriteria sc = UUIDSearch.create(); + sc.setParameters("uuid", uuid); + return listActiveBy(sc); + } + @Override public List listByDataCenterId(long datacenterId) { diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index 0b7ff4b675e..3f40bff1a38 100644 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -1364,7 +1364,7 @@ public class StorageManagerImpl implements StorageManager { } List pools = _storagePoolDao.listPoolByHostPath(storageHost, hostPath); - if (!pools.isEmpty()) { + if (!pools.isEmpty() && pools.get(0).getRemoved()==null) { Long oldPodId = pools.get(0).getPodId(); throw new ResourceInUseException("Storage pool " + uri + " already in use by another pod (id=" + oldPodId + ")", "StoragePool", uri.toASCIIString()); } @@ -1379,6 +1379,14 @@ public class StorageManagerImpl implements StorageManager { } long poolId = _storagePoolDao.getNextInSequence(Long.class, "id"); String uuid = UUID.nameUUIDFromBytes(new String(storageHost + hostPath).getBytes()).toString(); + + List spHandles = _storagePoolDao.findIfDuplicatePoolsExistByUUID(uuid); + if(spHandles!=null && spHandles.size()>0) + { + s_logger.debug("Another active pool with the same uuid already exists"); + throw new ResourceInUseException("Another active pool with the same uuid already exists"); + } + s_logger.debug("In createPool Setting poolId - " +poolId+ " uuid - " +uuid+ " zoneId - " +zoneId+ " podId - " +podId+ " poolName - " +poolName); pool.setId(poolId); pool.setUuid(uuid); diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 183fbab2026..f2e6f8c6ed7 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -907,7 +907,7 @@ CREATE TABLE `cloud`.`load_balancer` ( CREATE TABLE `cloud`.`storage_pool` ( `id` bigint unsigned UNIQUE NOT NULL, `name` varchar(255) COMMENT 'should be NOT NULL', - `uuid` varchar(255) UNIQUE NOT NULL, + `uuid` varchar(255) NOT NULL, `pool_type` varchar(32) NOT NULL, `port` int unsigned NOT NULL, `data_center_id` bigint unsigned NOT NULL,