lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r955469 - in /lucene/solr/branches/branch-1.4: CHANGES.txt src/solrj/org/apache/solr/client/solrj/impl/StreamingUpdateSolrServer.java
Date Thu, 17 Jun 2010 03:01:18 GMT
Author: yonik
Date: Thu Jun 17 03:01:17 2010
New Revision: 955469

URL: http://svn.apache.org/viewvc?rev=955469&view=rev
Log:
SOLR-1885 and SOLR-1711: release connections to prevent hang

Modified:
    lucene/solr/branches/branch-1.4/CHANGES.txt
    lucene/solr/branches/branch-1.4/src/solrj/org/apache/solr/client/solrj/impl/StreamingUpdateSolrServer.java

Modified: lucene/solr/branches/branch-1.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/solr/branches/branch-1.4/CHANGES.txt?rev=955469&r1=955468&r2=955469&view=diff
==============================================================================
--- lucene/solr/branches/branch-1.4/CHANGES.txt (original)
+++ lucene/solr/branches/branch-1.4/CHANGES.txt Thu Jun 17 03:01:17 2010
@@ -73,7 +73,9 @@ Bug Fixes
   in TestBufferedTokenStream (Robert Muir, Uwe Schindler via shalin)
 
 * SOLR-1711: SolrJ - StreamingUpdateSolrServer had a race condition that
-  could halt the streaming of documents. (Attila Babo via yonik)
+  could halt the streaming of documents. The original patch to fix this
+  (never officially released) introduced another hanging bug due to
+  connections not being released.  (Attila Babo, Erik Hetzner via yonik)
   
 * SOLR-1748, SOLR-1747, SOLR-1746, SOLR-1745, SOLR-1744: Streams and Readers
   retrieved from ContentStreams are not closed in various places, resulting

