Skip to content

Commit 9077c9a

Browse files
committed
CLOUDSTACK-9022: keep Destroyed volumes for sometime
1 parent e675250 commit 9077c9a

4 files changed

Lines changed: 20 additions & 3 deletions

File tree

engine/schema/src/com/cloud/storage/dao/VolumeDao.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package com.cloud.storage.dao;
1818

19+
import java.util.Date;
1920
import java.util.List;
2021

2122
import com.cloud.hypervisor.Hypervisor.HypervisorType;
@@ -79,6 +80,8 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S
7980

8081
List<VolumeVO> listVolumesToBeDestroyed();
8182

83+
List<VolumeVO> listVolumesToBeDestroyed(Date date);
84+
8285
ImageFormat getImageFormat(Long volumeId);
8386

8487
List<VolumeVO> findReadyRootVolumesByInstance(long instanceId);

engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ public VolumeDaoImpl() {
331331
AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ);
332332
AllFieldsSearch.and("destroyed", AllFieldsSearch.entity().getState(), Op.EQ);
333333
AllFieldsSearch.and("notDestroyed", AllFieldsSearch.entity().getState(), Op.NEQ);
334+
AllFieldsSearch.and("updateTime", AllFieldsSearch.entity().getUpdated(), SearchCriteria.Op.LT);
334335
AllFieldsSearch.and("updatedCount", AllFieldsSearch.entity().getUpdatedCount(), Op.EQ);
335336
AllFieldsSearch.and("name", AllFieldsSearch.entity().getName(), Op.EQ);
336337
AllFieldsSearch.done();
@@ -482,6 +483,15 @@ public List<VolumeVO> listVolumesToBeDestroyed() {
482483
return listBy(sc);
483484
}
484485

486+
@Override
487+
public List<VolumeVO> listVolumesToBeDestroyed(Date date) {
488+
SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
489+
sc.setParameters("state", Volume.State.Destroy);
490+
sc.setParameters("updateTime", date);
491+
492+
return listBy(sc);
493+
}
494+
485495
@Override
486496
public boolean updateState(com.cloud.storage.Volume.State currentState, Event event, com.cloud.storage.Volume.State nextState, Volume vo, Object data) {
487497

server/src/com/cloud/configuration/Config.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ public enum Config {
672672
"86400",
673673
"The interval (in seconds) to wait before running the storage cleanup thread.",
674674
null),
675+
StorageCleanupDelay("Advanced", StorageManager.class, Integer.class, "storage.cleanup.delay", "86400", "Determines how long (in seconds) to wait before actually expunging destroyed volumes. The default value = the default value of storage.cleanup.interval.", null),
675676
StorageCleanupEnabled("Advanced", StorageManager.class, Boolean.class, "storage.cleanup.enabled", "true", "Enables/disables the storage cleanup thread.", null),
676677
UpdateWait("Advanced", AgentManager.class, Integer.class, "update.wait", "600", "Time to wait (in seconds) before alerting on a updating agent", null),
677678
XapiWait("Advanced", AgentManager.class, Integer.class, "xapiwait", "60", "Time (in seconds) to wait for XAPI to return", null),

server/src/com/cloud/storage/StorageManagerImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ public void setDiscoverers(List<StoragePoolDiscoverer> discoverers) {
301301
boolean _templateCleanupEnabled = true;
302302
int _storageCleanupInterval;
303303
int _storagePoolAcquisitionWaitSeconds = 1800; // 30 minutes
304+
int _storageCleanupDelay;
304305
int _downloadUrlCleanupInterval;
305306
int _downloadUrlExpirationInterval;
306307
// protected BigDecimal _overProvisioningFactor = new BigDecimal(1);
@@ -470,9 +471,11 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
470471

471472
String time = configs.get("storage.cleanup.interval");
472473
_storageCleanupInterval = NumbersUtil.parseInt(time, 86400);
474+
time = configs.get("storage.cleanup.delay");
475+
_storageCleanupDelay = NumbersUtil.parseInt(time, _storageCleanupInterval);
473476

474-
s_logger.info("Storage cleanup enabled: " + _storageCleanupEnabled + ", interval: " + _storageCleanupInterval + ", template cleanup enabled: " +
475-
_templateCleanupEnabled);
477+
s_logger.info("Storage cleanup enabled: " + _storageCleanupEnabled + ", interval: " + _storageCleanupInterval + ", delay: " + _storageCleanupDelay +
478+
", template cleanup enabled: " + _templateCleanupEnabled);
476479

477480
String cleanupInterval = configs.get("extract.url.cleanup.interval");
478481
_downloadUrlCleanupInterval = NumbersUtil.parseInt(cleanupInterval, 7200);
@@ -1111,7 +1114,7 @@ public void cleanupStorage(boolean recurring) {
11111114

11121115
cleanupSecondaryStorage(recurring);
11131116

1114-
List<VolumeVO> vols = _volsDao.listVolumesToBeDestroyed();
1117+
List<VolumeVO> vols = _volsDao.listVolumesToBeDestroyed(new Date(System.currentTimeMillis() - ((long) _storageCleanupDelay << 10)));
11151118
for (VolumeVO vol : vols) {
11161119
try {
11171120
volService.expungeVolumeAsync(volFactory.getVolume(vol.getId()));

0 commit comments

Comments
 (0)