-
Notifications
You must be signed in to change notification settings - Fork 477
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
Reserve PID at publication if needed #7147
Changes from all commits
af4901f
032cb1f
dbf9458
89f5c4d
1cebc6f
09a8401
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,32 +155,30 @@ protected void tidyUpFields(DatasetVersion dsv) { | |
* @param ctxt | ||
* @throws CommandException | ||
*/ | ||
protected void registerExternalIdentifier(Dataset theDataset, CommandContext ctxt) throws CommandException { | ||
protected void registerExternalIdentifier(Dataset theDataset, CommandContext ctxt, boolean retry) throws CommandException { | ||
if (!theDataset.isIdentifierRegistered()) { | ||
GlobalIdServiceBean globalIdServiceBean = GlobalIdServiceBean.getBean(theDataset.getProtocol(), ctxt); | ||
if ( globalIdServiceBean != null ) { | ||
if (globalIdServiceBean instanceof FakePidProviderServiceBean) { | ||
try { | ||
globalIdServiceBean.createIdentifier(theDataset); | ||
} catch (Throwable ex) { | ||
logger.warning("Problem running createIdentifier for FakePidProvider: " + ex); | ||
} | ||
theDataset.setGlobalIdCreateTime(getTimestamp()); | ||
theDataset.setIdentifierRegistered(true); | ||
return; | ||
retry=false; //No reason to allow a retry with the FakeProvider, so set false for efficiency | ||
} | ||
try { | ||
if (globalIdServiceBean.alreadyExists(theDataset)) { | ||
int attempts = 0; | ||
|
||
while (globalIdServiceBean.alreadyExists(theDataset) && attempts < FOOLPROOF_RETRIAL_ATTEMPTS_LIMIT) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With while, there's an extra call to alreadyExists in the first iteration, so switched to do while loop. |
||
theDataset.setIdentifier(ctxt.datasets().generateDatasetIdentifier(theDataset, globalIdServiceBean)); | ||
logger.log(Level.INFO, "Attempting to register external identifier for dataset {0} (trying: {1}).", | ||
new Object[]{theDataset.getId(), theDataset.getIdentifier()}); | ||
attempts++; | ||
if(retry) { | ||
do { | ||
theDataset.setIdentifier(ctxt.datasets().generateDatasetIdentifier(theDataset, globalIdServiceBean)); | ||
logger.log(Level.INFO, "Attempting to register external identifier for dataset {0} (trying: {1}).", | ||
new Object[]{theDataset.getId(), theDataset.getIdentifier()}); | ||
attempts++; | ||
} while (globalIdServiceBean.alreadyExists(theDataset) && attempts <= FOOLPROOF_RETRIAL_ATTEMPTS_LIMIT); | ||
} | ||
|
||
if (globalIdServiceBean.alreadyExists(theDataset)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar - extra call to alreadyExists since attempts will be over the limit if the while call above doesn't find alreadyExists()==false by the end. |
||
if(!retry) { | ||
logger.warning("Reserving PID for: " + getDataset().getId() + " during publication failed."); | ||
throw new IllegalCommandException(BundleUtil.getStringFromBundle("publishDatasetCommand.pidNotReserved"), this); | ||
} | ||
if(attempts > FOOLPROOF_RETRIAL_ATTEMPTS_LIMIT) { | ||
//Didn't work - we existed the loop with too many tries | ||
throw new CommandExecutionException("This dataset may not be published because its identifier is already in use by another dataset; " | ||
+ "gave up after " + attempts + " attempts. Current (last requested) identifier: " + theDataset.getIdentifier(), this); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was just to avoid the retry attempts - same set of calls otherwise.