Project

General

Profile

« Previous | Next » 

Revision 7433

remove document from the indexing queue when delete is called. http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5750

View differences:

src/edu/ucsb/nceas/metacat/IndexingQueue.java
120 120
            try {
121 121
            	indexingMap.wait();
122 122
            } catch (InterruptedException ex) {
123
              System.err.println("Interrupted");
123
              logMetacat.error("Interrupted");
124 124
            }
125 125
          }
126 126
          
......
132 132
        }
133 133
        return returnVal;
134 134
      }
135
    
136
    /**
137
     * Removes the Indexing Task object from the queue
138
     * for the given docid. Currently, rev is ignored
139
     * This method should be used to cancel scheduled indexing on a document
140
     * (typically if it is being deleted but indexing has not completed yet)
141
     * see http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5750
142
     * @param docid the docid (without revision)
143
     * @param rev the docid's rev (ignored)
144
     */
145
    public void remove(String docid, String rev) {
146
		synchronized (indexingMap) {
147
			if (indexingMap.containsKey(docid)) {
148
				indexingMap.remove(docid);
149
			}
150
		}
151
	}
135 152

  
136 153
}
137 154

  
......
157 174
	  public void run() {
158 175
	    while (metacatRunning) {
159 176
	      // blocks until job
160
	      IndexingQueueObject returnVal = 
177
	      IndexingQueueObject indexQueueObject = 
161 178
	    	  IndexingQueue.getInstance().getNext();
162 179

  
163
	      if(returnVal != null){
180
	      if(indexQueueObject != null){
164 181
	    	  if(!IndexingQueue.getInstance().
165
	    			currentDocidsBeingIndexed.contains(returnVal.getDocid())){
182
	    			currentDocidsBeingIndexed.contains(indexQueueObject.getDocid())){
166 183
    		  try {
167 184
    			  IndexingQueue.getInstance().
168
    			  		currentDocidsBeingIndexed.add(returnVal.getDocid());
169
    		      String docid = returnVal.getDocid() + "." + returnVal.getRev();
185
    			  		currentDocidsBeingIndexed.add(indexQueueObject.getDocid());
186
    		      String docid = indexQueueObject.getDocid() + "." + indexQueueObject.getRev();
170 187
    			  if(checkDocumentTable(docid, "xml_documents")){
171 188
    				  logMetacat.warn("Calling buildIndex for " + docid);
172 189
    				  DocumentImpl doc = new DocumentImpl(docid, false);
......
183 200
    			  logMetacat.warn("Exception: " + e);
184 201
    			  e.printStackTrace();
185 202
	        
186
    			  if(returnVal.getCount() < 25){
187
    				  returnVal.setCount(returnVal.getCount()+1);
203
    			  if(indexQueueObject.getCount() < 25){
204
    				  indexQueueObject.setCount(indexQueueObject.getCount()+1);
188 205
    				  // add the docid back to the list
189
    				  IndexingQueue.getInstance().add(returnVal);
206
    				  IndexingQueue.getInstance().add(indexQueueObject);
190 207
    			  } else {
191
    				  logMetacat.fatal("Docid " + returnVal.getDocid() 
208
    				  logMetacat.fatal("Docid " + indexQueueObject.getDocid() 
192 209
	        			+ " has been inserted to IndexingQueue "
193 210
	        			+ "more than 25 times. Not adding the docid to"
194 211
	        			+ " the queue again.");
195 212
    			  }
196 213
    		  	} finally {
197 214
    			  	IndexingQueue.getInstance().currentDocidsBeingIndexed
198
    			  		.remove(returnVal.getDocid());	    	  
215
    			  		.remove(indexQueueObject.getDocid());	    	  
199 216
    		  	}
200 217
	    	  } else {
201
	    		  returnVal.setCount(returnVal.getCount()+1);
202
	    		  IndexingQueue.getInstance().add(returnVal);    		  
218
	    		  indexQueueObject.setCount(indexQueueObject.getCount()+1);
219
	    		  IndexingQueue.getInstance().add(indexQueueObject);    		  
203 220
	    	  }
204 221
	      }
205 222
	    }
src/edu/ucsb/nceas/metacat/DocumentImpl.java
2920 2920
            	IndexingQueue.getInstance().add(docid, rev);
2921 2921
        }
2922 2922
    }
2923
    
2924
    private static void removeDocidFromIndexingQueue(String docid, String rev) throws PropertyNotFoundException {
2925
        boolean useXMLIndex =
2926
            (new Boolean(PropertyService.getProperty("database.usexmlindex"))).booleanValue();
2927
        if (useXMLIndex) {
2928
            	IndexingQueue.getInstance().remove(docid, rev);
2929
        }
2930
    }
2923 2931

  
2924 2932
    /**
2925 2933
     * Write an XML file to the database during replication
......
3309 3317
            double afterArchiveDocAndNode = System.currentTimeMillis()/1000;
3310 3318
            logMetacat.info("DocumentImpl.delete - The time for archiveDocAndNodesRevision is "+(afterArchiveDocAndNode - start));
3311 3319
            
3320
            // make sure we don't have a pending index task
3321
            removeDocidFromIndexingQueue(docid, String.valueOf(rev));
3322
            
3312 3323
            // Now delete it from the xml_index table
3313 3324
            pstmt = conn.prepareStatement("DELETE FROM xml_index WHERE docid = ?");
3314 3325
            pstmt.setString(1, docid);

Also available in: Unified diff