Project

General

Profile

« Previous | Next » 

Revision 9335

Added by Jing Tao about 9 years ago

Add the code to check the date of system metadata modification match in MN.updateSystemMetadata only. CN.updateSystemMetadata doesn't check.

View differences:

src/edu/ucsb/nceas/metacat/dataone/CNodeService.java
2199 2199
               throw new NotAuthorized("4861", "The client -"+ session.getSubject().getValue()+ "is not authorized for updating the system metadata of the object "+pid.getValue());
2200 2200
         }
2201 2201
   }
2202
    //update the system metadata locally  
2203
    boolean success = super.updateSystemMetadata(session, pid, sysmeta);
2202

  
2203
    //update the system metadata locally
2204
    boolean success = false;
2205
    try {
2206
        HazelcastService.getInstance().getSystemMetadataMap().lock(pid);
2207
        SystemMetadata currentSysmeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
2208
        if(currentSysmeta == null) {
2209
            throw  new InvalidRequest("4863", "We can't find the current system metadata on the member node for the id "+pid.getValue());
2210
        }
2211
        boolean needUpdateModificationDate = false;//cn doesn't need to change the modification date.
2212
        success = updateSystemMetadata(session, pid, sysmeta, needUpdateModificationDate, currentSysmeta);
2213
    } finally {
2214
        HazelcastService.getInstance().getSystemMetadataMap().unlock(pid);
2215
    }
2204 2216
    return success;
2205 2217
  }
2206 2218
  
src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java
1579 1579
   */
1580 1580
    protected void updateSystemMetadata(SystemMetadata sysMeta)
1581 1581
        throws ServiceFailure {
1582

  
1583 1582
        logMetacat.debug("D1NodeService.updateSystemMetadata() called.");
1584
        sysMeta.setDateSysMetadataModified(new Date());
1585 1583
        try {
1586 1584
            HazelcastService.getInstance().getSystemMetadataMap().lock(sysMeta.getIdentifier());
1587
            HazelcastService.getInstance().getSystemMetadataMap().put(sysMeta.getIdentifier(), sysMeta);
1588
            // submit for indexing
1589
            MetacatSolrIndex.getInstance().submit(sysMeta.getIdentifier(), sysMeta, null, true);
1585
            boolean needUpdateModificationDate = true;
1586
            updateSystemMetadataWithoutLock(sysMeta, needUpdateModificationDate);
1590 1587
        } catch (Exception e) {
1591 1588
            throw new ServiceFailure("4862", e.getMessage());
1592

  
1593 1589
        } finally {
1594 1590
            HazelcastService.getInstance().getSystemMetadataMap().unlock(sysMeta.getIdentifier());
1595 1591

  
......
1598 1594
    }
1599 1595
    
1600 1596
    /**
1601
     * Update the system metadata of the specified pid
1597
     * Update system metadata without locking the system metadata in hazelcast server. So the caller should lock it first. 
1598
     * @param sysMeta
1599
     * @param needUpdateModificationDate
1600
     * @throws ServiceFailure
1601
     */
1602
    private void updateSystemMetadataWithoutLock(SystemMetadata sysMeta, boolean needUpdateModificationDate) throws ServiceFailure {
1603
        logMetacat.debug("D1NodeService.updateSystemMetadataWithoutLock() called.");
1604
        if(needUpdateModificationDate) {
1605
            logMetacat.debug("D1NodeService.updateSystemMetadataWithoutLock() - update the modification date.");
1606
            sysMeta.setDateSysMetadataModified(new Date());
1607
        }
1608
        
1609
        // submit for indexing
1610
        try {
1611
            HazelcastService.getInstance().getSystemMetadataMap().put(sysMeta.getIdentifier(), sysMeta);
1612
            MetacatSolrIndex.getInstance().submit(sysMeta.getIdentifier(), sysMeta, null, true);
1613
        } catch (Exception e) {
1614
            throw new ServiceFailure("4862", e.getMessage());
1615
            //logMetacat.warn("D1NodeService.updateSystemMetadataWithoutLock - we can't submit the change of the system metadata to the solr index since "+e.getMessage());
1616
        }
1617
    }
1618
    
1619
    /**
1620
     * Update the system metadata of the specified pid. The caller of this method should lock the system metadata in hazelcast server.
1602 1621
     * @param session - the identity of the client which calls the method
1603 1622
     * @param pid - the identifier of the object which will be updated
1604 1623
     * @param sysmeta - the new system metadata  
......
1610 1629
     * @throws InvalidSystemMetadata
1611 1630
     * @throws InvalidToken
1612 1631
     */
1613
	public boolean updateSystemMetadata(Session session, Identifier pid,
1614
			SystemMetadata sysmeta) throws NotImplemented, NotAuthorized,
1632
	protected boolean updateSystemMetadata(Session session, Identifier pid,
1633
			SystemMetadata sysmeta, boolean needUpdateModificationDate, SystemMetadata currentSysmeta) throws NotImplemented, NotAuthorized,
1615 1634
			ServiceFailure, InvalidRequest, InvalidSystemMetadata, InvalidToken {
1616 1635
		
1617
		// The lock to be used for this identifier
1636
	  // The lock to be used for this identifier
1618 1637
      Lock lock = null;
1619 1638
     
1620 1639
      // verify that guid == SystemMetadata.getIdentifier()
......
1630 1649
      //compare serial version.
1631 1650
      
1632 1651
      //check the sid
1633
      SystemMetadata currentSysmeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
1652
      //SystemMetadata currentSysmeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
1634 1653
      logMetacat.debug("The current dateUploaded is ============"+currentSysmeta.getDateUploaded());
1635 1654
      logMetacat.debug("the dateUploaded in the new system metadata is "+sysmeta.getDateUploaded());
1636 1655
      logMetacat.debug("The current dateUploaded is (by time) ============"+currentSysmeta.getDateUploaded().getTime());
......
1695 1714
      }
1696 1715
      
1697 1716
      // do the actual update
1698
      this.updateSystemMetadata(sysmeta);
1717
      updateSystemMetadataWithoutLock(sysmeta, needUpdateModificationDate);
1699 1718
      
1700 1719
      try {
1701 1720
    	  String localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
2303 2303
         }
2304 2304
         
2305 2305
     }
