Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
dcache-chimera: fix cleaner batch delete exception
Motivation:
Deleting files by DiskCleaner is done via a database batch update, which throws the following exception when the list happens to be empty: `java.util.concurrent.CompletionException: org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [DELETE FROM t_locationinfo_trash WHERE ilocation=? AND ipnfsid=? AND itype=1]; nested exception is java.sql.SQLException: statement is not in batch mode`.

Modification:
Pass an immutable delete file list copy to the batch delete method to make sure that it is not modified in the meantime. Check that the list is not empty in the batch delete method.

Result:
Reduced likelihood of `SQLException: statement is not in batch mode` in DiskCleaner.

Target: master
Request: 8.0
Request: 7.2
Request: 7.1
Request: 7.0
Request: 6.2
Fixes: #6496
Requires-notes: no
Requires-book: no
Patch: https://rb.dcache.org/r/13455/
Acked-by: Tigran Mkrtchyan
  • Loading branch information
lemora committed Mar 4, 2022
1 parent 1d4b4c2 commit 6ab4488
Showing 1 changed file with 7 additions and 3 deletions.
Expand Up @@ -192,6 +192,10 @@ List<String> getPoolList() {
* @param filelist file list for this pool
*/
void removeFiles(final String poolname, final List<String> filelist) {
if(filelist == null || filelist.isEmpty()) {
_log.info("Unexpected empty delete file list.");
return;
}
_db.batchUpdate(
"DELETE FROM t_locationinfo_trash WHERE ilocation=? AND ipnfsid=? AND itype=1",
new BatchPreparedStatementSetter() {
Expand Down Expand Up @@ -225,14 +229,14 @@ private int sendRemoveToPoolCleaner(String poolName, List<String> removeList)
CellStub.get(_poolStub.send(new CellPath(poolName),
new PoolRemoveFilesMessage(poolName, removeList)));
if (msg.getReturnCode() == 0) {
removeFiles(poolName, removeList);
removeFiles(poolName, List.copyOf(removeList));
return removeList.size();
} else if (msg.getReturnCode() == 1 && msg.getErrorObject() instanceof String[]) {
Set<String> notRemoved =
new HashSet<>(Arrays.asList((String[]) msg.getErrorObject()));
List<String> removed = new ArrayList<>(removeList);
removed.removeAll(notRemoved);
removeFiles(poolName, removed);
removeFiles(poolName, List.copyOf(removed));
return removed.size();
} else {
throw CacheExceptionFactory.exceptionOf(msg);
Expand Down Expand Up @@ -380,7 +384,7 @@ public String call() throws CommandException {
hint = "clean this file (file will be deleted from DISK)")
public class CleanFileCommand implements Callable<String> {

@Argument(usage = "pnfsid of the file to clean")
@Argument(required = true, usage = "pnfsid of the file to clean")
String pnfsid;

@Override
Expand Down

0 comments on commit 6ab4488

Please sign in to comment.