Modified: lucene/solr/branches/branch-1.4/src/solrj/org/apache/solr/client/solrj/impl/StreamingUpdateSolrServer.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/branch-1.4/src/solrj/org/apache/solr/client/solrj/impl/StreamingUpdateSolrServer.java?rev=955469&r1=955468&r2=955469&view=diff
==============================================================================
--- lucene/solr/branches/branch-1.4/src/solrj/org/apache/solr/client/solrj/impl/StreamingUpdateSolrServer.java
(original)
+++ lucene/solr/branches/branch-1.4/src/solrj/org/apache/solr/client/solrj/impl/StreamingUpdateSolrServer.java
Thu Jun 17 03:01:17 2010
@@ -83,79 +83,81 @@ public class StreamingUpdateSolrServer e
       PostMethod method = null;
       try {
         do {
-        RequestEntity request = new RequestEntity() {
-          // we don't know the length
-          public long getContentLength() { return -1; }
-          public String getContentType() { return ClientUtils.TEXT_XML; }
-          public boolean isRepeatable()  { return false; }
-  
-          public void writeRequest(OutputStream out) throws IOException {
-            try {
-              OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
-              writer.append( "<stream>" ); // can be anything...
-              UpdateRequest req = queue.poll( 250, TimeUnit.MILLISECONDS );
-              while( req != null ) {
-                log.debug( "sending: {}" , req );
-                req.writeXML( writer ); 
-                
-                // check for commit or optimize
-                SolrParams params = req.getParams();
-                if( params != null ) {
-                  String fmt = null;
-                  if( params.getBool( UpdateParams.OPTIMIZE, false ) ) {
-                    fmt = "<optimize waitSearcher=\"%s\" waitFlush=\"%s\" />";
-                  }
-                  else if( params.getBool( UpdateParams.COMMIT, false ) ) {
-                    fmt = "<commit waitSearcher=\"%s\" waitFlush=\"%s\" />";
-                  }
-                  if( fmt != null ) {
-                    log.info( fmt );
-                    writer.write( String.format( fmt, 
-                        params.getBool( UpdateParams.WAIT_SEARCHER, false )+"",
-                        params.getBool( UpdateParams.WAIT_FLUSH, false )+"") );
+          try {
+            RequestEntity request = new RequestEntity() {
+              // we don't know the length
+              public long getContentLength() { return -1; }
+              public String getContentType() { return ClientUtils.TEXT_XML; }
+              public boolean isRepeatable()  { return false; }
+      
+              public void writeRequest(OutputStream out) throws IOException {
+                try {
+                  OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
+                  writer.append( "<stream>" ); // can be anything...
+                  UpdateRequest req = queue.poll( 250, TimeUnit.MILLISECONDS );
+                  while( req != null ) {
+                    log.debug( "sending: {}" , req );
+                    req.writeXML( writer ); 
+                    
+                    // check for commit or optimize
+                    SolrParams params = req.getParams();
+                    if( params != null ) {
+                      String fmt = null;
+                      if( params.getBool( UpdateParams.OPTIMIZE, false ) ) {
+                        fmt = "<optimize waitSearcher=\"%s\" waitFlush=\"%s\" />";
+                      }
+                      else if( params.getBool( UpdateParams.COMMIT, false ) ) {
+                        fmt = "<commit waitSearcher=\"%s\" waitFlush=\"%s\" />";
+                      }
+                      if( fmt != null ) {
+                        log.info( fmt );
+                        writer.write( String.format( fmt, 
+                            params.getBool( UpdateParams.WAIT_SEARCHER, false )+"",
+                            params.getBool( UpdateParams.WAIT_FLUSH, false )+"") );
+                      }
+                    }
+                    
+                    writer.flush();
+                    req = queue.poll( 250, TimeUnit.MILLISECONDS );
                   }
+                  writer.append( "</stream>" );
+                  writer.flush();
+                }
+                catch (InterruptedException e) {
+                  e.printStackTrace();
                 }
-                
-                writer.flush();
-                req = queue.poll( 250, TimeUnit.MILLISECONDS );
               }
-              writer.append( "</stream>" );
-              writer.flush();
+            };
+          
+            method = new PostMethod(_baseURL+updateUrl );
+            method.setRequestEntity( request );
+            method.setFollowRedirects( false );
+            method.addRequestHeader( "User-Agent", AGENT );
+            
+            int statusCode = getHttpClient().executeMethod(method);
+            if (statusCode != HttpStatus.SC_OK) {
+              StringBuilder msg = new StringBuilder();
+              msg.append( method.getStatusLine().getReasonPhrase() );
+              msg.append( "\n\n" );
+              msg.append( method.getStatusText() );
+              msg.append( "\n\n" );
+              msg.append( "request: "+method.getURI() );
+              handleError( new Exception( msg.toString() ) );
             }
-            catch (InterruptedException e) {
-              e.printStackTrace();
+          } finally {
+            try {
+              // make sure to release the connection
+              if(method != null)
+                method.releaseConnection();
             }
+            catch( Exception ex ){}
           }
-        };
-        
-        method = new PostMethod(_baseURL+updateUrl );
-        method.setRequestEntity( request );
-        method.setFollowRedirects( false );
-        method.addRequestHeader( "User-Agent", AGENT );
-        
-        int statusCode = getHttpClient().executeMethod(method);
-        if (statusCode != HttpStatus.SC_OK) {
-          StringBuilder msg = new StringBuilder();
-          msg.append( method.getStatusLine().getReasonPhrase() );
-          msg.append( "\n\n" );
-          msg.append( method.getStatusText() );
-          msg.append( "\n\n" );
-          msg.append( "request: "+method.getURI() );
-          handleError( new Exception( msg.toString() ) );
-        }
-        }  while( ! queue.isEmpty());
+        } while( ! queue.isEmpty());
       }
       catch (Throwable e) {
         handleError( e );
       } 
       finally {
-        try {
-          // make sure to release the connection
-          if(method != null)
-          method.releaseConnection();
-        }
-        catch( Exception ex ){}
-        
         // remove it from the list of running things...
         synchronized (runners) {
           runners.remove( this );



Mime
View raw message