← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20173: Analytics tables, only vacuuming if aggregation levels for data elements exist

 

------------------------------------------------------------
revno: 20173
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-09-15 21:13:33 +0200
message:
  Analytics tables, only vacuuming if aggregation levels for data elements exist
modified:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java	2015-09-15 18:37:01 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java	2015-09-15 19:13:33 +0000
@@ -138,11 +138,6 @@
         createIndexes( tables );
         
         clock.logTime( "Created indexes" );
-        notifier.notify( taskId, "Vacuuming tables" );
-        
-        vacuumTables( tables );
-        
-        clock.logTime( "Vacuumed tables" );
         notifier.notify( taskId, "Swapping analytics tables" );
         
         swapTables( tables, clock, taskId );
@@ -215,11 +210,13 @@
         
         ConcurrentUtils.waitForCompletion( futures );
     }
-        
+    
     private void applyAggregationLevels( List<AnalyticsTable> tables )
     {
         int maxLevels = organisationUnitService.getMaxOfOrganisationUnitLevels();
         
+        boolean hasAggLevels = false;
+        
         levelLoop : for ( int i = 0; i < maxLevels; i++ )
         {
             int level = maxLevels - i;
@@ -231,7 +228,9 @@
             {
                 continue levelLoop;
             }
-                        
+
+            hasAggLevels = true;
+            
             ConcurrentLinkedQueue<AnalyticsTable> tableQ = new ConcurrentLinkedQueue<>( tables );
 
             List<Future<?>> futures = new ArrayList<>();
@@ -243,6 +242,27 @@
 
             ConcurrentUtils.waitForCompletion( futures );
         }
+        
+        if ( hasAggLevels )
+        {
+            vacuumTables( tables );
+
+            log.info( "Vacuumed tables" );
+        }
+    }
+
+    private void vacuumTables( List<AnalyticsTable> tables )
+    {
+        ConcurrentLinkedQueue<AnalyticsTable> tableQ = new ConcurrentLinkedQueue<>( tables );
+        
+        List<Future<?>> futures = new ArrayList<>();
+        
+        for ( int i = 0; i < getProcessNo(); i++ )
+        {
+            tableManager.vacuumTablesAsync( tableQ );
+        }
+        
+        ConcurrentUtils.waitForCompletion( futures );        
     }
     
     private void createIndexes( List<AnalyticsTable> tables )
@@ -271,20 +291,6 @@
         ConcurrentUtils.waitForCompletion( futures );
     }
 
-    private void vacuumTables( List<AnalyticsTable> tables )
-    {
-        ConcurrentLinkedQueue<AnalyticsTable> tableQ = new ConcurrentLinkedQueue<>( tables );
-        
-        List<Future<?>> futures = new ArrayList<>();
-        
-        for ( int i = 0; i < getProcessNo(); i++ )
-        {
-            tableManager.vacuumTablesAsync( tableQ );
-        }
-        
-        ConcurrentUtils.waitForCompletion( futures );        
-    }
-    
     private void swapTables( List<AnalyticsTable> tables, Clock clock, TaskId taskId )
     {
         resourceTableService.dropAllSqlViews();