Skip to content

Commit

Permalink
#16277 Adding pagination to batch delete to avoid deadlocks in MySQL
Browse files Browse the repository at this point in the history
  • Loading branch information
nollymar committed Apr 23, 2019
1 parent 56041ef commit b4876de
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,20 @@ protected void deleteReindexEntry(String identifier) throws DotDataException {

@CloseDBIfOpened
protected void deleteReindexEntry(final List<ReindexEntry> recordsToDelete) throws DotDataException {
new DotConnect().executeBatch("DELETE FROM dist_reindex_journal where ident_to_index = ?",
recordsToDelete.stream().map(entry -> new Params(entry.getIdentToIndex())).collect(
Collectors.toList()));
final DotConnect dotConnect = new DotConnect();

final int batchSize = REINDEX_RECORDS_TO_FETCH / 4;
int from = 0;
while(from <= recordsToDelete.size()){
dotConnect.executeBatch("DELETE FROM dist_reindex_journal where ident_to_index = ?",
recordsToDelete
.subList(from, Math.min(recordsToDelete.size(), batchSize + from))
.stream().map(entry -> new Params(entry.getIdentToIndex())).collect(
Collectors.toList()));

from += batchSize;
}

}


Expand Down

0 comments on commit b4876de

Please sign in to comment.