Commit 2154c5b8 authored by Michael Ritter's avatar Michael Ritter
Browse files

Only update a group summary if the collection has changed

parent c750a2d1
......@@ -46,6 +46,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
......@@ -62,16 +63,16 @@ public class CollectionCountContext implements ServletContextListener {
public static final String CTX_STARTUP = "startup_complete";
private static final Logger LOG = Logger.getLogger(
CollectionCountContext.class);
private static Map<Collection, Long> fileCountMap = new HashMap<Collection, Long>();
private static Map<Collection, Long> fileActiveMap = new HashMap<Collection, Long>();
private static Map<Collection, Long> fileCorruptMap = new HashMap<Collection, Long>();
private static Map<Collection, Long> fileMissingMap = new HashMap<Collection, Long>();
private static Map<Collection, Long> fileMissingTokenMap = new HashMap<Collection, Long>();
private static Map<Collection, Long> fileTokenMismatchMap = new HashMap<Collection, Long>();
private static Map<Collection, Long> totalErrorMap = new HashMap<Collection, Long>();
private static Map<Collection, Long> totalSizeMap = new HashMap<Collection, Long>();
private static Map<Collection, Long> fileRemoteMissing = new HashMap<Collection, Long>();
private static Map<Collection, Long> fileRemoteCorrupt = new HashMap<Collection, Long>();
private static Map<Collection, Long> fileCountMap = new HashMap<>();
private static Map<Collection, Long> fileActiveMap = new HashMap<>();
private static Map<Collection, Long> fileCorruptMap = new HashMap<>();
private static Map<Collection, Long> fileMissingMap = new HashMap<>();
private static Map<Collection, Long> fileMissingTokenMap = new HashMap<>();
private static Map<Collection, Long> fileTokenMismatchMap = new HashMap<>();
private static Map<Collection, Long> totalErrorMap = new HashMap<>();
private static Map<Collection, Long> totalSizeMap = new HashMap<>();
private static Map<Collection, Long> fileRemoteMissing = new HashMap<>();
private static Map<Collection, Long> fileRemoteCorrupt = new HashMap<>();
private static AtomicInteger totalCollections = new AtomicInteger(0);
private static Lock lock = new ReentrantLock();
private static boolean abort = false;
......@@ -226,10 +227,11 @@ public class CollectionCountContext implements ServletContextListener {
/**
* Update statistics for a collection.
*
*
* @param c
*/
private static void queryCollection(Collection c) {
private static boolean queryCollection(Collection c) {
boolean update = false;
Connection connection = null;
PreparedStatement ps = null;
ResultSet rs = null;
......@@ -249,14 +251,13 @@ public class CollectionCountContext implements ServletContextListener {
while (rs.next()) {
if (abort) {
return;
return update;
}
char state = rs.getString(1).charAt(0);
long count = rs.getLong(2);
total += count;
switch (state) {
case 'A':
fileActiveMap.put(c, count);
......@@ -288,7 +289,7 @@ public class CollectionCountContext implements ServletContextListener {
}
}
fileCountMap.put(c, total);
update = !Objects.equals(fileCountMap.put(c, total), total);
totalErrorMap.put(c, totalErrors);
SQL.release(rs);
SQL.release(ps);
......@@ -303,8 +304,7 @@ public class CollectionCountContext implements ServletContextListener {
rs = ps.executeQuery();
rs.next();
long totalSize = rs.getLong(1);
totalSizeMap.put(c, totalSize);
update = update | !Objects.equals(totalSizeMap.put(c, totalSize), totalSize);
} catch (Exception e) {
LOG.error("Error starting up, collection count", e);
} finally {
......@@ -312,8 +312,9 @@ public class CollectionCountContext implements ServletContextListener {
SQL.release(ps);
SQL.release(connection);
LOG.trace("Finished count on " + c.getName());
}
return update;
}
public static void updateCollection(final Collection c) {
......@@ -325,8 +326,10 @@ public class CollectionCountContext implements ServletContextListener {
lock.lock();
try {
queryCollection(c);
GroupSummaryContext.updateGroup(c.getGroup());
boolean update = queryCollection(c);
if (update) {
GroupSummaryContext.updateGroup(c.getGroup());
}
} finally {
lock.unlock();
}
......
......@@ -57,6 +57,7 @@ public class GroupSummaryContext implements ServletContextListener {
*/
public static void updateGroup(String group) {
if (group != null) {
log.debug("Updating group summary for " + group);
updateSummaries(
ImmutableList.of(SUMMARY_QUERY, SUMMARY_QUERY_PARAM, SUMMARY_QUERY_END),
ImmutableList.of(group));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment