@Override public SnapshotInfo getChild() { QueryBuilder<SnapshotDataStoreVO> sc = QueryBuilder.create(SnapshotDataStoreVO.class); sc.and(sc.entity().getDataStoreId(), Op.EQ, store.getId()); sc.and(sc.entity().getRole(), Op.EQ, store.getRole()); sc.and(sc.entity().getState(), Op.NIN, State.Destroying, State.Destroyed, State.Error); sc.and(sc.entity().getParentSnapshotId(), Op.EQ, getId()); SnapshotDataStoreVO vo = sc.find(); if (vo == null) { return null; } return snapshotFactory.getSnapshot(vo.getId(), store); }
s_logger.info("Duplicate " + snapshots.size() + " snapshot cache store records to region store"); for (SnapshotDataStoreVO snap : snapshots) { SnapshotDataStoreVO snapStore = findByStoreSnapshot(DataStoreRole.Image, storeId, snap.getSnapshotId()); if (snapStore != null) { s_logger.info("There is already entry for snapshot " + snap.getSnapshotId() + " on region store " + storeId); continue; s_logger.info("Persisting an entry for snapshot " + snap.getSnapshotId() + " on region store " + storeId); SnapshotDataStoreVO ss = new SnapshotDataStoreVO(); ss.setSnapshotId(snap.getSnapshotId()); ss.setDataStoreId(storeId); ss.setRole(DataStoreRole.Image); ss.setVolumeId(snap.getVolumeId()); ss.setParentSnapshotId(snap.getParentSnapshotId()); ss.setState(snap.getState()); ss.setSize(snap.getSize()); ss.setPhysicalSize(snap.getPhysicalSize()); ss.setRefCnt(snap.getRefCnt()); persist(ss); snap.incrRefCnt(); update(snap.getId(), snap);
@Override public boolean equals(Object obj) { if (obj instanceof SnapshotDataStoreVO) { SnapshotDataStoreVO other = (SnapshotDataStoreVO)obj; return (snapshotId == other.getSnapshotId() && dataStoreId == other.getDataStoreId()); } return false; }
@Override public boolean updateState(State currentState, Event event, State nextState, DataObjectInStore vo, Object data) { SnapshotDataStoreVO dataObj = (SnapshotDataStoreVO)vo; Long oldUpdated = dataObj.getUpdatedCount(); Date oldUpdatedTime = dataObj.getUpdated(); sc.setParameters("id", dataObj.getId()); sc.setParameters("state", currentState); sc.setParameters("updatedCount", dataObj.getUpdatedCount()); dataObj.incrUpdatedCount(); SnapshotDataStoreVO dbVol = findByIdIncludingRemoved(dataObj.getId()); if (dbVol != null) { StringBuilder str = new StringBuilder("Unable to update ").append(dataObj.toString()); str.append(": DB Data={id=") .append(dbVol.getId()) .append("; state=") .append(dbVol.getState()) .append("; updatecount=") .append(dbVol.getUpdatedCount()) .append(";updatedTime=") .append(dbVol.getUpdated()); str.append(": New Data={id=") .append(dataObj.getId()) .append("; state=") .append(nextState) .append(event) .append("; updatecount=")
storeSearch.and("store_id", storeSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ); storeSearch.and("store_role", storeSearch.entity().getRole(), SearchCriteria.Op.EQ); storeSearch.and("state", storeSearch.entity().getState(), SearchCriteria.Op.NEQ); storeSearch.done(); destroyedSearch.and("store_id", destroyedSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ); destroyedSearch.and("store_role", destroyedSearch.entity().getRole(), SearchCriteria.Op.EQ); destroyedSearch.and("state", destroyedSearch.entity().getState(), SearchCriteria.Op.EQ); destroyedSearch.done(); cacheSearch.and("store_id", cacheSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ); cacheSearch.and("store_role", cacheSearch.entity().getRole(), SearchCriteria.Op.EQ); cacheSearch.and("state", cacheSearch.entity().getState(), SearchCriteria.Op.NEQ); cacheSearch.and("ref_cnt", cacheSearch.entity().getRefCnt(), SearchCriteria.Op.NEQ); cacheSearch.done(); updateStateSearch.and("id", updateStateSearch.entity().getId(), Op.EQ); updateStateSearch.and("state", updateStateSearch.entity().getState(), Op.EQ); updateStateSearch.and("updatedCount", updateStateSearch.entity().getUpdatedCount(), Op.EQ); updateStateSearch.done(); snapshotSearch.and("snapshot_id", snapshotSearch.entity().getSnapshotId(), SearchCriteria.Op.EQ); snapshotSearch.and("store_role", snapshotSearch.entity().getRole(), SearchCriteria.Op.EQ); snapshotSearch.and("state", snapshotSearch.entity().getState(), SearchCriteria.Op.EQ); snapshotSearch.done(); storeSnapshotSearch.and("snapshot_id", storeSnapshotSearch.entity().getSnapshotId(), SearchCriteria.Op.EQ); storeSnapshotSearch.and("store_id", storeSnapshotSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ); storeSnapshotSearch.and("store_role", storeSnapshotSearch.entity().getRole(), SearchCriteria.Op.EQ);
snapshotSc.and(snapshotSc.entity().getLastUpdated(), SearchCriteria.Op.LT, bef); snapshotSc.and(snapshotSc.entity().getState(), SearchCriteria.Op.EQ, ObjectInDataStoreStateMachine.State.Ready); snapshotSc.and(snapshotSc.entity().getDataStoreId(), SearchCriteria.Op.EQ, store.getId()); snapshotSc.and(snapshotSc.entity().getRole(), SearchCriteria.Op.EQ, store.getRole()); snapshotSc.and(snapshotSc.entity().getRefCnt(), SearchCriteria.Op.EQ, 0); SnapshotDataStoreVO snapshot = snapshotSc.find(); if (snapshot != null) { return snapshotFactory.getSnapshot(snapshot.getSnapshotId(), store);
} else if (obj.getType() == DataObjectType.SNAPSHOT) { SnapshotInfo snapshotInfo = (SnapshotInfo)obj; SnapshotDataStoreVO ss = new SnapshotDataStoreVO(); ss.setSnapshotId(obj.getId()); ss.setDataStoreId(dataStore.getId()); ss.setRole(dataStore.getRole()); ss.setVolumeId(snapshotInfo.getVolumeId()); ss.setSize(snapshotInfo.getSize()); // this is the virtual size of snapshot in primary storage. ss.setPhysicalSize(snapshotInfo.getSize()); // this physical size will get updated with actual size once the snapshot backup is done. SnapshotDataStoreVO snapshotDataStoreVO = snapshotDataStoreDao.findParent(dataStore.getRole(), dataStore.getId(), snapshotInfo.getVolumeId()); if (snapshotDataStoreVO != null) { SnapshotVO parentSnap = snapshotDao.findById(snapshotDataStoreVO.getSnapshotId()); if (parentSnap != null) { ss.setParentSnapshotId(snapshotDataStoreVO.getSnapshotId()); } else { s_logger.debug("find inconsistent db for snapshot " + snapshotDataStoreVO.getSnapshotId()); ss.setState(ObjectInDataStoreStateMachine.State.Allocated); ss = snapshotDataStoreDao.persist(ss); case SNAPSHOT: SnapshotInfo snapshot = (SnapshotInfo)obj; SnapshotDataStoreVO ss = new SnapshotDataStoreVO(); ss.setSnapshotId(obj.getId()); ss.setDataStoreId(dataStore.getId()); ss.setRole(dataStore.getRole()); ss.setSize(snapshot.getSize()); ss.setVolumeId(snapshot.getVolumeId());
@Override public List<SnapshotInfo> listSnapshotOnCache(long snapshotId) { List<SnapshotDataStoreVO> cacheSnapshots = snapshotStoreDao.listOnCache(snapshotId); List<SnapshotInfo> snapObjs = new ArrayList<SnapshotInfo>(); for (SnapshotDataStoreVO cacheSnap : cacheSnapshots) { long storeId = cacheSnap.getDataStoreId(); DataStore store = storeMgr.getDataStore(storeId, DataStoreRole.ImageCache); SnapshotInfo tmplObj = getSnapshot(snapshotId, store); snapObjs.add(tmplObj); } return snapObjs; }
if (parentSnapshotDataStoreVO != null) { SnapshotVO parentSnap = _snapshotDao.findById(parentSnapshotDataStoreVO.getSnapshotId()); if (parentSnap != null && parentSnapshotDataStoreVO.getInstallPath() != null && parentSnapshotDataStoreVO.getInstallPath().equals(vmSnapshot.getName())) { throw new InvalidParameterValueException("Creating snapshot failed due to snapshot : " + parentSnap.getUuid() + " is created from the same vm snapshot"); snapshotInfo = (SnapshotInfo) store.create(snapshotInfo); SnapshotDataStoreVO snapshotOnPrimaryStore = this._snapshotStoreDao.findBySnapshot(snapshot.getId(), store.getRole()); snapshotOnPrimaryStore.setState(ObjectInDataStoreStateMachine.State.Ready); snapshotOnPrimaryStore.setInstallPath(vmSnapshot.getName()); _snapshotStoreDao.update(snapshotOnPrimaryStore.getId(), snapshotOnPrimaryStore); snapshot.setState(Snapshot.State.CreatedOnPrimary); _snapshotDao.update(snapshot.getId(), snapshot);
snapshotSizeSearch.select("sum", Func.SUM, snapshotSizeSearch.entity().getPhysicalSize()); snapshotSizeSearch.and("state", snapshotSizeSearch.entity().getState(), Op.EQ); snapshotSizeSearch.and("storeRole", snapshotSizeSearch.entity().getRole(), Op.EQ); SearchBuilder<SnapshotVO> join2 = _snapshotDao.createSearchBuilder(); join2.and("accountId", join2.entity().getAccountId(), Op.EQ); snapshotSizeSearch.join("snapshots", join2, snapshotSizeSearch.entity().getSnapshotId(), join2.entity().getId(), JoinBuilder.JoinType.INNER); snapshotSizeSearch.done();
for (SnapshotDataStoreVO destroyedSnapshotStoreVO : destroyedSnapshotStoreVOs) { SnapshotInfo snap = snapshotFactory.getSnapshot(destroyedSnapshotStoreVO.getSnapshotId(), store); if (snap.getChild() != null) { s_logger.debug("Skip snapshot on store: " + destroyedSnapshotStoreVO + " , because it has child"); _snapshotDao.remove(destroyedSnapshotStoreVO.getSnapshotId()); SnapshotDataStoreVO snapshotOnPrimary = _snapshotStoreDao.findBySnapshot(destroyedSnapshotStoreVO.getSnapshotId(), DataStoreRole.Primary); if (snapshotOnPrimary != null) { _snapshotStoreDao.remove(snapshotOnPrimary.getId()); _snapshotStoreDao.remove(destroyedSnapshotStoreVO.getId());
private DataStore findSnapshotImageStore(SnapshotInfo snapshot) { Boolean fullSnapshot = true; Boolean snapshotFullBackup = snapshot.getFullBackup(); if (snapshotFullBackup != null) { fullSnapshot = snapshotFullBackup; } if (fullSnapshot) { return dataStoreMgr.getImageStore(snapshot.getDataCenterId()); } else { SnapshotInfo parentSnapshot = snapshot.getParent(); // Note that DataStore information in parentSnapshot is for primary // data store here, we need to // find the image store where the parent snapshot backup is located SnapshotDataStoreVO parentSnapshotOnBackupStore = null; if (parentSnapshot != null) { parentSnapshotOnBackupStore = _snapshotStoreDao.findBySnapshot(parentSnapshot.getId(), DataStoreRole.Image); } if (parentSnapshotOnBackupStore == null) { return dataStoreMgr.getImageStore(snapshot.getDataCenterId()); } return dataStoreMgr.getDataStore(parentSnapshotOnBackupStore.getDataStoreId(), parentSnapshotOnBackupStore.getRole()); } }
if (answer instanceof CreateObjectAnswer) { SnapshotObjectTO snapshotTO = (SnapshotObjectTO)((CreateObjectAnswer)answer).getData(); snapshotStore.setInstallPath(snapshotTO.getPath()); snapshotStoreDao.update(snapshotStore.getId(), snapshotStore); } else if (answer instanceof CopyCmdAnswer) { SnapshotObjectTO snapshotTO = (SnapshotObjectTO)((CopyCmdAnswer)answer).getNewData(); snapshotStore.setInstallPath(snapshotTO.getPath()); if (snapshotTO.getPhysicalSize() != null) { snapshotStore.setPhysicalSize(snapshotTO.getPhysicalSize()); snapshotStore.setParentSnapshotId(0L); snapshotStoreDao.update(snapshotStore.getId(), snapshotStore);
long storagePoolId = snapStoreVo.getDataStoreId(); StoragePoolVO storagePoolVO = storagePoolDao.findById(storagePoolId); _snapshotStoreDao.remove(snapStoreVo.getId()); _snapshotStoreDao.remove(snapStoreVo.getId());
@Override public void cleanupVolumeDuringSnapshotFailure(Long volumeId, Long snapshotId) { SnapshotVO snaphsot = _snapshotDao.findById(snapshotId); if (snaphsot != null) { if (snaphsot.getState() != Snapshot.State.BackedUp) { List<SnapshotDataStoreVO> snapshotDataStoreVOs = _snapshotStoreDao.findBySnapshotId(snapshotId); for (SnapshotDataStoreVO snapshotDataStoreVO : snapshotDataStoreVOs) { s_logger.debug("Remove snapshot " + snapshotId + ", status " + snapshotDataStoreVO.getState() + " on snapshot_store_ref table with id: " + snapshotDataStoreVO.getId()); _snapshotStoreDao.remove(snapshotDataStoreVO.getId()); } s_logger.debug("Remove snapshot " + snapshotId + " status " + snaphsot.getState() + " from snapshot table"); _snapshotDao.remove(snapshotId); } } }
List<SnapshotDataStoreVO> storeRefs = snapshotStoreDao.findBySnapshotId(snapshotId); for (SnapshotDataStoreVO ref : storeRefs) { snapshotStoreDao.expunge(ref.getId()); if (snapshotOnPrimary != null) { SnapshotInfo snapshotOnPrimaryInfo = snapshotDataFactory.getSnapshot(snapshotId, DataStoreRole.Primary); long volumeId = snapshotOnPrimary.getVolumeId(); VolumeVO volumeVO = volumeDao.findById(volumeId); if (((PrimaryDataStoreImpl)snapshotOnPrimaryInfo.getDataStore()).getPoolType() == StoragePoolType.RBD && volumeVO != null) { snapshotSvr.deleteSnapshot(snapshotOnPrimaryInfo); snapshotOnPrimary.setState(State.Destroyed); snapshotStoreDao.update(snapshotOnPrimary.getId(), snapshotOnPrimary);
SnapshotDataStoreVO snapshotDataStoreVO = snapshotStoreDao.findByStoreSnapshot(primaryStore.getRole(), primaryStore.getId(), parentSnapshotId); if (snapshotDataStoreVO != null) { parentSnapshotId = snapshotDataStoreVO.getParentSnapshotId(); UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_OFF_PRIMARY, parent.getAccountId(), parent.getDataCenterId(), parent.getId(), parent.getName(), null, null, 0L, 0L, parent.getClass().getName(), parent.getUuid()); snapshotStoreDao.remove(snapshotDataStoreVO.getId()); } else { parentSnapshotId = null; snapshotDataStoreVO.setParentSnapshotId(0L); snapshotStoreDao.update(snapshotDataStoreVO.getId(), snapshotDataStoreVO);
@Override public void incRefCount() { if (store == null) { return; } if (store.getRole() == DataStoreRole.Image || store.getRole() == DataStoreRole.ImageCache) { SnapshotDataStoreVO store = snapshotStoreDao.findByStoreSnapshot(this.store.getRole(), this.store.getId(), getId()); store.incrRefCnt(); store.setLastUpdated(new Date()); snapshotStoreDao.update(store.getId(), store); } }
@Override public long getObjectId() { return getSnapshotId(); }
@Override public void decRefCount() { if (store == null) { return; } if (store.getRole() == DataStoreRole.Image || store.getRole() == DataStoreRole.ImageCache) { SnapshotDataStoreVO store = snapshotStoreDao.findByStoreSnapshot(this.store.getRole(), this.store.getId(), getId()); store.decrRefCnt(); store.setLastUpdated(new Date()); snapshotStoreDao.update(store.getId(), store); } }