Skip to content

Commit

Permalink
remove lock in transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
qqmyers committed Oct 31, 2024
1 parent 23569a3 commit 0958193
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import edu.harvard.iq.dataverse.util.FileMetadataUtil;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -276,13 +277,28 @@ public Dataset execute(CommandContext ctxt) throws CommandException {
AuthenticatedUser au = (AuthenticatedUser) getUser();
ctxt.datasetVersion().writeEditVersionLog(dvd, au);
}
if ( theDataset != null ) {
final Dataset lockedDataset=theDataset;
logger.info("Locks found: " + theDataset.getLocks().size());
new HashSet<>(lockedDataset.getLocks()).stream()
.filter( l -> l.getReason() == DatasetLock.Reason.EditInProgress )
.forEach( existingLock -> {
existingLock = ctxt.em().merge(existingLock);
lockedDataset.removeLock(existingLock);

AuthenticatedUser user = existingLock.getUser();
user.getDatasetLocks().remove(existingLock);

ctxt.em().remove(existingLock);
});
}
} finally {
// We're done making changes - remove the lock...
//Failures above may occur before savedDataset is set, in which case we need to remove the lock on theDataset instead
if(savedDataset!=null) {
ctxt.datasets().removeDatasetLocks(savedDataset, DatasetLock.Reason.EditInProgress);
} else {
//Only happens if an exception has caused us to miss the lock removal in this transaction
if(!theDataset.getLocks().isEmpty()) {
ctxt.datasets().removeDatasetLocks(theDataset, DatasetLock.Reason.EditInProgress);
} else {
logger.fine("No locks to remove");
}
}

Expand Down

0 comments on commit 0958193

Please sign in to comment.