2306
      //update the system metadata locally  
2307
      boolean success = super.updateSystemMetadata(session, pid, sysmeta);
2306
      //update the system metadata locally
2307
      boolean success = false;
2308
      try {
2309
          HazelcastService.getInstance().getSystemMetadataMap().lock(pid);
2310
          SystemMetadata currentSysmeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
2311
          if(currentSysmeta == null) {
2312
              throw  new InvalidRequest("4863", "We can't find the current system metadata on the member node for the id "+pid.getValue());
2313
          }
2314
          Date currentModiDate = currentSysmeta.getDateSysMetadataModified();
2315
          Date commingModiDate = sysmeta.getDateSysMetadataModified();
2316
          if(commingModiDate == null) {
2317
              throw  new InvalidRequest("4863", "The system metadata modification date can't be null.");
2318
          }
2319
          if(currentModiDate != null && commingModiDate.getTime() != currentModiDate.getTime()) {
2320
              throw new InvalidRequest("4863", "Your system metadata modification date is "+commingModiDate.toString()+
2321
                      ". It doesn't match our current system metadata modification date in the member node - "+currentModiDate.toString()+
2322
                      ". Please check if you have got the newest version of the system metadata before the modification.");
2323
          }
2324
          boolean needUpdateModificationDate = true;
2325
          success = updateSystemMetadata(session, pid, sysmeta, needUpdateModificationDate, currentSysmeta);
2326
      } finally {
2327
          HazelcastService.getInstance().getSystemMetadataMap().unlock(pid);
2328
      }
2308 2329
      
2309 2330
      if(success) {
2310 2331
          //TODO

Also available in: Unified diff