Revision 7187
Added by ben leinfelder over 12 years ago
src/edu/ucsb/nceas/metacat/dataone/hazelcast/HazelcastService.java | ||
---|---|---|
28 | 28 |
|
29 | 29 |
import java.io.FileNotFoundException; |
30 | 30 |
import java.sql.SQLException; |
31 |
import java.util.ArrayList; |
|
31 | 32 |
import java.util.Collection; |
32 | 33 |
import java.util.Date; |
34 |
import java.util.HashSet; |
|
33 | 35 |
import java.util.List; |
36 |
import java.util.Set; |
|
34 | 37 |
import java.util.concurrent.locks.Lock; |
35 | 38 |
|
36 | 39 |
import org.apache.log4j.Logger; |
... | ... | |
38 | 41 |
import org.dataone.service.types.v1.Identifier; |
39 | 42 |
import org.dataone.service.types.v1.Node; |
40 | 43 |
import org.dataone.service.types.v1.NodeReference; |
44 |
import org.dataone.service.types.v1.ObjectInfo; |
|
45 |
import org.dataone.service.types.v1.ObjectList; |
|
41 | 46 |
import org.dataone.service.types.v1.SystemMetadata; |
42 | 47 |
|
43 | 48 |
import com.hazelcast.config.Config; |
... | ... | |
61 | 66 |
|
62 | 67 |
import edu.ucsb.nceas.metacat.IdentifierManager; |
63 | 68 |
import edu.ucsb.nceas.metacat.McdbDocNotFoundException; |
64 |
import edu.ucsb.nceas.metacat.dataone.D1NodeService; |
|
65 | 69 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
66 | 70 |
import edu.ucsb.nceas.metacat.shared.BaseService; |
67 | 71 |
import edu.ucsb.nceas.metacat.shared.ServiceException; |
... | ... | |
209 | 213 |
|
210 | 214 |
// Get a reference to the shared identifiers set as a cluster member |
211 | 215 |
identifiers = Hazelcast.getSet(identifiersSet); |
216 |
identifiers.addAll(loadAllKeys()); |
|
212 | 217 |
|
213 | 218 |
// Listen for changes to the system metadata map |
214 | 219 |
systemMetadata.addEntryListener(this, true); |
... | ... | |
548 | 553 |
} |
549 | 554 |
} |
550 | 555 |
|
556 |
/** |
|
557 |
* Load all System Metadata keys from the backing store |
|
558 |
* @return set of pids |
|
559 |
*/ |
|
560 |
private Set<Identifier> loadAllKeys() { |
|
561 |
|
|
562 |
Set<Identifier> pids = new HashSet<Identifier>(); |
|
563 |
|
|
564 |
try { |
|
565 |
|
|
566 |
// ALTERNATIVE 1: this has more overhead than just looking at the GUIDs |
|
567 |
// ObjectList ol = IdentifierManager.getInstance().querySystemMetadata( |
|
568 |
// null, //startTime, |
|
569 |
// null, //endTime, |
|
570 |
// null, //objectFormatId, |
|
571 |
// false, //replicaStatus, |
|
572 |
// 0, //start, |
|
573 |
// -1 //count |
|
574 |
// ); |
|
575 |
// for (ObjectInfo o: ol.getObjectInfoList()) { |
|
576 |
// Identifier pid = o.getIdentifier(); |
|
577 |
// if ( !pids.contains(pid) ) { |
|
578 |
// pids.add(pid); |
|
579 |
// } |
|
580 |
// } |
|
581 |
|
|
582 |
// ALTERNATIVE method: look up all the Identifiers from the table |
|
583 |
List<String> guids = IdentifierManager.getInstance().getAllSystemMetadataGUIDs(); |
|
584 |
for (String guid: guids){ |
|
585 |
Identifier pid = new Identifier(); |
|
586 |
pid.setValue(guid); |
|
587 |
pids.add(pid); |
|
588 |
} |
|
589 |
|
|
590 |
} catch (Exception e) { |
|
591 |
throw new RuntimeException(e.getMessage(), e); |
|
592 |
|
|
593 |
} |
|
594 |
|
|
595 |
return pids; |
|
596 |
} |
|
597 |
|
|
551 | 598 |
} |
src/edu/ucsb/nceas/metacat/dataone/hazelcast/SystemMetadataMap.java | ||
---|---|---|
3 | 3 |
import java.sql.SQLException; |
4 | 4 |
import java.util.Collection; |
5 | 5 |
import java.util.HashMap; |
6 |
import java.util.List; |
|
7 | 6 |
import java.util.Map; |
8 | 7 |
import java.util.Set; |
9 | 8 |
|
10 | 9 |
import org.apache.log4j.Logger; |
11 | 10 |
import org.dataone.service.exceptions.InvalidSystemMetadata; |
12 | 11 |
import org.dataone.service.types.v1.Identifier; |
13 |
import org.dataone.service.types.v1.ObjectInfo; |
|
14 |
import org.dataone.service.types.v1.ObjectList; |
|
15 | 12 |
import org.dataone.service.types.v1.SystemMetadata; |
16 | 13 |
|
17 |
import com.hazelcast.core.Hazelcast; |
|
18 | 14 |
import com.hazelcast.core.MapLoader; |
19 | 15 |
import com.hazelcast.core.MapStore; |
20 | 16 |
|
21 | 17 |
import edu.ucsb.nceas.metacat.IdentifierManager; |
22 | 18 |
import edu.ucsb.nceas.metacat.McdbDocNotFoundException; |
23 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
|
24 |
import edu.ucsb.nceas.utilities.PropertyNotFoundException; |
|
25 | 19 |
|
26 | 20 |
/** |
27 | 21 |
* Storage implementation for Hazelcast System Metadata |
... | ... | |
102 | 96 |
return map; |
103 | 97 |
} |
104 | 98 |
|
99 |
/** |
|
100 |
* Returning null so that no entries are loaded on map initialization |
|
101 |
* |
|
102 |
* @see http://www.hazelcast.com/docs/1.9.4/manual/single_html/#Map |
|
103 |
* |
|
104 |
* As of 1.9.3 MapLoader has the new MapLoader.loadAllKeys API. |
|
105 |
* It is used for pre-populating the in-memory map when the map is first touched/used. |
|
106 |
* If MapLoader.loadAllKeys returns NULL then nothing will be loaded. |
|
107 |
* Your MapLoader.loadAllKeys implementation can return all or some of the keys. |
|
108 |
* You may select and return only the hot keys, for instance. |
|
109 |
* Also note that this is the fastest way of pre-populating the map as |
|
110 |
* Hazelcast will optimize the loading process by having each node loading owned portion of the entries. |
|
111 |
*/ |
|
105 | 112 |
@Override |
106 | 113 |
public Set<Identifier> loadAllKeys() { |
107 |
|
|
108 |
String identifiersSet; |
|
109 |
try { |
|
110 |
identifiersSet = |
|
111 |
PropertyService.getProperty("dataone.hazelcast.storageCluster.identifiersSet"); |
|
112 |
} catch (PropertyNotFoundException e1) { |
|
113 |
identifiersSet = "hzIdentifiers"; |
|
114 |
} |
|
115 |
|
|
116 |
Set<Identifier> pids = Hazelcast.getSet(identifiersSet); |
|
117 |
|
|
118 |
try { |
|
119 |
|
|
120 |
// this has more overhead than just looking at the GUIDs |
|
121 |
ObjectList ol = IdentifierManager.getInstance().querySystemMetadata( |
|
122 |
null, //startTime, |
|
123 |
null, //endTime, |
|
124 |
null, //objectFormatId, |
|
125 |
false, //replicaStatus, |
|
126 |
0, //start, |
|
127 |
-1 //count |
|
128 |
); |
|
129 |
for (ObjectInfo o: ol.getObjectInfoList()) { |
|
130 |
Identifier pid = o.getIdentifier(); |
|
131 |
if ( !pids.contains(pid) ) { |
|
132 |
pids.add(pid); |
|
133 |
} |
|
134 |
} |
|
135 |
|
|
136 |
// ALTERNATIVE method: look up all the Identifiers from the table |
|
137 |
// List<String> guids = IdentifierManager.getInstance().getAllGUIDs(); |
|
138 |
// for (String guid: guids){ |
|
139 |
// Identifier pid = new Identifier(); |
|
140 |
// pid.setValue(guid); |
|
141 |
// pids.add(pid); |
|
142 |
// } |
|
143 |
|
|
144 |
} catch (Exception e) { |
|
145 |
throw new RuntimeException(e.getMessage(), e); |
|
146 |
|
|
147 |
} |
|
148 |
|
|
149 |
return pids; |
|
114 |
return null; |
|
150 | 115 |
} |
151 | 116 |
|
152 | 117 |
} |
src/edu/ucsb/nceas/metacat/IdentifierManager.java | ||
---|---|---|
632 | 632 |
* return a listing of all guids in the object store |
633 | 633 |
* @return a list of all GUIDs in metacat |
634 | 634 |
*/ |
635 |
public List<String> getAllGUIDs() |
|
635 |
public List<String> getAllSystemMetadataGUIDs()
|
|
636 | 636 |
{ |
637 | 637 |
Vector<String> guids = new Vector<String>(); |
638 |
String sql = "select guid from identifier";
|
|
638 |
String sql = "select guid from systemmetadata";
|
|
639 | 639 |
DBConnection dbConn = null; |
640 | 640 |
int serialNumber = -1; |
641 | 641 |
try |
Also available in: Unified diff
Do not loadAllKeys() for SystemMetadataMap when Metacat first starts up. hzIdentifiers will be populated with a simple SQL statement rather than the serial loading of every single SystemMetadata object. It will remain in synch using the usual entryXXX() methods as before.
This should save us resources where we were previously attempting to load ALL SystemMetadata into memory on startup.