Project

General

Profile

« Previous | Next » 

Revision 580

Added by berkley about 24 years ago

updated file locking mechanisms to use revisions instead of dates.

View differences:

src/edu/ucsb/nceas/metacat/MetacatReplication.java
218 218
                                    HttpServletResponse response)
219 219
  {
220 220
    System.out.println("in handlegetlockrequest");
221
    java.util.Date remoteDate = new java.util.Date();
222
    java.util.Date localDate = new java.util.Date();
223 221
    try
224 222
    {
225 223
      Connection conn = util.openDBConnection();
226 224
      String docid = ((String[])params.get("docid"))[0];
227
      String remoteDateStr = ((String[])params.get("updatedate"))[0];
225
      String remoteRev = ((String[])params.get("updaterev"))[0];
228 226
      DocumentImpl requestDoc = new DocumentImpl(conn, docid);
229

  
230
      String localDateStr = requestDoc.getUpdateDate();
231
      SimpleDateFormat formatter = new SimpleDateFormat ("yy-MM-dd HH:mm:ss");
232
      ParsePosition pos = new ParsePosition(0);
233
      remoteDate = formatter.parse(remoteDateStr, pos);
234
      pos = new ParsePosition(0);
235
      localDate = formatter.parse(localDateStr, pos);
236

  
237
      if(remoteDate.compareTo(localDate) >= 0)
227
      int localRevInt = requestDoc.getRev();
228
      int remoteRevInt = Integer.parseInt(remoteRev);
229
      
230
      if(remoteRevInt >= localRevInt)
238 231
      {
239 232
        if(!fileLocks.contains(docid))
240
        { //grant the lock
233
        { //grant the lock if it is not already locked
241 234
          fileLocks.add(0, docid); //insert at the beginning of the queue Vector
242 235
          //send a message back to the the remote host authorizing the insert
243 236
          out.println("<lockgranted><docid>" +docid+ "</docid></lockgranted>");
src/edu/ucsb/nceas/metacat/DocumentImpl.java
746 746
   * @param xml the xml stream to be loaded into the database
747 747
   * @param action the action to be performed (INSERT OR UPDATE)
748 748
   * @param docid the docid to use for the INSERT OR UPDATE
749
   * @param user the user that owns the document
750
   * @param group the group to which user belongs
751
   * @param serverCode the serverid from xml_replication on which this document
752
   *        resides.
753
   * @param override flag to stop insert replication checking.
754
   *        if override = true then a document not belonging to the local server
755
   *        will not be checked upon update for a file lock.
756
   *        if override = false then a document not from this server, upon 
757
   *        update will be locked and version checked.
749 758
   */
750 759

  
751 760
  public static String write( Connection conn, Reader xml, Reader acl,
......
761 770
    
762 771
    System.out.println("action: " + action + " servercode: " + 
763 772
                        serverCode + " override: " + override);
773
                        
764 774
    if((serverCode != 1 && action.equals("UPDATE")) && !override)
765 775
    { //if this document being written is not a resident of this server then
766 776
      //we need to try to get a lock from it's resident server.  If the
......
770 780
      int istreamInt; 
771 781
      char istreamChar;
772 782
      DocumentImpl newdoc = new DocumentImpl(conn, docid);
773
      String update = newdoc.getUpdateDate();
783
      int updaterev = newdoc.getRev();
774 784
      String server = MetacatReplication.getServer(serverCode);
775
      update = update.replace(' ', '+');
776
      URL u = new URL("http://" + server + "?action=getlock&updatedate=" + 
777
                      update + "&docid=" + docid);
785
      URL u = new URL("http://" + server + "?action=getlock&updaterev=" + 
786
                      updaterev + "&docid=" + docid);
778 787
      System.out.println("sending message: " + u.toString());
779 788
      String serverResStr = MetacatReplication.getURLContent(u);
780 789
      String openingtag = serverResStr.substring(0, serverResStr.indexOf(">")+1);
src/edu/ucsb/nceas/metacat/ReplicationHandler.java
124 124
        u = new URL("http://" + server + "?action=update");
125 125
        //System.out.println(u.toString());
126 126
        String result = MetacatReplication.getURLContent(u);
127
        //System.out.println(result);
127
        System.out.println(result);
128 128
        responses.add(result);
129 129
      }
130 130
      
......
390 390
        }
391 391
      }
392 392

  
393
      keys = null;
393 394
      keys = serverList.keys();
394 395
      while(keys.hasMoreElements())
395 396
      {

Also available in: Unified diff