Bladeren bron

sig-todp: batchupdate log add

hante 6 maanden geleden
bovenliggende
commit
9b7c274d2b

+ 41 - 7
sig-todp-server/src/main/java/com/sig/todp/server/dao/mapper/BatchDaoService.java

@@ -6,6 +6,8 @@ import org.apache.ibatis.session.ExecutorType;
 import org.apache.ibatis.session.SqlSession;
 import org.apache.ibatis.session.SqlSessionFactory;
 
+import java.sql.SQLException;
+import java.sql.SQLTransientConnectionException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -24,10 +26,6 @@ public abstract class BatchDaoService {
         this.sqlSessionFactory = sqlSessionFactory;
     }
 
-    public int getCount() {
-        return this.count;
-    }
-
     public int execute(String mapperName) {
         int total = 0;
         SqlSession sqlSession = null;
@@ -73,7 +71,27 @@ public abstract class BatchDaoService {
         return this.count;
     }
 
-    public int updateBatch(String mapperName, List<HashMap<String, Object>> lists) {
+    public void dbExceptionHandler(String mapperName, Exception e) {
+        log.error("[BATCH--DAO] {}:updateBatch: {}: Transaction exception: {}", this.serviceName, mapperName, e.getMessage());
+        if (e instanceof NullPointerException) {
+            log.error("[BATCH--DAO] {}:updateBatch: {}: Transaction exception: {}", this.serviceName, mapperName, e.getMessage());
+        }
+        else if (e instanceof SQLException) {
+            SQLException sqlException = (SQLException)e;
+            int sqlCode = sqlException.getErrorCode();
+            if (sqlCode == 60) {
+                log.error("[BATCH--DAO] {}:updateBatch: {}: Deadlock detected: {}", this.serviceName, mapperName, sqlException.getMessage());
+            }
+            else if (e instanceof SQLTransientConnectionException) {
+                log.error("[BATCH--DAO] {}:updateBatch: {}: Connection is not available. SQLException: {}", this.serviceName, mapperName, e.getMessage());
+            }
+            else {
+                log.error("[BATCH--DAO] {}:updateBatch: {}: SQLException: {}", this.serviceName, mapperName, e.getMessage());
+            }
+        }
+    }
+
+    public int updateBatch(String mapperName, List<HashMap<String, Object>> lists) throws Exception {
         int total = lists.size();
         if (total == 0) {
             log.info("[BATCH--DAO] {}:updateBatch: {}: No Data.", this.serviceName, mapperName);
@@ -81,6 +99,7 @@ public abstract class BatchDaoService {
         }
         int jobCnt = 0;
         SqlSession sqlSession = null;
+        boolean success = false;
         try {
             sqlSession = this.sqlSessionFactory.openSession(ExecutorType.BATCH, false);
             for (Map<String, Object> param : lists) {
@@ -91,11 +110,26 @@ public abstract class BatchDaoService {
                     sqlSession.clearCache();
                 }
             }
+            success = true;
+        }
+        catch (Exception e) {
+            dbExceptionHandler(mapperName, e);
+            throw e;
         }
         finally {
             if (sqlSession != null) {
-                sqlSession.commit();
-                sqlSession.close();
+                try {
+                    if (success) {
+                        sqlSession.commit();
+                    }
+                    else {
+                        log.error("[BATCH--DAO] {}:updateBatch: {}: Roll back the transaction due to an error.", this.serviceName, mapperName);
+                        sqlSession.rollback();
+                    }
+                }
+                finally {
+                    sqlSession.close();
+                }
             }
         }
         this.count = total;

+ 15 - 4
sig-todp-server/src/main/java/com/sig/todp/server/dao/mapper/batch/SigTodpServerDao.java

@@ -17,18 +17,29 @@ public class SigTodpServerDao extends BatchDaoService {
         this.serviceName = "SigTodpServerDao";
     }
 
-    public int updateIntSimulationSend(List<HashMap<String, Object>> req) {
+    public int updateIntSimulationSend(List<HashMap<String, Object>> req) throws Exception {
 //        log.info("{}.updateIntSimulationSend: START. {} EA", this.serviceName, req.size());
 //        Elapsed elapsed = new Elapsed();
-        int total = updateBatch("updateIntSimulationSend", req);
+        int total = 0;
+        try {
+            total = updateBatch("updateIntSimulationSend", req);
+        } catch (Exception e) {
+            throw e;
+        }
 //        log.info("{}.updateIntSimulationSend: ..END. {} EA. {} ms.", this.serviceName, total, elapsed.milliSeconds());
         return total;
     }
 
-    public int updateIntSimulationSendTrans(List<HashMap<String, Object>> req) {
+    public int updateIntSimulationSendTrans(List<HashMap<String, Object>> req) throws Exception {
 //        log.info("{}.updateIntSimulationSendTrans: START. {} EA", this.serviceName, req.size());
 //        Elapsed elapsed = new Elapsed();
-        int total = updateBatch("updateIntSimulationSendTrans", req);
+        int total = 0;
+        try {
+            total = updateBatch("updateIntSimulationSendTrans", req);
+        }
+        catch (Exception e) {
+            throw e;
+        }
 //        log.info("{}.updateIntSimulationSendTrans: ..END. {} EA. {} ms.", this.serviceName, total, elapsed.milliSeconds());
         return total;
     }

+ 14 - 13
sig-todp-server/src/main/java/com/sig/todp/server/process/dbms/DbmsDataProcess.java

@@ -82,10 +82,10 @@ public class DbmsDataProcess {
     }
 
     public void process(DbmsData data) {
-        int result1 = -1;
-        int result2 = -1;
+        int result1 = 0;
         long elapsedTime1 = 0;
-        long elapsedTime2 = 0;
+//        int result2 = -1;
+//        long elapsedTime2 = 0;
         int type = -1;
         int count = 0;
         RegionCenter center = data.getCenter();
@@ -109,22 +109,23 @@ public class DbmsDataProcess {
                         elapsedTime1 = elapsed1.milliSeconds();
                     }
                     // TOD 데이터 무조건 업데이트
-                    elapsed1.reset();
-                    try {
-                        result2 = this.sigTodpServerDao.updateIntSimulationSendTrans(intTypeLists);
-                    }
-                    catch (Exception e) {
-                        log.error("DbmsJobProcess.process: [{}]. {}, updateIntSimulationSendTrans, Exception: {}", center.getLogKey(), type, e.getMessage());
-                    }
-                    elapsedTime2 = elapsed1.milliSeconds();
+//                    elapsed1.reset();
+//                    try {
+//                        result2 = this.sigTodpServerDao.updateIntSimulationSendTrans(intTypeLists);
+//                    }
+//                    catch (Exception e) {
+//                        log.error("DbmsJobProcess.process: [{}]. {}, updateIntSimulationSendTrans, Exception: {}", center.getLogKey(), type, e.getMessage());
+//                    }
+//                    elapsedTime2 = elapsed1.milliSeconds();
                     break;
 
                 default:
                     log.error("DbmsJobProcess.process: Unknown Request {}.", type);
                     break;
             }
-            log.info("DbmsDataProcess.run: [{}]. Request: {}, updateIntSimulationSend({} EA. {} ms.), updateIntSimulationSendTrans({} EA. {} ms.)",
-                    center.getLogKey(), count, result1, elapsedTime1, result2, elapsedTime2);
+//            log.info("DbmsDataProcess.run: [{}]. Request: {}, updateIntSimulationSend({} EA. {} ms.), updateIntSimulationSendTrans({} EA. {} ms.)",
+//                    center.getLogKey(), count, result1, elapsedTime1, result2, elapsedTime2);
+            log.info("DbmsDataProcess.run: [{}]. Request: {}, updateIntSimulationSend({} EA. {} ms.),", center.getLogKey(), count, result1, elapsedTime1);
         }
         finally {
             MDC.remove(center.getLogKey());