From ab171adfdd02c31ebff79199903bb54dd907bfd0 Mon Sep 17 00:00:00 2001 From: Harikrishna Patnala Date: Thu, 6 Aug 2020 23:56:11 +0530 Subject: [PATCH] Handle failure case of putting datastore cluster on maintenance mode --- .../java/com/cloud/storage/StorageManagerImpl.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/com/cloud/storage/StorageManagerImpl.java b/server/src/main/java/com/cloud/storage/StorageManagerImpl.java index eedcf71983b..597ec58ef8f 100644 --- a/server/src/main/java/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/main/java/com/cloud/storage/StorageManagerImpl.java @@ -1562,9 +1562,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C } }); List maintenanceSuccessfulStoragePools = new ArrayList<>(); - for (StoragePoolVO childDatastore : childDatastores) { - //FR41 need to handle when one of the primary stores is unable to put in maintenance mode - DataStore childStore = _dataStoreMgr.getDataStore(childDatastore.getId(), DataStoreRole.Primary); + for (Iterator iteratorChildDatastore = childDatastores.listIterator(); iteratorChildDatastore.hasNext(); ) { + DataStore childStore = _dataStoreMgr.getDataStore(iteratorChildDatastore.next().getId(), DataStoreRole.Primary); try { lifeCycle.maintain(childStore); } catch (Exception e) { @@ -1572,9 +1571,17 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C s_logger.debug(String.format("Exception on maintenance preparation of one of the child datastores in datastore cluster %d with error %s", primaryStorageId, e)); s_logger.debug(String.format("Cancelling the maintenance mode of child datastores in datastore cluster %d", primaryStorageId)); } + // Cancel maintenance mode of already prepared child storage pools + maintenanceSuccessfulStoragePools.add(childStore); for (DataStore dataStore: maintenanceSuccessfulStoragePools) { lifeCycle.cancelMaintain(dataStore); } + // Set back to Up state of remaining child storage pools + while (iteratorChildDatastore.hasNext()) { + StoragePoolVO childDatastore = iteratorChildDatastore.next(); + childDatastore.setStatus(StoragePoolStatus.Up); + _storagePoolDao.update(childDatastore.getId(), childDatastore); + } throw new CloudRuntimeException(String.format("Failed to prepare maintenance mode for datastore cluster %d with error %s %s", primaryStorageId, e.getMessage(), e)); } maintenanceSuccessfulStoragePools.add(childStore);