Project

General

Profile

« Previous | Next » 

Revision 10300

Added by Jing Tao about 7 years ago

Add the code to remove the pid from the identifier table if the update method failed.

View differences:

src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
534 534
                } catch (IOException e) {
535 535
                    String msg = "The Node is unable to create the object: "+pid.getValue() + "There was a problem converting the object to XML";
536 536
                    logMetacat.error(msg, e);
537
                    removeIdFromIdentifierTable(newPid);
537 538
                    throw new ServiceFailure("1310", msg + ": " + e.getMessage());
538 539

  
539 540
                }  catch (PropertyNotFoundException e) {
540 541
                    String msg = "The Node is unable to create the object. " +pid.getValue()+ " since the properties are not configured well "+e.getMessage();
541 542
                    logMetacat.error(msg, e);
543
                    removeIdFromIdentifierTable(newPid);
542 544
                    throw new ServiceFailure("1310", msg);
545
                } catch (Exception e) {
546
                    logMetacat.error("MNService.update - couldn't write the metadata object to the disk since "+e.getMessage(), e);
547
                    removeIdFromIdentifierTable(newPid);
548
                    throw e;
543 549
                }
544 550

  
545 551
            } else {
546 552

  
547 553
                // update the data object
548
                localId = insertDataObject(object, newPid, session, sysmeta.getChecksum());
554
                try {
555
                    localId = insertDataObject(object, newPid, session, sysmeta.getChecksum());
556
                } catch (Exception e) {
557
                    logMetacat.error("MNService.update - couldn't write the data object to the disk since "+e.getMessage(), e);
558
                    removeIdFromIdentifierTable(newPid);
559
                    throw e;
560
                }
561
                
549 562

  
550 563
            }
551 564
            
......
597 610
        logMetacat.debug("MNodeService.update - the total time of updating the old pid " +pid.getValue() +" whth the new pid "+newPid.getValue()+" is "+(end6- startTime)+ " milli seconds.");
598 611
        return newPid;
599 612
    }
613
    
614
    /*
615
     * Roll-back method when inserting data object fails.
616
     */
617
    protected void removeIdFromIdentifierTable(Identifier id){
618
        if(id != null) {
619
            try {
620
                if(IdentifierManager.getInstance().mappingExists(id.getValue())) {
621
                   String localId = IdentifierManager.getInstance().getLocalId(id.getValue());
622
                   IdentifierManager.getInstance().removeMapping(id.getValue(), localId);
623
                   logMetacat.info("MNodeService.removeIdFromIdentifierTable - the identifier "+id.getValue()+" and local id "+localId+" have been removed from the identifier table since the object creation failed");
624
                }
625
            } catch (Exception e) {
626
                logMetacat.warn("MNodeService.removeIdFromIdentifierTable - can't decide if the mapping of  the pid "+id.getValue()+" exists on the identifier table.");
627
            }
628
        }
629
    }
600 630

  
601 631
    public Identifier create(Session session, Identifier pid, InputStream object, SystemMetadata sysmeta) throws InvalidToken, ServiceFailure, NotAuthorized,
602 632
            IdentifierNotUnique, UnsupportedType, InsufficientResources, InvalidSystemMetadata, NotImplemented, InvalidRequest {

Also available in: Unified diff