@@ -125,8 +125,6 @@ public class VolumeServiceImpl implements VolumeService {
125125 @ Inject
126126 VMTemplatePoolDao _tmpltPoolDao ;
127127 @ Inject
128- VolumeDao _volumeDao ;
129- @ Inject
130128 EndPointSelector _epSelector ;
131129 @ Inject
132130 HostDao _hostDao ;
@@ -1021,7 +1019,7 @@ protected Void copyVolumeCallBack(AsyncCallbackDispatcher<VolumeServiceImpl, Cop
10211019 }
10221020 srcVolume .processEvent (Event .OperationSuccessed );
10231021 destVolume .processEvent (Event .OperationSuccessed , result .getAnswer ());
1024- _volumeDao .updateUuid (srcVolume .getId (), destVolume .getId ());
1022+ volDao .updateUuid (srcVolume .getId (), destVolume .getId ());
10251023 try {
10261024 destroyVolume (srcVolume .getId ());
10271025 srcVolume = volFactory .getVolume (srcVolume .getId ());
@@ -1226,10 +1224,16 @@ public AsyncCallFuture<VolumeApiResult> registerVolume(VolumeInfo volume, DataSt
12261224
12271225 protected Void registerVolumeCallback (AsyncCallbackDispatcher <VolumeServiceImpl , CreateCmdResult > callback , CreateVolumeContext <VolumeApiResult > context ) {
12281226 CreateCmdResult result = callback .getResult ();
1227+ VolumeObject vo = (VolumeObject )context .volume ;
12291228 try {
1230- VolumeObject vo = (VolumeObject )context .volume ;
12311229 if (result .isFailed ()) {
12321230 vo .processEvent (Event .OperationFailed );
1231+ // delete the volume entry from volumes table in case of failure
1232+ VolumeVO vol = volDao .findById (vo .getId ());
1233+ if (vol != null ) {
1234+ volDao .remove (vo .getId ());
1235+ }
1236+
12331237 } else {
12341238 vo .processEvent (Event .OperationSuccessed , result .getAnswer ());
12351239
@@ -1268,6 +1272,11 @@ protected Void registerVolumeCallback(AsyncCallbackDispatcher<VolumeServiceImpl,
12681272
12691273 } catch (Exception e ) {
12701274 s_logger .error ("register volume failed: " , e );
1275+ // delete the volume entry from volumes table in case of failure
1276+ VolumeVO vol = volDao .findById (vo .getId ());
1277+ if (vol != null ) {
1278+ volDao .remove (vo .getId ());
1279+ }
12711280 VolumeApiResult res = new VolumeApiResult (null );
12721281 context .future .complete (res );
12731282 return null ;
@@ -1303,7 +1312,7 @@ public void resizeVolumeOnHypervisor(long volumeId, long newSize, long destHostI
13031312 EndPoint ep = RemoteHostEndPoint .getHypervisorHostEndPoint (destHost );
13041313
13051314 if (ep != null ) {
1306- VolumeVO volume = _volumeDao .findById (volumeId );
1315+ VolumeVO volume = volDao .findById (volumeId );
13071316 PrimaryDataStore primaryDataStore = this .dataStoreMgr .getPrimaryDataStore (volume .getPoolId ());
13081317 ResizeVolumeCommand resizeCmd = new ResizeVolumeCommand (volume .getPath (), new StorageFilerTO (primaryDataStore ), volume .getSize (), newSize , true , instanceName );
13091318
@@ -1375,7 +1384,7 @@ public void handleVolumeSync(DataStore store) {
13751384 List <VolumeDataStoreVO > dbVolumes = _volumeStoreDao .listByStoreId (storeId );
13761385 List <VolumeDataStoreVO > toBeDownloaded = new ArrayList <VolumeDataStoreVO >(dbVolumes );
13771386 for (VolumeDataStoreVO volumeStore : dbVolumes ) {
1378- VolumeVO volume = _volumeDao .findById (volumeStore .getVolumeId ());
1387+ VolumeVO volume = volDao .findById (volumeStore .getVolumeId ());
13791388 if (volume == null ) {
13801389 s_logger .warn ("Volume_store_ref shows that volume " + volumeStore .getVolumeId () + " is on image store " + storeId +
13811390 ", but the volume is not found in volumes table, potentially some bugs in deleteVolume, so we just treat this volume to be deleted and mark it as destroyed" );
@@ -1420,7 +1429,7 @@ public void handleVolumeSync(DataStore store) {
14201429 if (volume .getSize () == 0 ) {
14211430 // Set volume size in volumes table
14221431 volume .setSize (volInfo .getSize ());
1423- _volumeDao .update (volumeStore .getVolumeId (), volume );
1432+ volDao .update (volumeStore .getVolumeId (), volume );
14241433 }
14251434
14261435 if (volInfo .getSize () > 0 ) {
0 commit comments