Project

General

Profile

« Previous | Next » 

Revision 1012

Added by Jing Tao about 22 years ago

Fixed the bug metacat will set server location to 1, no matter it is.

View differences:

DocumentImpl.java
949 949
                             String action, String docid, String user,
950 950
                             String[] groups, boolean validate)
951 951
                throws Exception {
952
    return write(conn,xml,pub,dtd,action,docid,user,groups,1,false,validate);
952
    //this method will be called in handleUpdateOrInsert method 
953
    //in MetacatServlet class
954
    // get server location for this doc
955
    int serverLocation=getServerLocationNumber(conn,docid);
956
    //System.out.println("server location: "+serverLocation);
957
    return write(conn,xml,pub,dtd,action,docid,user,groups,serverLocation,false,
958
                 validate);
953 959
  }
954 960

  
955 961
  public static String write(Connection conn, Reader xml, String pub,
......
1022 1028
                throws Exception
1023 1029
  {
1024 1030
    // NEW - WHEN CLIENT ALWAYS PROVIDE ACCESSION NUMBER INCLUDING REV IN IT
1031
    MetaCatUtil util = new MetaCatUtil();
1025 1032
    AccessionNumber ac = new AccessionNumber(conn, accnum, action);
1026 1033
    String docid = ac.getDocid();
1027 1034
    String rev = ac.getRev();
......
1040 1047
      String updaterev = id.getRev();
1041 1048
      String server = MetacatReplication.getServer(serverCode);
1042 1049
      MetacatReplication.replLog("attempting to lock " + accnum);
1043
      URL u = new URL("https://" + server + "?action=getlock&updaterev=" + 
1044
                      updaterev + "&docid=" + docid);
1045
      System.out.println("sending message: " + u.toString());
1050
      URL u = new URL("https://" + server + "?server="
1051
           +util.getLocalReplicationServerName()+"&action=getlock&updaterev=" 
1052
           +updaterev + "&docid=" + docid);
1053
      //System.out.println("sending message: " + u.toString());
1046 1054
      String serverResStr = MetacatReplication.getURLContent(u);
1047 1055
      String openingtag =serverResStr.substring(0, serverResStr.indexOf(">")+1);
1048
      
1049 1056
      if(openingtag.equals("<lockgranted>"))
1050 1057
      {//the lock was granted go ahead with the insert
1051 1058
        try 
1052 1059
        {
1060
          //System.out.println("In lockgranted");
1053 1061
          MetacatReplication.replLog("lock granted for " + accnum + " from " +
1054 1062
                                      server);
1055 1063
          XMLReader parser = initializeParser(conn, action, docid, updaterev,
......
1125 1133
    
1126 1134
    //force replicate out the new document to each server in our server list.
1127 1135
    if(serverCode == 1)
1128
    { //start the thread to replicate this new document out to the other servers
1136
    { 
1137
      
1138
      //start the thread to replicate this new document out to the other servers
1129 1139
      ForceReplicationHandler frh = new ForceReplicationHandler(accnum, action);
1130 1140
      
1131 1141
    }
......
1341 1351
  }//getLatestRevisionNumber
1342 1352
  
1343 1353
  /**
1354
   * Get server location form database for a accNum
1355
   * 
1356
   * @param accum <sitecode>.<uniqueid>.<rev>
1357
   */
1358
  private static int getServerLocationNumber(Connection conn, String accNum)
1359
                                            throws SQLException
1360
  {
1361
    //get rid of revNum part
1362
    String docId=MetaCatUtil.getDocIdFromString(accNum);
1363
    PreparedStatement pStmt;
1364
    int serverLocation;
1365
     
1366
    pStmt = conn.prepareStatement
1367
      ("SELECT server_location FROM xml_documents WHERE docid='" + docId + "'");
1368
    pStmt.execute();
1369

  
1370
    ResultSet rs = pStmt.getResultSet();
1371
    boolean hasRow = rs.next();
1372
    //if there is entry in xml_documents, get the serverlocation
1373
    if (hasRow)
1374
    {
1375
      serverLocation = rs.getInt(1);
1376
      pStmt.close();
1377
    }
1378
    else
1379
    {
1380
      // if htere is no entry in xml_documents, we consider it is new document
1381
      // the server location is local host and value is 1
1382
      serverLocation=1;
1383
      pStmt.close();
1384
    }
1385
      
1386
    return serverLocation;
1387
  }
1388
  /**
1344 1389
   * the main routine used to test the DBWriter utility.
1345 1390
   * <p>
1346 1391
   * Usage: java DocumentImpl <-f filename -a action -d docid>

Also available in: Unified diff