CLOUDSTACK-6236:Negative ref_cnt of template(snapshot/volume)_store_ref results 
in out-of-range error in Mysql

(cherry picked from commit cd8af6a3e2a180ea4d2cfea8a273dbb0929e0a87)
Signed-off-by: Rohit Yadav <rohit.ya...@shapeblue.com>

Conflicts:
        
engine/schema/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreVO.java


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/38bc20e6
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/38bc20e6
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/38bc20e6

Branch: refs/heads/4.4
Commit: 38bc20e67fe8324442e802a41e34564607e30535
Parents: e9d079a
Author: Min Chen <min.c...@citrix.com>
Authored: Wed Mar 12 15:44:18 2014 -0700
Committer: Rohit Yadav <rohit.ya...@shapeblue.com>
Committed: Thu Dec 11 20:47:57 2014 +0530

----------------------------------------------------------------------
 .../cloudstack/storage/datastore/db/VolumeDataStoreVO.java    | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/38bc20e6/engine/schema/src/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreVO.java
----------------------------------------------------------------------
diff --git 
a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreVO.java
 
b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreVO.java
index 91d4ef7..be6a6ad 100755
--- 
a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreVO.java
+++ 
b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreVO.java
@@ -350,7 +350,12 @@ public class VolumeDataStoreVO implements 
StateObject<ObjectInDataStoreStateMach
     }
 
     public void setRefCnt(Long refCnt) {
-        this.refCnt = refCnt;
+        if (refCnt > 0) {
+            refCnt--;
+        }
+        else {
+            s_logger.warn("We should not try to decrement a zero reference 
count even though our code has guarded");
+        }
     }
 
     public void incrRefCnt() {

Reply via email to