Fix deadlock in device application list update

reporting
Charitha Goonetilleke 5 years ago
parent 311ddc307e
commit dac5c2b511

@ -2650,7 +2650,8 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
int deviceCount = 0;
try {
conn = this.getConnection();
String sql = "SELECT COUNT(e.DEVICE_ID) AS DEVICE_COUNT FROM DM_ENROLMENT e WHERE STATUS != 'REMOVED'";
String sql = "SELECT COUNT(e.DEVICE_ID) AS DEVICE_COUNT FROM DM_ENROLMENT e WHERE STATUS = 'ACTIVE' " +
"OR STATUS = 'UNREACHABLE'";
stmt = conn.prepareStatement(sql);
ResultSet rs = stmt.executeQuery();

@ -88,7 +88,7 @@ public class ApplicationDAOImpl implements ApplicationDAO {
conn = this.getConnection();
stmt = conn.prepareStatement("UPDATE DM_APPLICATION SET NAME = ?, PLATFORM = ?, CATEGORY = ?, " +
"VERSION = ?, TYPE = ?, LOCATION_URL = ?, IMAGE_URL = ?, MEMORY_USAGE = ?, IS_ACTIVE = ? " +
"WHERE APP_IDENTIFIER = ? AND DEVICE_ID = ? AND ENROLMENT_ID = ? AND TENANT_ID = ?");
"WHERE ID = ?");
for (Application application : applications) {
stmt.setString(1, application.getName());
@ -100,10 +100,7 @@ public class ApplicationDAOImpl implements ApplicationDAO {
stmt.setString(7, application.getImageUrl());
stmt.setInt(8, application.getMemoryUsage());
stmt.setBoolean(9, application.isActive());
stmt.setString(10, application.getApplicationIdentifier());
stmt.setInt(11, deviceId);
stmt.setInt(12, enrolmentId);
stmt.setInt(13, tenantId);
stmt.setInt(10, application.getId());
stmt.addBatch();
}
stmt.executeBatch();
@ -123,14 +120,10 @@ public class ApplicationDAOImpl implements ApplicationDAO {
try {
conn = this.getConnection();
conn.setAutoCommit(false);
stmt = conn.prepareStatement("DELETE FROM DM_APPLICATION WHERE APP_IDENTIFIER = ? AND DEVICE_ID = ? " +
"AND ENROLMENT_ID = ? AND TENANT_ID = ?");
stmt = conn.prepareStatement("DELETE FROM DM_APPLICATION WHERE ID = ?");
for (Application app : apps) {
stmt.setString(1, app.getApplicationIdentifier());
stmt.setInt(2, deviceId);
stmt.setInt(3, enrolmentId);
stmt.setInt(4, tenantId);
stmt.setInt(1, app.getId());
stmt.addBatch();
}
stmt.executeBatch();

@ -834,13 +834,14 @@ public class OperationManagerImpl implements OperationManager {
public void updateOperation(int enrolmentId, Operation operation, DeviceIdentifier deviceId)
throws OperationManagementException {
int operationId = operation.getId();
boolean isOperationUpdated = false;
try {
OperationManagementDAOFactory.beginTransaction();
if (operation.getStatus() != null) {
int failAttempts = 0;
while (true) {
try {
operationDAO.updateOperationStatus(enrolmentId, operationId,
isOperationUpdated = operationDAO.updateOperationStatus(enrolmentId, operationId,
org.wso2.carbon.device.mgt.core.dto.operation.mgt.
Operation.Status.valueOf(operation.getStatus().
toString()));
@ -865,7 +866,10 @@ public class OperationManagerImpl implements OperationManager {
}
}
}
if (operation.getOperationResponse() != null) {
if (!isOperationUpdated) {
log.warn("Operation " + operationId + "'s status is not updated");
}
if (isOperationUpdated && operation.getOperationResponse() != null) {
OperationMonitoringTaskConfig operationMonitoringTaskConfig = DeviceManagementDataHolder
.getInstance().getDeviceManagementProvider().getDeviceMonitoringConfig(deviceId.getType());
List<MonitoringOperation> monitoringOperations = operationMonitoringTaskConfig.getMonitoringOperation();
@ -901,7 +905,7 @@ public class OperationManagerImpl implements OperationManager {
}
}
OperationResponseMeta responseMeta = null;
if (operation.getOperationResponse() != null) {
if (isOperationUpdated && operation.getOperationResponse() != null) {
int failAttempts = 0;
while (true) {
try {

@ -182,6 +182,9 @@ CREATE TABLE DM_DEVICE_OPERATION_RESPONSE (
DM_ENROLMENT_OP_MAPPING (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
IF NOT EXISTS (SELECT * FROM SYS.INDEXES WHERE NAME = 'IDX_DM_RES_RT' AND OBJECT_ID = OBJECT_ID('DM_DEVICE_OPERATION_RESPONSE'))
CREATE INDEX IDX_DM_RES_RT ON DM_DEVICE_OPERATION_RESPONSE(RECEIVED_TIMESTAMP);
IF NOT EXISTS (SELECT * FROM SYS.INDEXES WHERE NAME = 'IDX_ENID_OPID' AND OBJECT_ID = OBJECT_ID('DM_DEVICE_OPERATION_RESPONSE'))
CREATE INDEX IDX_ENID_OPID ON DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID, ENROLMENT_ID);
@ -190,11 +193,12 @@ CREATE INDEX IDX_DM_EN_OP_MAP_RES ON DM_DEVICE_OPERATION_RESPONSE(EN_OP_MAP_ID);
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_OPERATION_RESPONSE_LARGE]') AND TYPE IN (N'U'))
CREATE TABLE DM_DEVICE_OPERATION_RESPONSE_LARGE (
ID INTEGER IDENTITY(1,1) NOT NULL,
ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL,
EN_OP_MAP_ID INTEGER NOT NULL,
OPERATION_RESPONSE VARBINARY(MAX) DEFAULT NULL,
RECEIVED_TIMESTAMP DATETIME2 DEFAULT NULL
RECEIVED_TIMESTAMP DATETIME2 DEFAULT NULL,
DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL
PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_OPERATION_RESP_LARGE_OPERATION FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
@ -419,6 +423,9 @@ CREATE TABLE DM_APPLICATION (
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
IF NOT EXISTS (SELECT * FROM SYS.INDEXES WHERE NAME = 'IDX_DM_APPLICATION' AND OBJECT_ID = OBJECT_ID('DM_APPLICATION'))
CREATE INDEX IDX_DM_APPLICATION ON DM_APPLICATION(DEVICE_ID, ENROLMENT_ID, TENANT_ID);
-- POLICY RELATED TABLES FINISHED --
-- POLICY AND DEVICE GROUP MAPPING --

@ -439,6 +439,8 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION (
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
)ENGINE = InnoDB;
CREATE INDEX IDX_DM_APPLICATION ON DM_APPLICATION(DEVICE_ID, ENROLMENT_ID, TENANT_ID);
-- END OF POLICY RELATED TABLES --
-- POLICY AND DEVICE GROUP MAPPING --

Loading…
Cancel
Save