Author: virag
Date: Fri Jun 28 23:40:14 2013
New Revision: 1497956

URL: http://svn.apache.org/r1497956
Log:
OOZIE-1435 StatusTransitService unnecessarily updates the lastModifiedTime of 
jobs which causes MaterializationService to bring same jobs in memory (virag)

Modified:
    
oozie/trunk/core/src/main/java/org/apache/oozie/service/StatusTransitService.java
    
oozie/trunk/core/src/test/java/org/apache/oozie/service/TestStatusTransitService.java
    oozie/trunk/release-log.txt

Modified: 
oozie/trunk/core/src/main/java/org/apache/oozie/service/StatusTransitService.java
URL: 
http://svn.apache.org/viewvc/oozie/trunk/core/src/main/java/org/apache/oozie/service/StatusTransitService.java?rev=1497956&r1=1497955&r2=1497956&view=diff
==============================================================================
--- 
oozie/trunk/core/src/main/java/org/apache/oozie/service/StatusTransitService.java
 (original)
+++ 
oozie/trunk/core/src/main/java/org/apache/oozie/service/StatusTransitService.java
 Fri Jun 28 23:40:14 2013
@@ -656,14 +656,17 @@ public class StatusTransitService implem
                 }
             }
 
-            checkCoordPending(isPending, coordJob, false);
+            boolean isPendingStateChanged = checkCoordPending(isPending, 
coordJob, false);
             // Check for backward support when RUNNINGWITHERROR, 
SUSPENDEDWITHERROR and PAUSEDWITHERROR is
             // not supported
             
coordJob.setStatus(StatusUtils.getStatusIfBackwardSupportTrue(coordStatus));
             // Backward support when coordinator namespace is 0.1
             coordJob.setStatus(StatusUtils.getStatus(coordJob));
-            coordJob.setLastModifiedTime(new Date());
-            jpaService.execute(new CoordJobUpdateJPAExecutor(coordJob));
+            if (coordJob.getStatus() != prevStatus || isPendingStateChanged) {
+                LOG.debug("Updating coord job " + coordJob.getId());
+                coordJob.setLastModifiedTime(new Date());
+                jpaService.execute(new CoordJobUpdateJPAExecutor(coordJob));
+            }
             // update bundle action only when status changes in coord job
             if (coordJob.getBundleId() != null) {
                 if (!prevStatus.equals(coordJob.getStatus())) {
@@ -673,8 +676,10 @@ public class StatusTransitService implem
             }
         }
 
-        private void checkCoordPending(boolean isPending, CoordinatorJobBean 
coordJob, boolean saveToDB) throws JPAExecutorException {
+        private boolean checkCoordPending(boolean isPending, 
CoordinatorJobBean coordJob, boolean saveToDB)
+                throws JPAExecutorException {
             // Checking the coordinator pending should be updated or not
+            boolean prevPending = coordJob.isPending();
             if (isPending) {
                 coordJob.setPending();
                 LOG.info("Coord job [" + coordJob.getId() + "] Pending set to 
TRUE");
@@ -683,10 +688,12 @@ public class StatusTransitService implem
                 coordJob.resetPending();
                 LOG.info("Coord job [" + coordJob.getId() + "] Pending set to 
FALSE");
             }
-
-            if (saveToDB) {
+            boolean hasChange = prevPending != coordJob.isPending();
+            if (saveToDB && hasChange) {
                 jpaService.execute(new CoordJobUpdateJPAExecutor(coordJob));
             }
+            return hasChange;
+
         }
 
         /**

Modified: 
oozie/trunk/core/src/test/java/org/apache/oozie/service/TestStatusTransitService.java
URL: 
http://svn.apache.org/viewvc/oozie/trunk/core/src/test/java/org/apache/oozie/service/TestStatusTransitService.java?rev=1497956&r1=1497955&r2=1497956&view=diff
==============================================================================
--- 
oozie/trunk/core/src/test/java/org/apache/oozie/service/TestStatusTransitService.java
 (original)
+++ 
oozie/trunk/core/src/test/java/org/apache/oozie/service/TestStatusTransitService.java
 Fri Jun 28 23:40:14 2013
@@ -582,7 +582,25 @@ public class TestStatusTransitService ex
         assertEquals(job.getStatus(), Job.Status.RUNNINGWITHERROR);
     }
 
+    public void testCoordStatusTransitServiceUpdateLastModifiedTime() throws 
Exception {
+        String currentDatePlusMonth = 
XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
+        Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
+        Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
+        CoordinatorJobBean job = 
addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, true, 
false, 3);
+        Date lastModifiedDate = job.getLastModifiedTime();
+        addRecordToCoordActionTable(job.getId(), 1, 
CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 1);
+
+        final JPAService jpaService = Services.get().get(JPAService.class);
+        Runnable runnable = new StatusTransitRunnable();
+        runnable.run();
+        sleep(1000);
 
+        CoordJobGetJPAExecutor coordGetCmd = new 
CoordJobGetJPAExecutor(job.getId());
+        job = jpaService.execute(coordGetCmd);
+        // As state of job has not changed, lastModified should not be updated
+        assertEquals(lastModifiedDate.getTime(), 
job.getLastModifiedTime().getTime());
+        assertEquals(Job.Status.RUNNING, job.getStatus());
+    }
 
     /**
      * Test : all coord actions are running, job pending is reset

Modified: oozie/trunk/release-log.txt
URL: 
http://svn.apache.org/viewvc/oozie/trunk/release-log.txt?rev=1497956&r1=1497955&r2=1497956&view=diff
==============================================================================
--- oozie/trunk/release-log.txt (original)
+++ oozie/trunk/release-log.txt Fri Jun 28 23:40:14 2013
@@ -1,5 +1,6 @@
 -- Oozie 4.1.0 release (trunk - unreleased)
 
+OOZIE-1435 StatusTransitService unnecessarily updates the lastModifiedTime of 
jobs which causes MaterializationService to bring same jobs in memory (virag)
 OOZIE-1433 ActionCheckX should override XCommand.getKey() to prevent 
duplicates (virag)
 OOZIE-1436 Revert SLA_XML and few other varchar columns back to clob (virag)
 OOZIE-1427 Update CredentialsModule docs to mention Hive (rkanter)


Reply via email to