org.apache.jcs.auxiliary.disk.jdbc.mysql
Class MySQLTableOptimizer

java.lang.Object
  extended by org.apache.jcs.auxiliary.disk.jdbc.mysql.MySQLTableOptimizer

public class MySQLTableOptimizer
extends java.lang.Object

The MySQL Table Optimizer can optimize MySQL tables. It knows how to optimize for MySQL datbases in particular and how to repair the table if it is corrupted in the process.

We will probably be able to abstract out a generic optimizer interface from this class in the future.

Author:
Aaron Smuts

Constructor Summary
MySQLTableOptimizer(MySQLDiskCacheAttributes attributes, TableState tableState, JDBCDiskCachePoolAccess poolAccess)
          This constructs an optimizer with the disk cacn properties.
 
Method Summary
 java.lang.String getTableName()
           
protected  java.lang.String getTableStatus(java.sql.Statement sStatement)
          This calls show table status and returns the result as a String.
 boolean optimizeTable()
          A scheduler will call this method.
protected  boolean repairTable(java.sql.Statement sStatement)
          This is called if the optimizatio is in error.
 void setTableName(java.lang.String tableName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MySQLTableOptimizer

public MySQLTableOptimizer(MySQLDiskCacheAttributes attributes,
                           TableState tableState,
                           JDBCDiskCachePoolAccess poolAccess)
This constructs an optimizer with the disk cacn properties.

Parameters:
attributes -
tableState - We mark the table status as optimizing when this is happening.
poolAccess - access to the database
Method Detail

optimizeTable

public boolean optimizeTable()
A scheduler will call this method. When it is called the table state is marked as optimizing. TODO we need to verify that no deletions are running before we call optimize. We should wait if a deletion is in progress.

This restores when there is an optimization error. The error output looks like this:

           mysql> optimize table JCS_STORE_FLIGHT_OPTION_ITINERARY;
               +---------------------------------------------+----------+----------+---------------------+
               | Table                                       | Op       | Msg_type | Msg_text            |
               +---------------------------------------------+----------+----------+---------------------+
               | jcs_cache.JCS_STORE_FLIGHT_OPTION_ITINERARY | optimize | error    | 2 when fixing table |
               | jcs_cache.JCS_STORE_FLIGHT_OPTION_ITINERARY | optimize | status   | Operation failed    |
               +---------------------------------------------+----------+----------+---------------------+
               2 rows in set (51.78 sec)
 
A successful repair response looks like this:
        mysql> REPAIR TABLE JCS_STORE_FLIGHT_OPTION_ITINERARY;
            +---------------------------------------------+--------+----------+----------------------------------------------+
            | Table                                       | Op     | Msg_type | Msg_text                                     |
            +---------------------------------------------+--------+----------+----------------------------------------------+
            | jcs_cache.JCS_STORE_FLIGHT_OPTION_ITINERARY | repair | error    | 2 when fixing table                          |
            | jcs_cache.JCS_STORE_FLIGHT_OPTION_ITINERARY | repair | warning  | Number of rows changed from 131276 to 260461 |
            | jcs_cache.JCS_STORE_FLIGHT_OPTION_ITINERARY | repair | status   | OK                                           |
            +---------------------------------------------+--------+----------+----------------------------------------------+
            3 rows in set (3 min 5.94 sec)
 
A successful optimization looks like this:
       mysql> optimize table JCS_STORE_DEFAULT;
           +-----------------------------+----------+----------+----------+
           | Table                       | Op       | Msg_type | Msg_text |
           +-----------------------------+----------+----------+----------+
           | jcs_cache.JCS_STORE_DEFAULT | optimize | status   | OK       |
           +-----------------------------+----------+----------+----------+
           1 row in set (1.10 sec)
 

Returns:
true if it worked

getTableStatus

protected java.lang.String getTableStatus(java.sql.Statement sStatement)
                                   throws java.sql.SQLException
This calls show table status and returns the result as a String.

Parameters:
sStatement -
Returns:
String
Throws:
java.sql.SQLException

repairTable

protected boolean repairTable(java.sql.Statement sStatement)
                       throws java.sql.SQLException
This is called if the optimizatio is in error.

It looks for "OK" in response. If it find "OK" as a message in any result set row, it returns true. Otherwise we assume that the repair failed.

Parameters:
sStatement -
Returns:
true if successful
Throws:
java.sql.SQLException

setTableName

public void setTableName(java.lang.String tableName)
Parameters:
tableName - The tableName to set.

getTableName

public java.lang.String getTableName()
Returns:
Returns the tableName.


Copyright © 2002-2010 Apache Software Foundation. All Rights Reserved.