Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #8053 - avoid setting lock on as-yet-uncomitted dataset #8056

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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