@@ -48,19 +48,23 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO
4848 private SearchBuilder <SnapshotDataStoreVO > updateStateSearch ;
4949 private SearchBuilder <SnapshotDataStoreVO > storeSearch ;
5050 private SearchBuilder <SnapshotDataStoreVO > destroyedSearch ;
51+ private SearchBuilder <SnapshotDataStoreVO > cacheSearch ;
5152 private SearchBuilder <SnapshotDataStoreVO > snapshotSearch ;
5253 private SearchBuilder <SnapshotDataStoreVO > storeSnapshotSearch ;
5354 private String parentSearch = "select store_id, store_role, snapshot_id from cloud.snapshot_store_ref where store_id = ? " +
54- " and store_role = ? and volume_id = ? and state = 'Ready'" +
55- " order by created DESC " +
56- " limit 1" ;
55+ " and store_role = ? and volume_id = ? and state = 'Ready'" +
56+ " order by created DESC " +
57+ " limit 1" ;
5758
5859
5960
6061 @ Override
6162 public boolean configure (String name , Map <String , Object > params ) throws ConfigurationException {
6263 super .configure (name , params );
6364
65+ // Note that snapshot_store_ref stores snapshots on primary as well as
66+ // those on secondary, so we need to
67+ // use (store_id, store_role) to search
6468 storeSearch = createSearchBuilder ();
6569 storeSearch .and ("store_id" , storeSearch .entity ().getDataStoreId (), SearchCriteria .Op .EQ );
6670 storeSearch .and ("store_role" , storeSearch .entity ().getRole (), SearchCriteria .Op .EQ );
@@ -72,6 +76,13 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
7276 destroyedSearch .and ("state" , destroyedSearch .entity ().getState (), SearchCriteria .Op .EQ );
7377 destroyedSearch .done ();
7478
79+ cacheSearch = createSearchBuilder ();
80+ cacheSearch .and ("store_id" , cacheSearch .entity ().getDataStoreId (), SearchCriteria .Op .EQ );
81+ cacheSearch .and ("store_role" , cacheSearch .entity ().getRole (), SearchCriteria .Op .EQ );
82+ cacheSearch .and ("state" , cacheSearch .entity ().getState (), SearchCriteria .Op .NEQ );
83+ cacheSearch .and ("ref_cnt" , cacheSearch .entity ().getRefCnt (), SearchCriteria .Op .NEQ );
84+ cacheSearch .done ();
85+
7586 updateStateSearch = this .createSearchBuilder ();
7687 updateStateSearch .and ("id" , updateStateSearch .entity ().getId (), Op .EQ );
7788 updateStateSearch .and ("state" , updateStateSearch .entity ().getState (), Op .EQ );
@@ -115,14 +126,14 @@ public boolean updateState(State currentState, Event event, State nextState, Dat
115126 if (dbVol != null ) {
116127 StringBuilder str = new StringBuilder ("Unable to update " ).append (dataObj .toString ());
117128 str .append (": DB Data={id=" ).append (dbVol .getId ()).append ("; state=" ).append (dbVol .getState ())
118- .append ("; updatecount=" ).append (dbVol .getUpdatedCount ()).append (";updatedTime=" )
119- .append (dbVol .getUpdated ());
129+ .append ("; updatecount=" ).append (dbVol .getUpdatedCount ()).append (";updatedTime=" )
130+ .append (dbVol .getUpdated ());
120131 str .append (": New Data={id=" ).append (dataObj .getId ()).append ("; state=" ).append (nextState )
121- .append ("; event=" ).append (event ).append ("; updatecount=" ).append (dataObj .getUpdatedCount ())
122- .append ("; updatedTime=" ).append (dataObj .getUpdated ());
132+ .append ("; event=" ).append (event ).append ("; updatecount=" ).append (dataObj .getUpdatedCount ())
133+ .append ("; updatedTime=" ).append (dataObj .getUpdated ());
123134 str .append (": stale Data={id=" ).append (dataObj .getId ()).append ("; state=" ).append (currentState )
124- .append ("; event=" ).append (event ).append ("; updatecount=" ).append (oldUpdated )
125- .append ("; updatedTime=" ).append (oldUpdatedTime );
135+ .append ("; event=" ).append (event ).append ("; updatecount=" ).append (oldUpdated )
136+ .append ("; updatedTime=" ).append (oldUpdatedTime );
126137 } else {
127138 s_logger .debug ("Unable to update objectIndatastore: id=" + dataObj .getId ()
128139 + ", as there is no such object exists in the database anymore" );
@@ -140,9 +151,10 @@ public List<SnapshotDataStoreVO> listByStoreId(long id, DataStoreRole role) {
140151 }
141152
142153 @ Override
143- public void deletePrimaryRecordsForStore (long id ) {
154+ public void deletePrimaryRecordsForStore (long id , DataStoreRole role ) {
144155 SearchCriteria <SnapshotDataStoreVO > sc = storeSearch .create ();
145156 sc .setParameters ("store_id" , id );
157+ sc .setParameters ("store_role" , role );
146158 Transaction txn = Transaction .currentTxn ();
147159 txn .start ();
148160 remove (sc );
@@ -176,7 +188,7 @@ public SnapshotDataStoreVO findParent(DataStoreRole role, Long storeId, Long vol
176188 return this .findByStoreSnapshot (role , sid , snid );
177189 }
178190 } catch (SQLException e ) {
179- s_logger .debug ("Failed to find parent snapshot: " + e .toString ());
191+ s_logger .debug ("Failed to find parent snapshot: " + e .toString ());
180192 } finally {
181193 txn .close ();
182194 }
@@ -199,4 +211,14 @@ public List<SnapshotDataStoreVO> listDestroyed(long id) {
199211 sc .setParameters ("state" , ObjectInDataStoreStateMachine .State .Destroyed );
200212 return listBy (sc );
201213 }
214+
215+ @ Override
216+ public List <SnapshotDataStoreVO > listActiveOnCache (long id ) {
217+ SearchCriteria <SnapshotDataStoreVO > sc = cacheSearch .create ();
218+ sc .setParameters ("store_id" , id );
219+ sc .setParameters ("store_role" , DataStoreRole .ImageCache );
220+ sc .setParameters ("state" , ObjectInDataStoreStateMachine .State .Destroyed );
221+ sc .setParameters ("ref_cnt" , 0 );
222+ return listBy (sc );
223+ }
202224}
0 commit comments