Revision: 48147
Author:   rainman
Date:     2009-03-07 22:40:39 +0000 (Sat, 07 Mar 2009)

Log Message:
-----------
* Add new switch to take only certain indexes out of rotation on index update. 
This can be useful 
  when couple of hosts have redundant copies of some (but not all) indexes. 
* cleanup some logs and detect empty queries

Modified Paths:
--------------
    
branches/lucene-search-2.1/src/org/wikimedia/lsearch/frontend/SearchDaemon.java
    
branches/lucene-search-2.1/src/org/wikimedia/lsearch/interoperability/RMIMessenger.java
    
branches/lucene-search-2.1/src/org/wikimedia/lsearch/interoperability/RMIMessengerClient.java
    
branches/lucene-search-2.1/src/org/wikimedia/lsearch/interoperability/RMIMessengerImpl.java
    
branches/lucene-search-2.1/src/org/wikimedia/lsearch/search/SearchEngine.java
    
branches/lucene-search-2.1/src/org/wikimedia/lsearch/search/SearcherCache.java
    
branches/lucene-search-2.1/src/org/wikimedia/lsearch/search/UpdateThread.java

Modified: 
branches/lucene-search-2.1/src/org/wikimedia/lsearch/frontend/SearchDaemon.java
===================================================================
--- 
branches/lucene-search-2.1/src/org/wikimedia/lsearch/frontend/SearchDaemon.java 
    2009-03-07 21:55:06 UTC (rev 48146)
+++ 
branches/lucene-search-2.1/src/org/wikimedia/lsearch/frontend/SearchDaemon.java 
    2009-03-07 22:40:39 UTC (rev 48147)
@@ -359,6 +359,12 @@
                                }
                        }
                }
+               ArrayList<String> outOfRotation = 
cache.indexesTakenOutOfRotation();
+               if( !outOfRotation.isEmpty() ){
+                       sendOutputLine("Out of rotation:");
+                       for(String s : outOfRotation)
+                               sendOutputLine(s);
+               }
        }
        
        // never use keepalive

Modified: 
branches/lucene-search-2.1/src/org/wikimedia/lsearch/interoperability/RMIMessenger.java
===================================================================
--- 
branches/lucene-search-2.1/src/org/wikimedia/lsearch/interoperability/RMIMessenger.java
     2009-03-07 21:55:06 UTC (rev 48146)
+++ 
branches/lucene-search-2.1/src/org/wikimedia/lsearch/interoperability/RMIMessenger.java
     2009-03-07 22:40:39 UTC (rev 48147)
@@ -266,4 +266,22 @@
        
        /** Remote host has been deployed */
        public void hostDeployed(String host) throws RemoteException;
+       
+       /**
+        * Take index out of rotation temporarely 
+        * 
+        * @param host
+        * @param dbrole
+        * @throws RemoteException
+        */
+       public void takeOutOfRotation(String host, String dbrole) throws 
RemoteException;
+       
+       /** 
+        * Put index back to rotation 
+        * 
+        * @param host
+        * @param dbrole
+        * @throws RemoteException
+        */
+       public void returnToRotation(String host, String dbrole) throws 
RemoteException;
 }

Modified: 
branches/lucene-search-2.1/src/org/wikimedia/lsearch/interoperability/RMIMessengerClient.java
===================================================================
--- 
branches/lucene-search-2.1/src/org/wikimedia/lsearch/interoperability/RMIMessengerClient.java
       2009-03-07 21:55:06 UTC (rev 48146)
+++ 
branches/lucene-search-2.1/src/org/wikimedia/lsearch/interoperability/RMIMessengerClient.java
       2009-03-07 22:40:39 UTC (rev 48147)
@@ -429,5 +429,28 @@
                        log.error("Messenger not bound: "+e.getMessage(),e);
                }       
        }
+       
+       public void takeOutOfRotation(String host, String myHost, String 
dbrole) throws RemoteException {
+               RMIMessenger r;
+               try {
+                       r = messengerFromCache(host);
+                       r.takeOutOfRotation(myHost, dbrole);
+               } catch(NotBoundException e){
+                       e.printStackTrace();
+                       log.error("Messenger not bound: "+e.getMessage(),e);
+               }       
+               
+       }
 
+       public void returnToRotation(String host, String myHost, String dbrole) 
throws RemoteException {
+               RMIMessenger r;
+               try {
+                       r = messengerFromCache(host);
+                       r.returnToRotation(myHost, dbrole);
+               } catch(NotBoundException e){
+                       e.printStackTrace();
+                       log.error("Messenger not bound: "+e.getMessage(),e);
+               }       
+       }
+
 }

Modified: 
branches/lucene-search-2.1/src/org/wikimedia/lsearch/interoperability/RMIMessengerImpl.java
===================================================================
--- 
branches/lucene-search-2.1/src/org/wikimedia/lsearch/interoperability/RMIMessengerImpl.java
 2009-03-07 21:55:06 UTC (rev 48146)
