Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
srm: Fix asynchroneous job storage leak
The asynchroneous job storage fails to preserve the force flag when collapsing several save calls. In case srm.persistence.enable.history is false (the default), this could lead to incomplete data in the database. This in case could lead to incomplete cleanup of upload directories after an SRM restart. The patch also renames the boolean parameter to something that I find less confusing. Target: trunk Request: 2.10 Request: 2.9 Request: 2.8 Request: 2.7 Require-notes: yes Require-book: no Acked-by: Paul Millar <paul.millar@desy.de> Patch: https://rb.dcache.org/r/7307/ (cherry picked from commit 98f2115) Conflicts: modules/srm-server/src/main/java/org/dcache/srm/scheduler/FinalStateOnlyJobStorageDecorator.java
- Loading branch information
Showing
8 changed files
with
149 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
...les/srm-server/src/test/java/org/dcache/srm/scheduler/AsynchronousSaveJobStorageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package org.dcache.srm.scheduler; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.Executor; | ||
|
||
import org.dcache.srm.request.Job; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
public class AsynchronousSaveJobStorageTest | ||
{ | ||
private JobStorage<Job> storage; | ||
private List<Runnable> tasks; | ||
private AsynchronousSaveJobStorage<Job> asyncStorage; | ||
private Job job; | ||
|
||
@Before | ||
public void setUp() throws Exception | ||
{ | ||
storage = mock(JobStorage.class); | ||
job = mock(Job.class); | ||
tasks = new ArrayList<>(); | ||
asyncStorage = new AsynchronousSaveJobStorage<>(storage, new ListExecutor(tasks)); | ||
} | ||
|
||
@Test | ||
public void whenRequestHistoryLoggingIsDisabledAndSavingWithForceThenActualSaveIsWithForce() throws Exception | ||
{ | ||
when(storage.isJdbcLogRequestHistoryInDBEnabled()).thenReturn(false); | ||
asyncStorage.saveJob(job, true); | ||
runTasks(); | ||
verify(storage).saveJob(job, true); | ||
} | ||
|
||
@Test | ||
public void whenRequestHistoryLoggingIsEnabledAndSavingWithForceThenActualSaveIsWithForce() throws Exception | ||
{ | ||
when(storage.isJdbcLogRequestHistoryInDBEnabled()).thenReturn(true); | ||
asyncStorage.saveJob(job, true); | ||
runTasks(); | ||
verify(storage).saveJob(job, true); | ||
} | ||
|
||
@Test | ||
public void whenRequestHistoryLoggingIsEnabledAndSavingWithoutForceThenActualSaveIsWithoutForce() throws Exception | ||
{ | ||
when(storage.isJdbcLogRequestHistoryInDBEnabled()).thenReturn(true); | ||
asyncStorage.saveJob(job, false); | ||
runTasks(); | ||
verify(storage).saveJob(job, false); | ||
} | ||
|
||
@Test | ||
public void whenSavingTwiceWithoutForceThenActualSaveIsOnceWithoutForce() throws Exception | ||
{ | ||
when(storage.isJdbcLogRequestHistoryInDBEnabled()).thenReturn(true); | ||
asyncStorage.saveJob(job, false); | ||
asyncStorage.saveJob(job, false); | ||
runTasks(); | ||
verify(storage).saveJob(job, false); | ||
} | ||
|
||
@Test | ||
public void whenSavingTwiceWithForceThenActualSaveIsOnceWithForce() throws Exception | ||
{ | ||
when(storage.isJdbcLogRequestHistoryInDBEnabled()).thenReturn(true); | ||
asyncStorage.saveJob(job, true); | ||
asyncStorage.saveJob(job, true); | ||
runTasks(); | ||
verify(storage).saveJob(job, true); | ||
} | ||
|
||
@Test | ||
public void whenSavingTwiceWithAndWithoutForceThenActualSaveIsOnceWithForce() throws Exception | ||
{ | ||
when(storage.isJdbcLogRequestHistoryInDBEnabled()).thenReturn(true); | ||
asyncStorage.saveJob(job, true); | ||
asyncStorage.saveJob(job, false); | ||
runTasks(); | ||
verify(storage).saveJob(job, true); | ||
} | ||
|
||
@Test | ||
public void whenSavingTwiceWithoutAndWithForceThenActualSaveIsOnceWithForce() throws Exception | ||
{ | ||
when(storage.isJdbcLogRequestHistoryInDBEnabled()).thenReturn(true); | ||
asyncStorage.saveJob(job, false); | ||
asyncStorage.saveJob(job, true); | ||
runTasks(); | ||
verify(storage).saveJob(job, true); | ||
} | ||
|
||
private void runTasks() | ||
{ | ||
for (Runnable task : tasks) { | ||
task.run(); | ||
} | ||
} | ||
|
||
private static class ListExecutor implements Executor | ||
{ | ||
private final List<Runnable> tasks; | ||
|
||
private ListExecutor(List<Runnable> tasks) | ||
{ | ||
this.tasks = tasks; | ||
} | ||
|
||
@Override | ||
public void execute( | ||
Runnable command) | ||
{ | ||
tasks.add(command); | ||
} | ||
} | ||
} |