Project

General

Profile

« Previous | Next » 

Revision 6863

Added by Chris Jones over 12 years ago

In registerSystemMetadata(), lock the pid prior to calling map.containsKey(pid) since a put to the map could occur between the check and the subsequent put().

View differences:

src/edu/ucsb/nceas/metacat/dataone/CNodeService.java
684 684
              sysmeta.getIdentifier().getValue() + ").");
685 685
      }
686 686

  
687
      logMetacat.debug("Checking if identifier exists...");
688
      // Check that the identifier does not already exist
689
      if (HazelcastService.getInstance().getSystemMetadataMap().containsKey(pid)) {
690
          throw new InvalidRequest("4863", 
691
              "The identifier is already in use by an existing object.");
692
      
693
      }
694
      
695
      // insert the system metadata into the object store
696
      logMetacat.debug("Starting to insert SystemMetadata...");
697 687
      try {
698 688
          lock = HazelcastService.getInstance().getLock(sysmeta.getIdentifier().getValue());
699
          sysmeta.setSerialVersion(BigInteger.ONE);
700
          sysmeta.setDateSysMetadataModified(Calendar.getInstance().getTime());
701
          HazelcastService.getInstance().getSystemMetadataMap().put(sysmeta.getIdentifier(), sysmeta);
689
          lock.lock();
690
          logMetacat.debug("Checking if identifier exists...");
691
          // Check that the identifier does not already exist
692
          if (HazelcastService.getInstance().getSystemMetadataMap().containsKey(pid)) {
693
              throw new InvalidRequest("4863", 
694
                  "The identifier is already in use by an existing object.");
702 695
          
696
          }
697
          
698
          // insert the system metadata into the object store
699
          logMetacat.debug("Starting to insert SystemMetadata...");
700
          try {
701
              sysmeta.setSerialVersion(BigInteger.ONE);
702
              sysmeta.setDateSysMetadataModified(Calendar.getInstance().getTime());
703
              HazelcastService.getInstance().getSystemMetadataMap().put(sysmeta.getIdentifier(), sysmeta);
704
              
705
          } catch (Exception e) {
706
            logMetacat.error("Problem registering system metadata: " + pid.getValue(), e);
707
              throw new ServiceFailure("4862", "Error inserting system metadata: " + 
708
                  e.getClass() + ": " + e.getMessage());
709
              
710
          }
711
          
703 712
      } catch (Exception e) {
704
        logMetacat.error("Problem registering system metadata: " + pid.getValue(), e);
705 713
          throw new ServiceFailure("4862", "Error inserting system metadata: " + 
706
              e.getClass() + ": " + e.getMessage());
714
                  e.getClass() + ": " + e.getMessage());
707 715
          
708
      } finally {
709
        lock.unlock();
710
        logMetacat.debug("Unlocked identifier " + pid.getValue());
716
      }  finally {
717
          lock.unlock();
718
          logMetacat.debug("Unlocked identifier " + pid.getValue());
719
          
720
      }
711 721

  
712
      }
713 722
      
714 723
      logMetacat.debug("Returning from registerSystemMetadata");
715 724
      EventLog.getInstance().log(request.getRemoteAddr(), 

Also available in: Unified diff