Skip to content

Commit

Permalink
0003174: Purge should clean up abandoned sym_data_event rows
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Jun 30, 2017
1 parent 11885a4 commit f7a4d44
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Expand Up @@ -211,6 +211,7 @@ private long purgeDataRows(final Calendar time) {
private long[] queryForMinMax(String sql, Object... params) {
long[] minMax = sqlTemplate.queryForObject(sql, new ISqlRowMapper<long[]>() {
public long[] mapRow(Row rs) {
// Max - 1 so we always leave 1 row behind, which keeps MySQL autoinc from resetting
return new long[] { rs.getLong("min_id"), rs.getLong("max_id")-1 };
}
}, params);
Expand Down
Expand Up @@ -122,7 +122,7 @@ public PurgeServiceSqlMap(IDatabasePlatform platform, Map<String, String> replac
"delete from $(data_event) " +
"where data_id between ? and ? " +
"and create_time < ? " +
"where batch_id not in (select batch_id from $(outgoing_batch))");
"and batch_id not in (select batch_id from $(outgoing_batch))");

}

Expand Down
Expand Up @@ -984,6 +984,34 @@ public void test25TestPurge() throws Exception {
purgeRetentionMinues, "test");
}

@Test(timeout = 120000)
public void test25TestPurge2() throws Exception {
logTestRunning();

int totalCount = getServer().getSqlTemplate().queryForInt("select count(*) from sym_data_event");
int batchId = getServer().getSqlTemplate().queryForInt("select min(batch_id) from sym_outgoing_batch");
int purgeCount = getServer().getSqlTemplate().queryForInt("select count(*) from sym_data_event where batch_id = ?", batchId);

// Purge always leaves the last item in a table, so we have to abandon at least two
getServer().getSqlTemplate().update("delete from sym_outgoing_batch where batch_id in (?, ?)", batchId, batchId + 1);

IParameterService parameterService = getServer().getParameterService();
int purgeRetentionMinues = parameterService.getInt(ParameterConstants.PURGE_RETENTION_MINUTES);
// Put retention into future to force it to purge
parameterService.saveParameter(ParameterConstants.PURGE_RETENTION_MINUTES, -60 * 24, "test");

getServer().purge();

parameterService.saveParameter(ParameterConstants.PURGE_RETENTION_MINUTES, purgeRetentionMinues, "test");

int count = getServer().getSqlTemplate().queryForInt("select count(*) from sym_data_event where batch_id = ?", batchId);
assertTrue(count == 0);

int newTotalCount = getServer().getSqlTemplate().queryForInt("select count(*) from sym_data_event");
assertTrue(newTotalCount == totalCount - purgeCount);

}

@Test(timeout = 120000)
public void test26Heartbeat() throws Exception {
logTestRunning();
Expand Down

0 comments on commit f7a4d44

Please sign in to comment.