Skip to content

Commit

Permalink
added better logging for purge.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Jan 30, 2008
1 parent d9e15d3 commit 0aa575f
Showing 1 changed file with 26 additions and 10 deletions.
Expand Up @@ -29,6 +29,7 @@
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jumpmind.symmetric.db.IDbDialect;
Expand Down Expand Up @@ -101,44 +102,53 @@ public void purge() {

private void purgeDataRows() {
int dataIdCount = 0;
int totalCount = 0;
long ts = System.currentTimeMillis();
do {
dataIdCount = (Integer) transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus s) {
public Object doInTransaction(final TransactionStatus s) {
int count = 0;
List<Integer> dataIds = null;
dataIds = getNextDataIds(selectDataIdToPurgeSql, null, maxNumOfDataIdsToPurgeInTx);
for (Integer dataId : dataIds) {
for (final Integer dataId : dataIds) {
count += jdbcTemplate.update(deleteDataSql, new Object[] { dataId });
}
if (count > 0) {
logger.info("Purged " + count + " data rows.");
}
return dataIds.size();
}
});

totalCount += dataIdCount;

if (totalCount > 0 && (System.currentTimeMillis() - ts > DateUtils.MILLIS_PER_MINUTE * 5)) {
logger.info("Purged " + totalCount + " a total of data rows.");
ts = System.currentTimeMillis();
}
} while (dataIdCount > 0);

logger.info("Purged " + totalCount + " data rows.");

}

@SuppressWarnings("unchecked")
private void purgeBatchesOlderThan(Calendar time) {
private void purgeBatchesOlderThan(final Calendar time) {
// Iterate over batch ids and data events to access by primary key so we prevent lock escalation
List<Integer> batchIds = jdbcTemplate.queryForList(selectOutgoingBatchIdsToPurgeSql, new Object[] { time
final List<Integer> batchIds = jdbcTemplate.queryForList(selectOutgoingBatchIdsToPurgeSql, new Object[] { time
.getTime() }, Integer.class);
int eventRowCount = 0;
int dataIdCount = 0;
long ts = System.currentTimeMillis();
for (final Integer batchId : batchIds) {
do {
dataIdCount = (Integer) transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus s) {
public Object doInTransaction(final TransactionStatus s) {
jdbcTemplate.update(deleteFromOutgoingBatchHistSql, new Object[] { batchId });

int eventCount = 0;
List<Integer> dataIds = null;
dataIds = getNextDataIds(selectEventDataIdToPurgeSql, new Object[] { batchId },
maxNumOfDataIdsToPurgeInTx);

for (Integer dataId : dataIds) {
for (final Integer dataId : dataIds) {
eventCount += jdbcTemplate.update(deleteDataEventSql, new Object[] { dataId, batchId });
}

Expand All @@ -147,6 +157,12 @@ public Object doInTransaction(TransactionStatus s) {
}
});
eventRowCount += dataIdCount;

if (System.currentTimeMillis() - ts > DateUtils.MILLIS_PER_MINUTE * 5) {
logger.info("Purged " + batchIds.size() + " a total of batches and " + eventRowCount
+ " data_events.");
ts = System.currentTimeMillis();
}
} while (dataIdCount > 0);

}
Expand Down Expand Up @@ -185,7 +201,7 @@ public Object doInConnection(Connection conn) throws SQLException, DataAccessExc
}

private String cleanSql(String sql) {
return StringUtils.replace(StringUtils.replace(StringUtils.replace(sql, "\r", " "),"\n"," "), " ", "");
return StringUtils.replace(StringUtils.replace(StringUtils.replace(sql, "\r", " "), "\n", " "), " ", "");
}

public void setOtherPurgeSql(String[] purgeSql) {
Expand Down

0 comments on commit 0aa575f

Please sign in to comment.