Drizzled Public API Documentation

flush.cc
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2009 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #include <config.h>
00022 
00023 #include <drizzled/show.h>
00024 #include <drizzled/session.h>
00025 #include <drizzled/lock.h>
00026 #include <drizzled/statement/flush.h>
00027 #include <drizzled/sql_table.h>
00028 #include <drizzled/plugin/logging.h>
00029 #include <drizzled/plugin/storage_engine.h>
00030 
00031 namespace drizzled
00032 {
00033 
00034 bool statement::Flush::execute()
00035 {
00036   /*
00037    * reloadCache() will tell us if we are allowed to write to the
00038    * binlog or not.
00039    */
00040   if (not reloadCache())
00041   {
00042     session().my_ok();
00043   }
00044 
00045   return false;
00046 }
00047 
00048 bool statement::Flush::reloadCache()
00049 {
00050   bool result= false;
00051   TableList *tables= (TableList *) lex().select_lex.table_list.first;
00052 
00053   if (flush_log)
00054   {
00055     if (plugin::StorageEngine::flushLogs(NULL))
00056     {
00057       result= true;
00058     }
00059   }
00060   /*
00061     Note that if REFRESH_READ_LOCK bit is set then REFRESH_TABLES is set too
00062     (see sql_yacc.yy)
00063   */
00064   if (flush_tables || flush_tables_with_read_lock)
00065   {
00066     if (&session() && flush_tables_with_read_lock)
00067     {
00068       if (session().lockGlobalReadLock())
00069       {
00070         return true; /* Killed */
00071       }
00072       result= session().close_cached_tables(tables, true, true);
00073 
00074       if (session().makeGlobalReadLockBlockCommit()) /* Killed */
00075       {
00076         /* Don't leave things in a half-locked state */
00077         session().unlockGlobalReadLock();
00078         return true;
00079       }
00080     }
00081     else
00082     {
00083       result= session().close_cached_tables(tables, true, false);
00084     }
00085   }
00086 
00087   if (&session() && flush_status)
00088   {
00089     session().refresh_status();
00090   }
00091 
00092   if (&session() && flush_global_status)
00093   {
00094     memset(&current_global_counters, 0, sizeof(current_global_counters));
00095     plugin::Logging::resetStats(&session());
00096     session().refresh_status();
00097   }
00098 
00099   return result;
00100 }
00101 
00102 }