diff --git a/api/src/org/labkey/api/util/FileUtil.java b/api/src/org/labkey/api/util/FileUtil.java index 8446e0c3535..40dc5348e69 100644 --- a/api/src/org/labkey/api/util/FileUtil.java +++ b/api/src/org/labkey/api/util/FileUtil.java @@ -61,6 +61,7 @@ import java.nio.CharBuffer; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; +import java.nio.channels.OverlappingFileLockException; import java.nio.channels.ReadableByteChannel; import java.nio.file.FileSystems; import java.nio.file.FileVisitResult; @@ -1078,6 +1079,17 @@ public static void copyFile(File src, File dst) throws IOException } } + private static FileLock acquireLock(FileChannel out) throws IOException + { + try + { + return out.lock(); + } + catch (OverlappingFileLockException e) + { + throw new IOException(e); + } + } // FileUtil.copyFile() does not use transferTo() or sync() public static void copyFile(ReadableByteChannel in, long expected, File dst) throws IOException @@ -1092,7 +1104,7 @@ public static void copyFile(ReadableByteChannel in, long expected, File dst) thr try (FileOutputStream os = new FileOutputStream(dst); FileChannel out = os.getChannel(); - FileLock lockOut = out.lock()) + FileLock lockOut = acquireLock(out)) { do { diff --git a/experiment/src/org/labkey/experiment/api/SampleTypeServiceImpl.java b/experiment/src/org/labkey/experiment/api/SampleTypeServiceImpl.java index b9b43484560..46e14260387 100644 --- a/experiment/src/org/labkey/experiment/api/SampleTypeServiceImpl.java +++ b/experiment/src/org/labkey/experiment/api/SampleTypeServiceImpl.java @@ -118,6 +118,7 @@ import java.util.Optional; import java.util.Set; import java.util.SortedSet; +import java.util.TreeMap; import java.util.TreeSet; import java.util.function.Function; import java.util.function.Predicate; @@ -1700,7 +1701,7 @@ private Map> getSampleAliquotCounts(Collection> sampleAliquotCounts = new HashMap<>(); + Map> sampleAliquotCounts = new TreeMap<>(); // Order sample by rowId to reduce probability of deadlock with search indexer try (ResultSet rs = new SqlSelector(dbSchema, sql).getResultSet()) { while (rs.next()) @@ -1761,7 +1762,7 @@ SELECT RootMaterialRowId as rootRowId, COUNT(*) as aliquotCount } dialect.appendInClauseSql(sql, sampleIds); - Map> sampleAliquotCounts = new HashMap<>(); + Map> sampleAliquotCounts = new TreeMap<>(); // Order by rowId to reduce deadlock with search indexer try (ResultSet rs = new SqlSelector(dbSchema, sql).getResultSet()) { while (rs.next())