Skip to content

Commit

Permalink
Added a statistics purge method to the purge service.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed May 24, 2008
1 parent 4691e46 commit 902d957
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
Expand Up @@ -20,5 +20,5 @@
package org.jumpmind.symmetric.service;

public enum LockAction {
PUSH, PULL, PURGE_OUTGOING, PURGE_INCOMING, HEARTBEAT, SYNCTRIGGERS, OTHER
PUSH, PULL, PURGE_OUTGOING, PURGE_INCOMING, PURGE_STATISTICS, HEARTBEAT, SYNCTRIGGERS, OTHER
}
Expand Up @@ -62,10 +62,31 @@ public class PurgeService extends AbstractService implements IPurgeService {
public void purge() {
Calendar retentionCutoff = Calendar.getInstance();
retentionCutoff.add(Calendar.MINUTE, -retentionInMinutes);

purgeOutgoing(retentionCutoff);
purgeIncoming(retentionCutoff);
purgeStatistic(retentionCutoff);
}

private void purgeStatistic(Calendar retentionCutoff) {
try {
if (clusterService.lock(LockAction.PURGE_STATISTICS)) {
try {
logger.info("The statistic purge process is about to run.");
int count = jdbcTemplate.update(
getSql("deleteFromStatisticSql"),
new Object[] { retentionCutoff.getTime() });
logger.info("Purged " + count + " statistic rows.");
} finally {
clusterService.unlock(LockAction.PURGE_STATISTICS);
logger.info("The statistic purge process has completed.");
}

} else {
logger.info("Could not get a lock to run an statistic purge.");
}
} catch (Exception ex) {
logger.error(ex, ex);
}
}

private void purgeOutgoing(Calendar retentionCutoff) {
Expand Down
5 changes: 4 additions & 1 deletion symmetric/src/main/resources/ddl-config.xml
Expand Up @@ -271,9 +271,12 @@
<column name="statistic_count" type="BIGINT" />
<column name="capture_start_time" type="TIMESTAMP" />
<column name="capture_end_time" type="TIMESTAMP" />
<index name="idx_statistic">
<index name="idx_stat">
<index-column name="node_id" />
<index-column name="statistic_name" />
</index>
<index name="idx_stat_end_time">
<index-column name="capture_end_time" />
</index>
</table>

Expand Down
5 changes: 5 additions & 0 deletions symmetric/src/main/resources/sql/purge-service-sql.xml
Expand Up @@ -43,6 +43,11 @@
select batch_id, node_id, status, create_time from ${sync.table.prefix}_incoming_batch order
by create_time asc
</value>
</entry>
<entry key="deleteFromStatisticSql">
<value>
delete from ${sync.table.prefix}_statistic where capture_end_time &lt; ?
</value>
</entry>
</util:map>

Expand Down

0 comments on commit 902d957

Please sign in to comment.