Revision 5175
Added by daigle almost 15 years ago
src/edu/ucsb/nceas/metacat/replication/ReplicationHandler.java | ||
---|---|---|
77 | 77 |
private static int DOCERRORNUMBER = 1; |
78 | 78 |
private static int REVINSERTNUMBER = 1; |
79 | 79 |
private static int REVERRORNUMBER = 1; |
80 |
|
|
81 |
private static int _xmlDocQueryCount = 0; |
|
82 |
private static int _xmlRevQueryCount = 0; |
|
83 |
private static long _xmlDocQueryTime = 0; |
|
84 |
private static long _xmlRevQueryTime = 0; |
|
85 |
|
|
86 |
|
|
80 | 87 |
public ReplicationHandler() |
81 | 88 |
{ |
82 | 89 |
//this.out = o; |
... | ... | |
111 | 118 |
} |
112 | 119 |
|
113 | 120 |
/** |
114 |
* Method that uses revision taging for replication instead of update_date. |
|
121 |
* Method that uses revision tagging for replication instead of update_date.
|
|
115 | 122 |
*/ |
116 | 123 |
private void update() |
117 | 124 |
{ |
125 |
|
|
126 |
_xmlDocQueryCount = 0; |
|
127 |
_xmlRevQueryCount = 0; |
|
128 |
_xmlDocQueryTime = 0; |
|
129 |
_xmlRevQueryTime = 0; |
|
118 | 130 |
/* |
119 | 131 |
Pseudo-algorithm |
120 | 132 |
- request a doc list from each server in xml_replication |
... | ... | |
136 | 148 |
// String update; |
137 | 149 |
Vector<String> responses = new Vector<String>(); |
138 | 150 |
URL u; |
139 |
|
|
140 |
|
|
151 |
long replicationStartTime = System.currentTimeMillis(); |
|
152 |
long timeToGetServerList = 0; |
|
141 | 153 |
|
142 | 154 |
//Check for every server in server list to get updated list and put |
143 | 155 |
// them in to response |
156 |
long startTimeToGetServers = System.currentTimeMillis(); |
|
144 | 157 |
for (int i=0; i<serverList.size(); i++) |
145 | 158 |
{ |
146 | 159 |
// Get ReplicationServer object from server list |
... | ... | |
165 | 178 |
continue; |
166 | 179 |
} |
167 | 180 |
|
168 |
logReplication.info("docid: "+server+" "+result);
|
|
181 |
//logReplication.info("ReplicationHandler.update - docid: "+server+" "+result);
|
|
169 | 182 |
//check if result have error or not, if has skip it. |
170 | 183 |
if (result.indexOf("<error>")!=-1 && result.indexOf("</error>")!=-1) |
171 | 184 |
{ |
... | ... | |
177 | 190 |
//Add result to vector |
178 | 191 |
responses.add(result); |
179 | 192 |
} |
193 |
timeToGetServerList = System.currentTimeMillis() - startTimeToGetServers; |
|
180 | 194 |
|
181 | 195 |
//make sure that there is updated file list |
182 | 196 |
//If response is null, metacat don't need do anything |
... | ... | |
189 | 203 |
} |
190 | 204 |
|
191 | 205 |
|
192 |
logReplication.info("ReplicationHandler.update - Responses from remote metacat about updated "+ |
|
193 |
"document information: "+ responses.toString()); |
|
206 |
//logReplication.info("ReplicationHandler.update - Responses from remote metacat about updated "+ |
|
207 |
// "document information: "+ responses.toString()); |
|
208 |
|
|
209 |
long totalServerListParseTime = 0; |
|
194 | 210 |
// go through response vector(it contains updated vector and delete vector |
195 | 211 |
for(int i=0; i<responses.size(); i++) |
196 | 212 |
{ |
213 |
long startServerListParseTime = System.currentTimeMillis(); |
|
197 | 214 |
XMLReader parser; |
198 | 215 |
ReplMessageHandler message = new ReplMessageHandler(); |
199 | 216 |
try |
... | ... | |
257 | 274 |
DOCERRORNUMBER = 1; |
258 | 275 |
REVINSERTNUMBER = 1; |
259 | 276 |
REVERRORNUMBER = 1; |
277 |
|
|
278 |
totalServerListParseTime += (System.currentTimeMillis() - startServerListParseTime); |
|
260 | 279 |
}//for response |
261 | 280 |
|
262 | 281 |
//updated last_checked |
... | ... | |
273 | 292 |
continue; |
274 | 293 |
} |
275 | 294 |
}//for |
295 |
|
|
296 |
long replicationEndTime = System.currentTimeMillis(); |
|
297 |
logMetacat.debug("ReplicationHandler.update - Total replication time: " + |
|
298 |
(replicationEndTime - replicationStartTime)); |
|
299 |
logMetacat.debug("ReplicationHandler.update - time to get server list: " + |
|
300 |
timeToGetServerList); |
|
301 |
logMetacat.debug("ReplicationHandler.update - server list parse time: " + |
|
302 |
totalServerListParseTime); |
|
303 |
logMetacat.debug("ReplicationHandler.update - 'in xml_documents' total query count: " + |
|
304 |
_xmlDocQueryCount); |
|
305 |
logMetacat.debug("ReplicationHandler.update - 'in xml_documents' total query time: " + |
|
306 |
_xmlDocQueryTime + " ms"); |
|
307 |
logMetacat.debug("ReplicationHandler.update - 'in xml_revisions' total query count: " + |
|
308 |
_xmlRevQueryCount); |
|
309 |
logMetacat.debug("ReplicationHandler.update - 'in xml_revisions' total query time: " + |
|
310 |
_xmlRevQueryTime + " ms");; |
|
276 | 311 |
|
277 | 312 |
}//update |
278 | 313 |
|
... | ... | |
450 | 485 |
String docInfoStr = ReplicationService.getURLContent(docinfoUrl); |
451 | 486 |
docinfoParser.parse(new InputSource(new StringReader(docInfoStr))); |
452 | 487 |
Hashtable<String, String> docinfoHash = dih.getDocInfo(); |
453 |
// Get doicd owner
|
|
488 |
// Get docid owner
|
|
454 | 489 |
String user = docinfoHash.get("user_owner"); |
455 | 490 |
// Get docid name (such as acl or dataset) |
456 | 491 |
String docName = docinfoHash.get("docname"); |
457 | 492 |
// Get doc type (eml public id) |
458 | 493 |
String docType = docinfoHash.get("doctype"); |
459 | 494 |
// Get docid home sever. it might be different to remoteserver |
460 |
// becuause of hub feature
|
|
495 |
// because of hub feature |
|
461 | 496 |
String docHomeServer = docinfoHash.get("home_server"); |
462 | 497 |
String createdDate = docinfoHash.get("date_created"); |
463 | 498 |
String updatedDate = docinfoHash.get("date_updated"); |
... | ... | |
502 | 537 |
|
503 | 538 |
logReplication.info("ReplicationHandler.handleSingleDataFile - Successfully to write datafile " + accNumber); |
504 | 539 |
/*MetacatReplication.replLog("wrote datafile " + accNumber + " from " + |
505 |
remoteserver);*/ |
|
540 |
remote server);*/
|
|
506 | 541 |
if (tableName.equals(DocumentImpl.DOCUMENTTABLE)) |
507 | 542 |
{ |
508 | 543 |
logReplication.info("ReplicationHandler.handleSingleDataFile - " + DOCINSERTNUMBER + " Wrote data file" + accNumber + |
... | ... | |
530 | 565 |
}//try |
531 | 566 |
catch(Exception e) |
532 | 567 |
{ |
533 |
/*MetacatReplication.replErrorLog("Failed to try wrote datafile " + accNumber + |
|
568 |
/*MetacatReplication.replErrorLog("Failed to try wrote data file " + accNumber +
|
|
534 | 569 |
" because " +e.getMessage());*/ |
535 | 570 |
if (tableName.equals(DocumentImpl.DOCUMENTTABLE)) |
536 | 571 |
{ |
... | ... | |
707 | 742 |
{ |
708 | 743 |
throw new Exception("Couldn't get catalog list form server " +server); |
709 | 744 |
} |
710 |
logReplication.info("ReplicationHandler.updateCatalog - catxml: " + catxml);
|
|
745 |
logReplication.debug("ReplicationHandler.updateCatalog - catxml: " + catxml);
|
|
711 | 746 |
CatalogMessageHandler cmh = new CatalogMessageHandler(); |
712 | 747 |
XMLReader catparser = initParser(cmh); |
713 | 748 |
catparser.parse(new InputSource(new StringReader(catxml))); |
714 | 749 |
//parse the returned catalog xml and put it into a vector |
715 | 750 |
remoteCatalog = cmh.getCatalogVect(); |
716 | 751 |
|
717 |
// Makse sure remoteCatalog is not empty
|
|
752 |
// Make sure remoteCatalog is not empty |
|
718 | 753 |
if (remoteCatalog.isEmpty()) |
719 | 754 |
{ |
720 | 755 |
throw new Exception("Couldn't get catalog list form server " +server); |
... | ... | |
801 | 836 |
finally |
802 | 837 |
{ |
803 | 838 |
DBConnectionPool.returnDBConnection(dbConn, serialNumber); |
804 |
}//finall |
|
839 |
}//finally
|
|
805 | 840 |
}//for remote catalog |
806 | 841 |
}//for server list |
807 | 842 |
logReplication.info("End of updateCatalog"); |
... | ... | |
940 | 975 |
} |
941 | 976 |
|
942 | 977 |
/** |
943 |
* This method will combinate given time string(in short format) to current
|
|
978 |
* This method will combine given time string(in short format) to current |
|
944 | 979 |
* date. If the given time (e.g 10:00 AM) passed the current time (e.g 2:00 |
945 | 980 |
* PM Aug 21, 2005), then the time will set to second day, 10:00 AM Aug 22, |
946 | 981 |
* 2005. If the given time (e.g 10:00 AM) haven't passed the current time |
... | ... | |
996 | 1031 |
} |
997 | 1032 |
|
998 | 1033 |
/* |
999 |
* Pasre a given string to date and time. Date format is long and time
|
|
1034 |
* Parse a given string to date and time. Date format is long and time
|
|
1000 | 1035 |
* format is short. |
1001 | 1036 |
*/ |
1002 | 1037 |
private static Date parseDateTime(String timeString) throws ParseException |
... | ... | |
1061 | 1096 |
// Get revision number |
1062 | 1097 |
int rev = Integer.parseInt((String) w.elementAt(1)); |
1063 | 1098 |
logReplication.info("rev: " + rev); |
1064 |
// Get remote server name (it is may not be doc homeserver because |
|
1099 |
// Get remote server name (it is may not be doc home server because
|
|
1065 | 1100 |
// the new hub feature |
1066 | 1101 |
String remoteServer = (String) w.elementAt(2); |
1067 | 1102 |
remoteServer = remoteServer.trim(); |
... | ... | |
1081 | 1116 |
+ " in time replication" + e.getMessage()); |
1082 | 1117 |
continue; |
1083 | 1118 |
} |
1119 |
|
|
1120 |
if (_xmlDocQueryCount > 0 && (_xmlDocQueryCount % 100) == 0) { |
|
1121 |
logMetacat.debug("ReplicationHandler.update - xml_doc query count: " + _xmlDocQueryCount + |
|
1122 |
", xml_doc avg query time: " + (_xmlDocQueryTime / _xmlDocQueryCount)); |
|
1123 |
} |
|
1124 |
|
|
1125 |
if (_xmlRevQueryCount > 0 && (_xmlRevQueryCount % 100) == 0) { |
|
1126 |
logMetacat.debug("ReplicationHandler.update - xml_rev query count: " + _xmlRevQueryCount + |
|
1127 |
", xml_rev avg query time: " + (_xmlRevQueryTime / _xmlRevQueryCount)); |
|
1128 |
} |
|
1084 | 1129 |
|
1085 | 1130 |
}// for update docs |
1086 | 1131 |
|
... | ... | |
1098 | 1143 |
boolean flag = false; |
1099 | 1144 |
try |
1100 | 1145 |
{ |
1146 |
long docQueryStartTime = System.currentTimeMillis(); |
|
1101 | 1147 |
localrev = DBUtil.getLatestRevisionInDocumentTable(docid); |
1148 |
long docQueryEndTime = System.currentTimeMillis(); |
|
1149 |
_xmlDocQueryTime += (docQueryEndTime - docQueryStartTime); |
|
1150 |
_xmlDocQueryCount++; |
|
1102 | 1151 |
} |
1103 | 1152 |
catch (SQLException e) |
1104 | 1153 |
{ |
... | ... | |
1121 | 1170 |
// check if the revision is in the revision table |
1122 | 1171 |
Vector<Integer> localRevVector = null; |
1123 | 1172 |
try { |
1173 |
long revQueryStartTime = System.currentTimeMillis(); |
|
1124 | 1174 |
localRevVector = DBUtil.getRevListFromRevisionTable(docid); |
1175 |
long revQueryEndTime = System.currentTimeMillis(); |
|
1176 |
_xmlRevQueryTime += (revQueryEndTime - revQueryStartTime); |
|
1177 |
_xmlRevQueryCount++; |
|
1125 | 1178 |
} catch (SQLException sqle) { |
1126 | 1179 |
throw new HandlerException("ReplicationHandler.handleDocInXMLDocuments - SQL error " |
1127 | 1180 |
+ " when getting rev list for docid: " + docid + " : " + sqle.getMessage()); |
... | ... | |
1184 | 1237 |
} |
1185 | 1238 |
catch(HandlerException he) |
1186 | 1239 |
{ |
1187 |
// skip this datafile |
|
1240 |
// skip this data file
|
|
1188 | 1241 |
throw he; |
1189 | 1242 |
} |
1190 | 1243 |
|
1191 |
}//for datafile |
|
1244 |
}//for data file
|
|
1192 | 1245 |
} |
1193 | 1246 |
|
1194 | 1247 |
/* |
... | ... | |
1206 | 1259 |
boolean flag = false; |
1207 | 1260 |
try |
1208 | 1261 |
{ |
1262 |
long revQueryStartTime = System.currentTimeMillis(); |
|
1209 | 1263 |
localrev = DBUtil.getRevListFromRevisionTable(docid); |
1264 |
long revQueryEndTime = System.currentTimeMillis(); |
|
1265 |
_xmlRevQueryTime += (revQueryEndTime - revQueryStartTime); |
|
1266 |
_xmlRevQueryCount++; |
|
1210 | 1267 |
} |
1211 | 1268 |
catch (SQLException sqle) |
1212 | 1269 |
{ |
... | ... | |
1257 | 1314 |
} |
1258 | 1315 |
catch(HandlerException he) |
1259 | 1316 |
{ |
1260 |
// skip this datafile |
|
1317 |
// skip this data file
|
|
1261 | 1318 |
throw he; |
1262 | 1319 |
} |
1263 | 1320 |
|
1264 |
}//for datafile |
|
1321 |
}//for data file
|
|
1265 | 1322 |
} |
1266 | 1323 |
|
1267 | 1324 |
/* |
Also available in: Unified diff
Log doc and rev query counts and times. Fix mis-spellings.