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

(cherry picked from commit cd8af6a3e2)
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Min Chen 2014-03-12 15:44:18 -07:00 committed by Rohit Yadav
parent 7332ea8a1c
commit 88ec08439d
3 changed files with 30 additions and 3 deletions

View File

@ -29,6 +29,8 @@ import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.log4j.Logger;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
@ -44,6 +46,8 @@ import com.cloud.utils.fsm.StateObject;
@Entity
@Table(name = "snapshot_store_ref")
public class SnapshotDataStoreVO implements StateObject<ObjectInDataStoreStateMachine.State>, DataObjectInStore {
private static final Logger s_logger = Logger.getLogger(SnapshotDataStoreVO.class);
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
@ -266,7 +270,12 @@ public class SnapshotDataStoreVO implements StateObject<ObjectInDataStoreStateMa
}
public void decrRefCnt() {
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 Long getVolumeId() {

View File

@ -29,6 +29,8 @@ import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.log4j.Logger;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
@ -45,6 +47,8 @@ import com.cloud.utils.fsm.StateObject;
@Entity
@Table(name = "template_store_ref")
public class TemplateDataStoreVO implements StateObject<ObjectInDataStoreStateMachine.State>, DataObjectInStore {
private static final Logger s_logger = Logger.getLogger(TemplateDataStoreVO.class);
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
@ -369,7 +373,12 @@ public class TemplateDataStoreVO implements StateObject<ObjectInDataStoreStateMa
}
public void decrRefCnt() {
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");
}
}
}

View File

@ -29,6 +29,8 @@ import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.log4j.Logger;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
@ -44,6 +46,8 @@ import com.cloud.utils.fsm.StateObject;
@Entity
@Table(name = "volume_store_ref")
public class VolumeDataStoreVO implements StateObject<ObjectInDataStoreStateMachine.State>, DataObjectInStore {
private static final Logger s_logger = Logger.getLogger(VolumeDataStoreVO.class);
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
@ -344,7 +348,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() {