+++ 
branches/lucene-search-2.1/src/org/wikimedia/lsearch/interoperability/RMIMessengerImpl.java
 2009-03-07 22:40:39 UTC (rev 48147)
@@ -254,7 +254,20 @@
                        cache = SearcherCache.getInstance();
                cache.hostDeploying(host);
        }
+       
+       public void takeOutOfRotation(String host, String dbrole) throws 
RemoteException {
+               if(cache == null)
+                       cache = SearcherCache.getInstance();
+               cache.takeOutOfRotation(host, dbrole);
+               
+       }
 
+       public void returnToRotation(String host, String dbrole) throws 
RemoteException {
+               if(cache == null)
+                       cache = SearcherCache.getInstance();
+               cache.returnToRotation(host, dbrole);
+       }
+
        protected RMIMessengerImpl(){
                networkStatus = null;
                indexRegistry = null;

Modified: 
branches/lucene-search-2.1/src/org/wikimedia/lsearch/search/SearchEngine.java
===================================================================
--- 
branches/lucene-search-2.1/src/org/wikimedia/lsearch/search/SearchEngine.java   
    2009-03-07 21:55:06 UTC (rev 48146)
+++ 
branches/lucene-search-2.1/src/org/wikimedia/lsearch/search/SearchEngine.java   
    2009-03-07 22:40:39 UTC (rev 48147)
@@ -592,6 +592,13 @@
                Hashtable<String,NamespaceFilter> cachedFilters = 
GlobalConfiguration.getInstance().getNamespacePrefixes();
                boolean searchAll = false;
                
+               // check for empty queries
+               if(searchterm.equals("")){
+                       res = new SearchResults();
+                       res.setErrorMsg("Empty search");
+                       return res;
+               }
+               
                // if search is over one field, try to use filters
                if(fields.size()==1){
                        if(fields.contains(new NamespaceFilter())){
@@ -702,7 +709,7 @@
                                e.printStackTrace();
                                res = new SearchResults();
                                res.retry();
-                               log.warn("Retry, temportal error for query: 
["+q+"] on "+iid+" : "+e.getMessage(),e);
+                               log.warn("Retry, temporal error for query: 
["+searchterm+"] on "+iid+" : "+e.getMessage(),e);
                                return res;
                        }                       
                } catch(ParseException e){

Modified: 
branches/lucene-search-2.1/src/org/wikimedia/lsearch/search/SearcherCache.java
===================================================================
--- 
branches/lucene-search-2.1/src/org/wikimedia/lsearch/search/SearcherCache.java  
    2009-03-07 21:55:06 UTC (rev 48146)
+++ 
branches/lucene-search-2.1/src/org/wikimedia/lsearch/search/SearcherCache.java  
    2009-03-07 22:40:39 UTC (rev 48147)
@@ -212,6 +212,9 @@
        
        /** Remote hosts being deployed, never use their searchers, unless 
necessary! (host->deployment level) */
        protected Hashtable<String,Integer> hostsDeploying = new 
Hashtable<String,Integer>();
+       
+       /** dbrole -> hosts - indexes taken out of rotation */
+       protected Hashtable<String,Set<String>> outOfRotation = new 
Hashtable<String,Set<String>>();
 
        /** deployment has been tried at least once for these */
        protected static Set<String> initialWarmup = 
Collections.synchronizedSet(new HashSet<String>());
@@ -227,6 +230,40 @@
                return localCache.containsKey(iid.toString());          
        }
        
+       /** Take a certain index on a remote or localhost out of rotation */
+       public void takeOutOfRotation(String host, String dbrole){
+               synchronized(outOfRotation){
+                       Set<String> hosts = outOfRotation.get(dbrole);
+                       if(hosts == null)
+                               outOfRotation.put(dbrole, hosts = 
Collections.synchronizedSet(new HashSet<String>()));
+                       hosts.add(host);
+               }
+       }
+       
+       /** Put certain index back into rotation */
+       public void returnToRotation(String host, String dbrole){
+               synchronized(outOfRotation){
+                       Set<String> hosts = outOfRotation.get(dbrole);
+                       if(hosts == null){
+                               log.warn("Tried to put host="+host+", 
dbrole="+dbrole+" back into rotation, but hasn't been out of rotation.");
+                               return; 
+                       }
+                       hosts.remove(host);
+                       if(hosts.isEmpty())
+                               outOfRotation.remove(dbrole);
+               }
+       }
+       
+       /** Check if this index is out of rotation */
+       public boolean isOutOfRotation(String host, IndexId iid){
+               synchronized(outOfRotation){
+                       Set<String> hosts = outOfRotation.get(iid.toString());
+                       if(hosts != null && hosts.contains(host))
+                               return true;
+                       return false;
+               }
+       }
+       
        /** Signalize that host is begining it's index update, and that we 
shouldn't touch it */
        public void hostDeploying(String host){
                synchronized(hostsDeploying){
@@ -253,6 +290,19 @@
                }
        }
        
+       /** Produce nice human-readable list of indexes out of rotation */
+       public ArrayList<String> indexesTakenOutOfRotation(){
+               ArrayList<String> out = new ArrayList<String>();
+               synchronized(hostsDeploying){
+                       for(Entry<String,Set<String>> e : 
outOfRotation.entrySet()){
+                               for(String host : e.getValue()){
+                                       out.add(e.getKey()+" at "+host);
+                               }
+                       }
+               }
+               return out;
+       }
+       
        public boolean thisHostIsDeploying(){
                return hostsDeploying.containsKey("localhost");
        }
@@ -265,7 +315,8 @@
         * @return
         */
        public String getRandomHost(IndexId iid){
-               if(iid.isMySearch() && hasLocalSearcher(iid) && 
!hostsDeploying.containsKey("localhost"))
+               if(iid.isMySearch() && hasLocalSearcher(iid) 
+                               && !hostsDeploying.containsKey("localhost") && 
!isOutOfRotation("localhost",iid))
                        return "localhost";
                if(!initialized.contains(iid.toString()))
                        initializeRemote(iid);
@@ -277,6 +328,11 @@
                        HashSet<String> hosts = new HashSet<String>();
                        hosts.addAll(pools.keySet());
                        hosts.removeAll(hostsDeploying.keySet());
+                       // get hosts for which this index is out of rotation
+                       Set<String> takenOut = 
outOfRotation.get(iid.toString());
+                       if(takenOut != null)
+                               hosts.removeAll(takenOut);
+                       // no hosts left
                        if(hosts.size() == 0)
                                return null;
                        int num = (int)(Math.random()*hosts.size());

Modified: 
branches/lucene-search-2.1/src/org/wikimedia/lsearch/search/UpdateThread.java
===================================================================
--- 
branches/lucene-search-2.1/src/org/wikimedia/lsearch/search/UpdateThread.java   
    2009-03-07 21:55:06 UTC (rev 48146)
+++ 
branches/lucene-search-2.1/src/org/wikimedia/lsearch/search/UpdateThread.java   
    2009-03-07 22:40:39 UTC (rev 48147)
@@ -106,6 +106,8 @@
        protected boolean forceLocalDeployment = false;
        /** If old update/ dirs should be deleted once the new index is 
deployed */
        protected boolean deleteOldUpdates = false;
+       /** when indexes are updated, which indexes to take out of rotation */
+       protected Set<String> forceRedirect = Collections.synchronizedSet(new 
HashSet<String>());
        
        protected static Object threadSerialization = new Object();
        
@@ -236,6 +238,19 @@
                                                log.warn("Error notifying host 
"+host+" of index deployment: "+e.getMessage(),e);
                                        }
                                }
+                       } else if( !forceRedirect.isEmpty() ){
+                               for(String dbrole : forceRedirect){
+                                       cache.takeOutOfRotation("localhost", 
dbrole);
+                                       String myHost = global.getLocalhost();
+                                       for(String host : 
global.getAllSearchHosts()){
+                                               try{
+                                                       if(!host.equals(myHost))
+                                                               
messenger.takeOutOfRotation(host,myHost,dbrole);
+                                               } catch(Exception e){
+                                                       log.warn("Error trying 
to take index "+dbrole+" out of rotation on "+host+" : "+e.getMessage(),e);
+                                               }
+                                       }
+                               }
                        }
                        // if local, use cp -lr instead of rsync
                        if(global.isLocalhost(iid.getIndexHost())){
@@ -302,6 +317,20 @@
                                                log.warn("Error notifying host 
"+host+" of end of deployment: "+e.getMessage(),e);
                                        }
                                }
+                       } else if( !forceRedirect.isEmpty() ){
+                               for(String dbrole : forceRedirect){
+                                       cache.returnToRotation("localhost", 
dbrole);
+                                       String myHost = global.getLocalhost();
+                                       for(String host : 
global.getAllSearchHosts()){
+                                               try{
+                                                       if(!host.equals(myHost))
+                                                               
messenger.returnToRotation(host,myHost,dbrole);
+                                               } catch(Exception e){
+                                                       log.warn("Error trying 
to return index "+dbrole+" in rotation on "+host+" : "+e.getMessage(),e);
+                                               }
+                                       }
+                               }
+
                        }
                }
        }
@@ -418,6 +447,15 @@
                rsyncPath = config.getString("Rsync","path","/usr/bin/rsync");
                rsyncParams = config.getString("Rsync","params","");
                forceLocalDeployment = 
config.getBoolean("Search","forceLocalDeployment");
+               for(String indexpart : 
config.getArray("Search","forceRedirect")){
+                       try{
+                               // make sure these indexes are actually valid 
index names
+                               IndexId iid = IndexId.get(indexpart);
+                               forceRedirect.add(iid.toString());
+                       } catch(RuntimeException e){
+                               log.warn("Ignoring force redirect index 
"+indexpart+" since it doesn't exist.");
+                       }
+               }
                deleteOldUpdates = 
config.getBoolean("Search","deleteOldUpdates");
        }
        



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to