Revision 625
Added by berkley about 24 years ago
src/edu/ucsb/nceas/metacat/MetacatReplication.java | ||
---|---|---|
426 | 426 |
System.out.println("received update request"); |
427 | 427 |
StringBuffer docsql = new StringBuffer(); |
428 | 428 |
StringBuffer doclist = new StringBuffer(); |
429 |
Vector packageFiles = new Vector(); |
|
429 | 430 |
|
430 | 431 |
//get all docs that reside on this server |
431 | 432 |
doclist.append("<?xml version=\"1.0\"?><replication>"); |
... | ... | |
433 | 434 |
doclist.append(util.getOption("replicationpath")); |
434 | 435 |
doclist.append("</server><updates>"); |
435 | 436 |
|
436 |
docsql.append("select docid, rev from xml_documents where "); |
|
437 |
docsql.append("select docid, rev, doctype from xml_documents where ");
|
|
437 | 438 |
docsql.append("server_location = 1"); |
438 | 439 |
|
439 | 440 |
//get any deleted documents |
... | ... | |
449 | 450 |
boolean tablehasrows = rs.next(); |
450 | 451 |
while(tablehasrows) |
451 | 452 |
{ |
452 |
doclist.append("<updatedDocument>"); |
|
453 |
doclist.append("<docid>").append(rs.getString(1)); |
|
454 |
doclist.append("</docid><rev>").append(rs.getInt(2)); |
|
455 |
doclist.append("</rev>"); |
|
456 |
doclist.append("</updatedDocument>"); |
|
453 |
if(!rs.getString(3).equals(util.getOption("packagedoctype"))) |
|
454 |
{ //if this is a package file, put it at the end |
|
455 |
//because if a package file is read before all of the files it |
|
456 |
//refers to are loaded then there is an error |
|
457 |
doclist.append("<updatedDocument>"); |
|
458 |
doclist.append("<docid>").append(rs.getString(1)); |
|
459 |
doclist.append("</docid><rev>").append(rs.getInt(2)); |
|
460 |
doclist.append("</rev>"); |
|
461 |
doclist.append("</updatedDocument>"); |
|
462 |
} |
|
463 |
else |
|
464 |
{ //the package files are saved to be put into the xml later. |
|
465 |
Vector v = new Vector(); |
|
466 |
v.add(new String(rs.getString(1))); |
|
467 |
v.add(new Integer(rs.getInt(2))); |
|
468 |
packageFiles.add(new Vector(v)); |
|
469 |
} |
|
457 | 470 |
tablehasrows = rs.next(); |
458 | 471 |
} |
459 | 472 |
|
... | ... | |
469 | 482 |
tablehasrows = rs.next(); |
470 | 483 |
} |
471 | 484 |
|
485 |
//now we can put the package files into the xml results |
|
486 |
for(int i=0; i<packageFiles.size(); i++) |
|
487 |
{ |
|
488 |
Vector v = (Vector)packageFiles.elementAt(i); |
|
489 |
doclist.append("<updatedDocument>"); |
|
490 |
doclist.append("<docid>").append((String)v.elementAt(0)); |
|
491 |
doclist.append("</docid><rev>"); |
|
492 |
doclist.append(((Integer)v.elementAt(1)).intValue()); |
|
493 |
doclist.append("</rev>"); |
|
494 |
doclist.append("</updatedDocument>"); |
|
495 |
} |
|
496 |
|
|
472 | 497 |
doclist.append("</updates></replication>"); |
473 | 498 |
MetaCatUtil.debugMessage("doclist: " + doclist.toString()); |
474 | 499 |
conn.close(); |
475 | 500 |
response.setContentType("text/xml"); |
476 | 501 |
out.println(doclist.toString()); |
502 |
System.out.println("doclist: " + doclist.toString()); |
|
477 | 503 |
System.out.println("update request handled"); |
478 | 504 |
} |
479 | 505 |
catch(Exception e) |
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
910 | 910 |
// Find the document id number |
911 | 911 |
docidstr = ((String[])params.get("docid"))[0]; |
912 | 912 |
docid = docidstr; |
913 |
|
|
913 | 914 |
conn = util.getConnection(); |
914 | 915 |
DocumentImpl xmldoc = new DocumentImpl(conn, docid); |
915 | 916 |
// Get the document indicated from the db |
src/edu/ucsb/nceas/metacat/DocumentImpl.java | ||
---|---|---|
976 | 976 |
stmt.close(); |
977 | 977 |
conn.commit(); |
978 | 978 |
conn.setAutoCommit(true); |
979 |
|
|
979 | 980 |
} |
980 | 981 |
|
981 | 982 |
/** |
src/edu/ucsb/nceas/metacat/ReplicationHandler.java | ||
---|---|---|
126 | 126 |
responses.add(result); |
127 | 127 |
} |
128 | 128 |
|
129 |
System.out.println("responses: " + responses.toString()); |
|
129 |
//System.out.println("responses: " + responses.toString());
|
|
130 | 130 |
|
131 | 131 |
for(int i=0; i<responses.size(); i++) |
132 | 132 |
{ //check each server for updated files |
... | ... | |
191 | 191 |
docinfoParser.parse(new InputSource(new StringReader(docInfoStr))); |
192 | 192 |
Hashtable docinfoHash = dih.getDocInfo(); |
193 | 193 |
int serverCode = MetacatReplication.getServerCode(docServer); |
194 |
MetaCatUtil.debugMessage("updating doc: " + docid + " action: "+ action); |
|
195 |
String newDocid = DocumentImpl.write(conn, |
|
194 |
System.out.println("updating doc: " + docid + " action: "+ action); |
|
195 |
try |
|
196 |
{ |
|
197 |
String newDocid = DocumentImpl.write(conn, |
|
196 | 198 |
new StringReader(newxmldoc), |
197 | 199 |
null, |
198 | 200 |
action, |
... | ... | |
201 | 203 |
(String)docinfoHash.get("user_owner"), |
202 | 204 |
serverCode, |
203 | 205 |
true); |
204 |
MetacatReplication.replLog("wrote doc " + docid + " from " + |
|
205 |
docServer); |
|
206 |
System.out.println("wrote doc " + docid + " from " + |
|
207 |
docServer); |
|
206 |
MetacatReplication.replLog("wrote doc " + docid + " from " + |
|
207 |
docServer); |
|
208 |
System.out.println("wrote doc " + docid + " from " + |
|
209 |
docServer); |
|
210 |
} |
|
211 |
catch(Exception e) |
|
212 |
{ |
|
213 |
System.out.println("error writing document " + docid); |
|
214 |
} |
|
208 | 215 |
} |
209 | 216 |
} |
210 | 217 |
|
src/edu/ucsb/nceas/metacat/ForceReplicationHandler.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* '$RCSfile$' |
3 |
* Purpose: A class to asyncronously force the replication of each server
|
|
3 |
* Purpose: A class to asyncronously force the replication of each server |
|
4 | 4 |
* that has an entry in the xml_replication table. When run, this thread |
5 | 5 |
* communicates with each server in the list and solicites a read of an |
6 | 6 |
* updated or newly inserted document with a certain docid. |
Also available in: Unified diff
cleaned up code