Author: kwright
Date: Mon Dec 10 23:37:19 2012
New Revision: 1419872

URL: http://svn.apache.org/viewvc?rev=1419872&view=rev
Log:
Infrastructure which does something very special regarding index hints for MySQL

Modified:
    
manifoldcf/branches/CONNECTORS-584/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceMySQL.java
    
manifoldcf/branches/CONNECTORS-584/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
    
manifoldcf/branches/CONNECTORS-584/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java
    
manifoldcf/branches/CONNECTORS-584/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobManager.java
    
manifoldcf/branches/CONNECTORS-584/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobQueue.java

Modified: 
manifoldcf/branches/CONNECTORS-584/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceMySQL.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-584/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceMySQL.java?rev=1419872&r1=1419871&r2=1419872&view=diff
==============================================================================
--- 
manifoldcf/branches/CONNECTORS-584/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceMySQL.java
 (original)
+++ 
manifoldcf/branches/CONNECTORS-584/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceMySQL.java
 Mon Dec 10 23:37:19 2012
@@ -918,6 +918,18 @@ public class DBInterfaceMySQL extends Da
     }
   }
 
+  /** Construct index hint clause.
+  * On most databases this returns an empty string, but on MySQL this returns
+  * a USE INDEX hint.  It requires the name of an index.
+  *@param indexName is the name of an index.
+  *@return the query chunk that should go between the table names and the WHERE
+  * clause.
+  */
+  public String constructIndexHintClause(String indexName)
+  {
+    return "FORCE INDEX ("+indexName+") ";
+  }
+
   /** Construct a cast to a double value.
   * On most databases this cast needs to be explicit, but on some it is 
implicit (and cannot be in fact
   * specified).

Modified: 
manifoldcf/branches/CONNECTORS-584/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-584/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java?rev=1419872&r1=1419871&r2=1419872&view=diff
==============================================================================
--- 
manifoldcf/branches/CONNECTORS-584/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
 (original)
+++ 
manifoldcf/branches/CONNECTORS-584/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
 Mon Dec 10 23:37:19 2012
@@ -483,6 +483,18 @@ public abstract class Database
     }
   }
 
+  /** Construct index hint clause.
+  * On most databases this returns an empty string, but on MySQL this returns
+  * a USE INDEX hint.  It requires the name of an index.
+  *@param indexName is the name of an index.
+  *@return the query chunk that should go between the table names and the WHERE
+  * clause.
+  */
+  public String constructIndexHintClause(String indexName)
+  {
+    return "";
+  }
+
   /** Construct an offset/limit clause.
   * This method constructs an offset/limit clause in the proper manner for the 
database in question.
   *@param offset is the starting offset number.

Modified: 
manifoldcf/branches/CONNECTORS-584/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-584/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java?rev=1419872&r1=1419871&r2=1419872&view=diff
==============================================================================
--- 
manifoldcf/branches/CONNECTORS-584/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java
 (original)
+++ 
manifoldcf/branches/CONNECTORS-584/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java
 Mon Dec 10 23:37:19 2012
@@ -254,6 +254,15 @@ public interface IDBInterface
     int maxResults, ResultSpecification resultSpec, ILimitChecker returnLimit)
     throws ManifoldCFException;
 
+  /** Construct index hint clause.
+  * On most databases this returns an empty string, but on MySQL this returns
+  * a USE INDEX hint.  It requires the name of an index.
+  *@param indexName is the name of an index.
+  *@return the query chunk that should go between the table names and the WHERE
+  * clause.
+  */
+  public String constructIndexHintClause(String indexName);
+  
   /** Construct a cast to a double value.
   * On most databases this cast needs to be explicit, but on some it is 
implicit (and cannot be in fact
   * specified).

Modified: 
manifoldcf/branches/CONNECTORS-584/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobManager.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-584/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobManager.java?rev=1419872&r1=1419871&r2=1419872&view=diff
==============================================================================
--- 
manifoldcf/branches/CONNECTORS-584/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobManager.java
 (original)
+++ 
manifoldcf/branches/CONNECTORS-584/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobManager.java
 Mon Dec 10 23:37:19 2012
@@ -2104,7 +2104,7 @@ public class JobManager implements IJobM
     
sb.append(jobQueue.docPriorityField).append(",").append(jobQueue.jobIDField).append(",")
       .append(jobQueue.docHashField).append(",").append(jobQueue.docIDField)
       .append(" FROM ").append(jobQueue.getTableName())
-      .append(" t0 WHERE ");
+      .append(" t0 
").append(jobQueue.getGetNextDocumentsIndex()).append("WHERE ");
       
     sb.append(database.buildConjunctionClause(list,new ClauseDescription[]{
       //new UnitaryClause(jobQueue.docPriorityField,">=",new Long(0L)),
@@ -2161,7 +2161,8 @@ public class JobManager implements IJobM
       .append(jobQueue.statusField).append(",t0.")
       .append(jobQueue.failTimeField).append(",t0.")
       .append(jobQueue.failCountField).append(",t0.")
-      .append(jobQueue.prioritySetField).append(" FROM 
").append(jobQueue.getTableName()).append(" t0 WHERE ");
+      .append(jobQueue.prioritySetField).append(" FROM 
").append(jobQueue.getTableName())
+      .append(" t0 
").append(jobQueue.getGetNextDocumentsIndex()).append("WHERE ");
     
     sb.append(database.buildConjunctionClause(list,new ClauseDescription[]{
       //new UnitaryClause("t0."+jobQueue.docPriorityField,">=",new Long(0L)),

Modified: 
manifoldcf/branches/CONNECTORS-584/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobQueue.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-584/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobQueue.java?rev=1419872&r1=1419871&r2=1419872&view=diff
==============================================================================
--- 
manifoldcf/branches/CONNECTORS-584/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobQueue.java
 (original)
+++ 
manifoldcf/branches/CONNECTORS-584/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobQueue.java
 Mon Dec 10 23:37:19 2012
@@ -154,6 +154,9 @@ public class JobQueue extends org.apache
   /** Thread context */
   protected IThreadContext threadContext;
   
+  /** Cached getNextDocuments order-by index name */
+  protected String getNextDocumentsIndex = null;
+  
   /** Constructor.
   *@param database is the database handle.
   */
@@ -266,6 +269,33 @@ public class JobQueue extends org.apache
     }
   }
 
+  /** Get the 'getNextDocuments' index name.
+  */
+  public String getGetNextDocumentsIndex()
+    throws ManifoldCFException
+  {
+    if (getNextDocumentsIndex == null)
+    {
+      // Figure out what index it is
+      IndexDescription docpriorityIndex = new IndexDescription(false,new 
String[]{docPriorityField,statusField,checkActionField,checkTimeField});
+      Map indexes = getTableIndexes(null,null);
+      Iterator iter = indexes.keySet().iterator();
+      while (iter.hasNext())
+      {
+        String indexName = (String)iter.next();
+        IndexDescription id = (IndexDescription)indexes.get(indexName);
+        if (id.equals(docpriorityIndex))
+        {
+          getNextDocumentsIndex = indexName;
+          break;
+        }
+      }
+      if (getNextDocumentsIndex == null)
+        throw new ManifoldCFException("Can't find getnextdocuments index");
+    }
+    return getNextDocumentsIndex;
+  }
+  
   /** Analyze job tables due to major event */
   public void unconditionallyAnalyzeTables()
     throws ManifoldCFException


Reply via email to