Search in sources :

Example 26 with SnapshotDataStoreVO

use of com.cloud.storage.datastore.db.SnapshotDataStoreVO in project cosmic by MissionCriticalCloud.

the class SnapshotObject method getPhysicalSize.

@Override
public long getPhysicalSize() {
    long physicalSize = 0;
    final SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findBySnapshot(snapshot.getId(), DataStoreRole.Image);
    if (snapshotStore != null) {
        physicalSize = snapshotStore.getPhysicalSize();
    }
    return physicalSize;
}
Also used : SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO)

Example 27 with SnapshotDataStoreVO

use of com.cloud.storage.datastore.db.SnapshotDataStoreVO in project cosmic by MissionCriticalCloud.

the class SnapshotServiceImpl method cleanupVolumeDuringSnapshotFailure.

@Override
public void cleanupVolumeDuringSnapshotFailure(final Long volumeId, final Long snapshotId) {
    final SnapshotVO snaphsot = _snapshotDao.findById(snapshotId);
    if (snaphsot != null) {
        if (snaphsot.getState() != Snapshot.State.BackedUp) {
            final List<SnapshotDataStoreVO> snapshotDataStoreVOs = _snapshotStoreDao.findBySnapshotId(snapshotId);
            for (final 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);
        }
    }
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO)

Example 28 with SnapshotDataStoreVO

use of com.cloud.storage.datastore.db.SnapshotDataStoreVO in project cosmic by MissionCriticalCloud.

the class SnapshotDataStoreDaoImpl method updateState.

@Override
public boolean updateState(final State currentState, final Event event, final State nextState, final DataObjectInStore vo, final Object data) {
    final SnapshotDataStoreVO dataObj = (SnapshotDataStoreVO) vo;
    final Long oldUpdated = dataObj.getUpdatedCount();
    final Date oldUpdatedTime = dataObj.getUpdated();
    final SearchCriteria<SnapshotDataStoreVO> sc = updateStateSearch.create();
    sc.setParameters("id", dataObj.getId());
    sc.setParameters("state", currentState);
    sc.setParameters("updatedCount", dataObj.getUpdatedCount());
    dataObj.incrUpdatedCount();
    final UpdateBuilder builder = getUpdateBuilder(dataObj);
    builder.set(dataObj, "state", nextState);
    builder.set(dataObj, "updated", new Date());
    final int rows = update(dataObj, sc);
    if (rows == 0 && s_logger.isDebugEnabled()) {
        final SnapshotDataStoreVO dbVol = findByIdIncludingRemoved(dataObj.getId());
        if (dbVol != null) {
            final 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(event).append("; updatecount=").append(dataObj.getUpdatedCount()).append("; updatedTime=").append(dataObj.getUpdated());
            str.append(": stale Data={id=").append(dataObj.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatecount=").append(oldUpdated).append("; updatedTime=").append(oldUpdatedTime);
        } else {
            s_logger.debug("Unable to update objectIndatastore: id=" + dataObj.getId() + ", as there is no such object exists in the database anymore");
        }
    }
    return rows > 0;
}
Also used : SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO) UpdateBuilder(com.cloud.utils.db.UpdateBuilder) Date(java.util.Date)

Example 29 with SnapshotDataStoreVO

use of com.cloud.storage.datastore.db.SnapshotDataStoreVO in project cosmic by MissionCriticalCloud.

the class SnapshotDataStoreDaoImpl method duplicateCacheRecordsOnRegionStore.

@Override
public void duplicateCacheRecordsOnRegionStore(final long storeId) {
    // find all records on image cache
    final SearchCriteria<SnapshotDataStoreVO> sc = storeSnapshotSearch.create();
    sc.setParameters("store_role", DataStoreRole.ImageCache);
    sc.setParameters("destroyed", false);
    final List<SnapshotDataStoreVO> snapshots = listBy(sc);
    // create an entry for each record, but with empty install path since the content is not yet on region-wide store yet
    if (snapshots != null) {
        s_logger.info("Duplicate " + snapshots.size() + " snapshot cache store records to region store");
        for (final SnapshotDataStoreVO snap : snapshots) {
            final 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);
            final 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);
            // increase ref_cnt so that this will not be recycled before the content is pushed to region-wide store
            snap.incrRefCnt();
            update(snap.getId(), snap);
        }
    }
}
Also used : SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO)

Example 30 with SnapshotDataStoreVO

use of com.cloud.storage.datastore.db.SnapshotDataStoreVO in project cosmic by MissionCriticalCloud.

the class SnapshotDataStoreDaoImpl method deleteSnapshotRecordsOnPrimary.

@Override
public void deleteSnapshotRecordsOnPrimary() {
    final SearchCriteria<SnapshotDataStoreVO> sc = storeSearch.create();
    sc.setParameters("store_role", DataStoreRole.Primary);
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    remove(sc);
    txn.commit();
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO)

Aggregations

SnapshotDataStoreVO (com.cloud.storage.datastore.db.SnapshotDataStoreVO)34 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)12 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)10 SnapshotInfo (com.cloud.engine.subsystem.api.storage.SnapshotInfo)9 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)9 SnapshotVO (com.cloud.storage.SnapshotVO)8 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)8 TemplateDataStoreVO (com.cloud.storage.datastore.db.TemplateDataStoreVO)6 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)5 Date (java.util.Date)5 ConfigurationException (javax.naming.ConfigurationException)5 SnapshotStrategy (com.cloud.engine.subsystem.api.storage.SnapshotStrategy)4 DB (com.cloud.utils.db.DB)4 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)3 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)3 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)3 VolumeVO (com.cloud.storage.VolumeVO)3 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)3 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)2 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)2