Project

General

Profile

« Previous | Next » 

Revision 8450

Change CNodeService's archive() and delete() methods to only update Member Nodes in the replica list (not CNs!), since calling CN.archive() again would cause an infinite loop. Thanks for catching this Ben.

View differences:

src/edu/ucsb/nceas/metacat/dataone/CNodeService.java
343 343
  public Identifier delete(Session session, Identifier pid) 
344 344
      throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented {
345 345
      
346
      String localId = null; // The corresponding docid for this pid
347
	  Lock lock = null;      // The lock to be used for this identifier
346
      String localId = null;      // The corresponding docid for this pid
347
	  Lock lock = null;           // The lock to be used for this identifier
348
      CNode cn = null;            // a reference to the CN to get the node list    
349
      NodeType nodeType = null;   // the nodeType of the replica node being contacted
350
      List<Node> nodeList = null; // the list of nodes in this CN environment
348 351

  
349 352
      // check for a valid session
350 353
      if (session == null) {
......
420 423

  
421 424
      }
422 425

  
423
      
426
      // get the node list
427
      try {
428
          cn = D1Client.getCN();
429
          nodeList = cn.listNodes().getNodeList();
430
          
431
      } catch (Exception e) { // handle BaseException and other I/O issues
432
          
433
          // swallow errors since the call is not critical
434
          logMetacat.error("Can't inform MNs of the deletion of " + pid.getValue() + 
435
              " due to communication issues with the CN: " + e.getMessage());
436
          
437
      }
438

  
424 439
	  // notify the replicas
425 440
	  SystemMetadata systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
426 441
	  if (systemMetadata.getReplicaList() != null) {
427 442
		  for (Replica replica: systemMetadata.getReplicaList()) {
428 443
			  NodeReference replicaNode = replica.getReplicaMemberNode();
429 444
			  try {
430
				  Identifier mnRetId = D1Client.getMN(replicaNode).delete(null, pid);
445
                  if (nodeList != null) {
446
                      // find the node type
447
                      for (Node node : nodeList) {
448
                          if ( node.getIdentifier().getValue().equals(replicaNode.getValue()) ) {
449
                              nodeType = node.getType();
450
                              break;
451
              
452
                          }
453
                      }
454
                  }
455
                  
456
                  // only send call MN.delete() to avoid an infinite loop with the CN
457
                  if (nodeType != null && nodeType == NodeType.MN) {
458
				      Identifier mnRetId = D1Client.getMN(replicaNode).delete(null, pid);
459
                  }
460
                  
431 461
			  } catch (Exception e) {
432 462
				  // all we can really do is log errors and carry on with life
433
				  logMetacat.error("Error deleting pid: " +  pid.getValue() + " from replica MN: " + replicaNode.getValue(), e);
463
				  logMetacat.error("Error deleting pid: " +  pid.getValue() + 
464
					  " from replica MN: " + replicaNode.getValue(), e);
434 465
			}
435 466
			  
436 467
		  }
......
461 492

  
462 493
      String localId = null; // The corresponding docid for this pid
463 494
	  Lock lock = null;      // The lock to be used for this identifier
495
      CNode cn = null;            // a reference to the CN to get the node list    
496
      NodeType nodeType = null;   // the nodeType of the replica node being contacted
497
      List<Node> nodeList = null; // the list of nodes in this CN environment
498
      
464 499

  
465 500
      // check for a valid session
466 501
      if (session == null) {
......
531 566
                  pid.getValue(), Event.DELETE.xmlValue());
532 567

  
533 568
      }
534
      
569

  
570
      // get the node list
571
      try {
572
          cn = D1Client.getCN();
573
          nodeList = cn.listNodes().getNodeList();
574
          
575
      } catch (Exception e) { // handle BaseException and other I/O issues
576
          
577
          // swallow errors since the call is not critical
578
          logMetacat.error("Can't inform MNs of the archive of " + pid.getValue() + 
579
              " due to communication issues with the CN: " + e.getMessage());
580
          
581
      }
582

  
535 583
	  // notify the replicas
536 584
	  SystemMetadata systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
537 585
	  if (systemMetadata.getReplicaList() != null) {
538 586
		  for (Replica replica: systemMetadata.getReplicaList()) {
539 587
			  NodeReference replicaNode = replica.getReplicaMemberNode();
540 588
			  try {
541
				  // TODO: implement in the clients
542
				  //Identifier mnRetId = D1Client.getMN(replicaNode).archive(null, pid);
589
                  if (nodeList != null) {
590
                      // find the node type
591
                      for (Node node : nodeList) {
592
                          if ( node.getIdentifier().getValue().equals(replicaNode.getValue()) ) {
593
                              nodeType = node.getType();
594
                              break;
595
              
596
                          }
597
                      }
598
                  }
599
                  
600
                  // only send call MN.archive() to avoid an infinite loop with the CN
601
                  if (nodeType != null && nodeType == NodeType.MN) {
602
				      Identifier mnRetId = D1Client.getMN(replicaNode).archive(null, pid);
603
				      
604
                  }
605
                  
543 606
			  } catch (Exception e) {
544 607
				  // all we can really do is log errors and carry on with life
545
				  logMetacat.error("Error archiving pid: " +  pid.getValue() + " from replica MN: " + replicaNode.getValue(), e);
608
				  logMetacat.error("Error archiving pid: " +  pid.getValue() + 
609
					  " from replica MN: " + replicaNode.getValue(), e);
546 610
			}
547 611
			  
548 612
		  }
......
1770 1834
                  if (nodeList != null) {
1771 1835
                      // find the node type
1772 1836
                      for (Node node : nodeList) {
1773
                          if (node.getIdentifier().getValue() == 
1774
                              replicaNodeRef.getValue()) {
1837
                          if ( node.getIdentifier().getValue().equals(replicaNodeRef.getValue()) ) {
1775 1838
                              nodeType = node.getType();
1776 1839
                              break;
1777 1840
              

Also available in: Unified diff