Skip to content

Commit 6523547

Browse files
committed
Add check in place for concurrent jobs trying to save the same aligner index
1 parent 4093754 commit 6523547

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

SequenceAnalysis/api-src/org/labkey/api/sequenceanalysis/pipeline/AlignerIndexUtil.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ private static boolean verifyOrCreateCachedIndex(PipelineContext ctx, @Nullable
6767
{
6868
ctx.getLogger().info("previously created index found, no need to recreate");
6969
ctx.getLogger().debug(webserverIndexDir.getPath());
70+
71+
//This is going to be a really rare event, so for the time being leave this as-is. We could consider throwing an exception and letting the job restart?
72+
File lockFile = new File(webserverIndexDir.getPath() + ".copyLock");
73+
if (lockFile.exists())
74+
{
75+
ctx.getLogger().error("Another job is actively saving this cached index. Will not re-created, but if this job tries to use it before copy is complete this might cause issues.");
76+
}
77+
7078
hasCachedIndex = true;
7179

7280
try
@@ -129,9 +137,18 @@ public static void saveCachedIndex(boolean hasCachedIndex, PipelineContext ctx,
129137
File cachingDir = new File(genome.getSourceFastaFile().getParentFile(), INDEX_DIR + "/" + name);
130138
ctx.getLogger().info("caching index files for future use");
131139
ctx.getLogger().debug(cachingDir.getPath());
140+
File lockFile = new File(cachingDir.getPath() + ".copyLock");
141+
if (lockFile.exists())
142+
{
143+
ctx.getLogger().info("Another job is already caching this index, skipping");
144+
return;
145+
}
132146

133147
try
134148
{
149+
//use as indicator to prevent multiple concurrent jobs from interfering
150+
FileUtils.touch(lockFile);
151+
135152
if (!cachingDir.exists())
136153
{
137154
cachingDir.mkdirs();
@@ -157,6 +174,8 @@ public static void saveCachedIndex(boolean hasCachedIndex, PipelineContext ctx,
157174
FileUtils.copyFile(f, dest);
158175
}
159176
}
177+
178+
lockFile.delete();
160179
}
161180
catch (IOException e)
162181
{

0 commit comments

Comments
 (0)