use of com.zimbra.cs.redolog.op.DeleteVolume in project zm-mailbox by Zimbra.
the class VolumeManager method delete.
/**
* Remove the volume from the system. Files on the volume being deleted are not removed.
*
* @return true if actual deletion occurred
*/
public boolean delete(short id, boolean noRedo) throws ServiceException {
DeleteVolume redoRecorder = null;
if (!noRedo) {
redoRecorder = new DeleteVolume(id);
redoRecorder.start(System.currentTimeMillis());
}
// Don't allow deleting the current message/index volume.
synchronized (this) {
if (currentMessageVolume != null && id == currentMessageVolume.getId()) {
throw VolumeServiceException.CANNOT_DELETE_CURRVOL(id, "message");
}
if (currentSecondaryMessageVolume != null && id == currentSecondaryMessageVolume.getId()) {
throw VolumeServiceException.CANNOT_DELETE_CURRVOL(id, "secondary message");
}
if (currentIndexVolume != null && id == currentIndexVolume.getId()) {
throw VolumeServiceException.CANNOT_DELETE_CURRVOL(id, "index");
}
Volume vol = getVolume(id);
if (vol.getType() == Volume.TYPE_MESSAGE || vol.getType() == Volume.TYPE_MESSAGE_SECONDARY) {
File path = new File(vol.getRootPath());
String[] files = path.list();
if (files != null && files.length > 0) {
//have to check DB to see if any of these files are referenced by mail_item; no FK anymore
DbConnection conn = DbPool.getConnection();
try {
if (DbVolume.isVolumeReferenced(conn, id)) {
ZimbraLog.store.warn("volume %d referenced by mail_item cannot be deleted", id);
throw VolumeServiceException.CANNOT_DELETE_VOLUME_IN_USE(id, null);
}
} finally {
conn.closeQuietly();
}
}
}
}
boolean success = false;
DbConnection conn = DbPool.getConnection();
try {
boolean deleted = DbVolume.delete(conn, id);
if (!noRedo) {
redoRecorder.log();
}
synchronized (this) {
id2volume.remove(id);
updateSweptDirectories();
}
success = true;
return deleted;
} finally {
endTransaction(success, conn, redoRecorder);
}
}
Aggregations