Skip to content

Commit

Permalink
Merge pull request #8056 from GlobalDataverseCommunityConsortium/IQSS…
Browse files Browse the repository at this point in the history
…/8053-fix_import

Fix for #8053 - avoid setting lock on as-yet-uncomitted dataset
  • Loading branch information
kcondon committed Aug 11, 2021
2 parents 72c26e3 + 99a761e commit c6c355a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,25 @@ public PublishDatasetResult execute(CommandContext ctxt) throws CommandException
info += validatePhysicalFiles ? "Validating Datafiles Asynchronously" : "";

AuthenticatedUser user = request.getAuthenticatedUser();
DatasetLock lock = new DatasetLock(DatasetLock.Reason.finalizePublication, user);
lock.setDataset(theDataset);
lock.setInfo(info);
ctxt.datasets().addDatasetLock(theDataset, lock);
/*
* datasetExternallyReleased is only true in the case of the
* Dataverses.importDataset() and importDatasetDDI() methods. In that case, we
* are still in the transaction that creates theDataset, so
* A) Trying to create a DatasetLock referncing that dataset in a new
* transaction (as ctxt.datasets().addDatasetLock() does) will fail since the
* dataset doesn't yet exist, and
* B) a lock isn't needed because no one can be trying to edit it yet (as it
* doesn't exist).
* Thus, we can/need to skip creating the lock. Since the calls to removeLocks
* in FinalizeDatasetPublicationCommand search for and remove existing locks, if
* one doesn't exist, the removal is a no-op in this case.
*/
if (!datasetExternallyReleased) {
DatasetLock lock = new DatasetLock(DatasetLock.Reason.finalizePublication, user);
lock.setDataset(theDataset);
lock.setInfo(info);
ctxt.datasets().addDatasetLock(theDataset, lock);
}
theDataset = ctxt.em().merge(theDataset);
// The call to FinalizePublicationCommand has been moved to the new @onSuccess()
// method:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ public void start(Workflow wf, WorkflowContext ctxt, boolean findDataset) throws
/*
* Sleep here briefly to make sure the database update from the callers
* transaction completes which avoids any concurrency/optimistic lock issues.
* Note: 1 second appears long enough, but shorter delays may work
* Note: 1 second appears long enough, but shorter delays may work.
* One example:
* the Dataverses.importDataset()/importDatasetDDI() calls with release=yes will
* trigger a prepublish workflow on a dataset that isn't committed to the
* database until the API call completes.
*/
try {
Thread.sleep(1000);
Expand Down

0 comments on commit c6c355a

Please sign in to comment.