Project

General

Profile

« Previous | Next » 

Revision 7201

on init (start up) launch a synchronization thread that ensures all shared identifier entries have a corresponding local System Metadata entry.

View differences:

src/edu/ucsb/nceas/metacat/dataone/hazelcast/HazelcastService.java
34 34
import java.util.HashSet;
35 35
import java.util.List;
36 36
import java.util.Set;
37
import java.util.Map.Entry;
38
import java.util.concurrent.ExecutorService;
39
import java.util.concurrent.Executors;
37 40
import java.util.concurrent.locks.Lock;
38 41

  
39 42
import org.apache.log4j.Logger;
......
235 238
    // make sure we have all metadata locally
236 239
    try {
237 240
    	// synch on restart
238
    	// BRL: this can be problematic, commenting out 20120404
239
        //synchronizeLocalStore();
241
        resynchInThread();
240 242
	} catch (Exception e) {
241
		String msg = "Problem synchronizing system metadata. " + e.getMessage();
243
		String msg = "Problem resynchronizing system metadata. " + e.getMessage();
242 244
		logMetacat.error(msg, e);
243 245
	}
244 246
        
......
486 488
		}
487 489
	}
488 490
	
489
	public void resynch() throws Exception {
490
		
491
		// get the CN that is online
492
		// TODO: do we even need to use a specific CN?
493
		// All the System Metadata records should be available via the shared map
494
//		NodeList allNodes = CNodeService.getInstance().listNodes();
495
//		Node onlineCN = null;
496
//		for (Node node: allNodes.getNodeList()) {
497
//			if (node.getType().equals(NodeType.CN)) {
498
//				if (node.getState().equals(NodeState.UP)) {
499
//					onlineCN = node;
500
//					break;
501
//				}
502
//			}
503
//		}
504
		
505
		// get the list of items that have changed since X
506
		Date since = IdentifierManager.getInstance().getLastModifiedDate();
507
		EntryObject e = new PredicateBuilder().getEntryObject();
508
		Predicate predicate = e.get(SINCE_PROPERTY).greaterEqual(since);
509
		Collection<SystemMetadata> updatedSystemMetadata = getSystemMetadataMap().values(predicate);
510
		for (SystemMetadata sm: updatedSystemMetadata) {
511
			saveLocally(sm);
491
	/**
492
	 * Make sure we have a copy of every entry in the shared map.
493
	 * We use lazy loading and therefore the CNs may not all be in sync when one
494
	 * comes back online after an extended period of being offline
495
	 * @throws Exception
496
	 */
497
	private void resynch() throws Exception {
498
		// loop through all the [shared] entries and save any missing ones locally
499
		for (Identifier pid: identifiers) {
500
			if (!IdentifierManager.getInstance().systemMetadataExists(pid.getValue())) {
501
				SystemMetadata sm = systemMetadata.get(pid);
502
				saveLocally(sm);
503
			}
512 504
		}
513 505
	}
506
	
507
	private void resynchInThread() {
508
		ExecutorService executor = Executors.newSingleThreadExecutor();
509
		executor.execute(new Runnable() {
510
			@Override
511
			public void run() {
512
				try {
513
					resynch();
514
				} catch (Exception e) {
515
					logMetacat.error("Error in resynchInThread: " + e.getMessage(), e);
516
				}
517
			}
518
		});
519
		executor.shutdown();
520
	}
514 521

  
515 522
	/**
516 523
	 * When there is missing SystemMetadata on the local member,

Also available in: Unified diff