Better handle large search result deletion in JPA

This commit is contained in:
James Agnew 2018-02-08 17:55:46 -05:00
parent e4785b17b5
commit 80353e5d42
2 changed files with 21 additions and 7 deletions

View File

@ -37,6 +37,7 @@ import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;
import java.util.Date;
@ -95,17 +96,24 @@ public class StaleSearchDeletingSvcImpl implements IStaleSearchDeletingSvc {
ourLog.debug("Searching for searches which are before {}", cutoff);
TransactionTemplate tt = new TransactionTemplate(myTransactionManager);
int count = tt.execute(new TransactionCallback<Integer>() {
final Slice<Long> toDelete = tt.execute(new TransactionCallback<Slice<Long>>() {
@Override
public Integer doInTransaction(TransactionStatus theStatus) {
Slice<Long> toDelete = mySearchDao.findWhereLastReturnedBefore(cutoff, new PageRequest(0, 1000));
for (final Long next : toDelete) {
deleteSearch(next);
}
return toDelete.getContent().size();
public Slice<Long> doInTransaction(TransactionStatus theStatus) {
return mySearchDao.findWhereLastReturnedBefore(cutoff, new PageRequest(0, 1000));
}
});
for (final Long nextSearchToDelete : toDelete) {
ourLog.debug("Deleting search with PID {}", nextSearchToDelete);
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
deleteSearch(nextSearchToDelete);
}
});
}
int count = toDelete.getContent().size();
if (count > 0) {
long total = tt.execute(new TransactionCallback<Long>() {
@Override

View File

@ -125,6 +125,12 @@
parameters that include additional content (e.g.
<![CDATA[<code>_format=html/json;fhirVersion=1.0</code>]]>)
</action>
<action type="add">
Stale search deleting routine on JPA server has been adjusted
to delete one search per transaction instead of batching 1000
searches per transaction. This should make the deletion logic
more tolerant of deleting very large search result sets.
</action>
</release>
<release version="3.2.0" date="2018-01-13">
<action type="add">