~drizzle-trunk/drizzle/development

1100.3.48 by Padraig O'Sullivan
Extracted the FLUSH command into its own class and implementation files.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2009 Sun Microsystems, Inc.
1100.3.48 by Padraig O'Sullivan
Extracted the FLUSH command into its own class and implementation files.
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
20
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
21
#include <config.h>
2148.7.12 by Brian Aker
Merge in header fixes.
22
1100.3.48 by Padraig O'Sullivan
Extracted the FLUSH command into its own class and implementation files.
23
#include <drizzled/show.h>
24
#include <drizzled/session.h>
25
#include <drizzled/lock.h>
26
#include <drizzled/statement/flush.h>
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
27
#include <drizzled/sql_table.h>
28
#include <drizzled/plugin/logging.h>
29
#include <drizzled/plugin/storage_engine.h>
2241.3.1 by Olaf van der Spek
Refactor Session::status_var
30
#include <drizzled/statistics_variables.h>
1100.3.48 by Padraig O'Sullivan
Extracted the FLUSH command into its own class and implementation files.
31
2241.3.1 by Olaf van der Spek
Refactor Session::status_var
32
namespace drizzled {
1100.3.48 by Padraig O'Sullivan
Extracted the FLUSH command into its own class and implementation files.
33
34
bool statement::Flush::execute()
35
{
36
  /*
37
   * reloadCache() will tell us if we are allowed to write to the
38
   * binlog or not.
39
   */
1921.4.13 by Brian Aker
Fix issue where session info might not be correct.
40
  if (not reloadCache())
1100.3.48 by Padraig O'Sullivan
Extracted the FLUSH command into its own class and implementation files.
41
  {
2227.4.1 by Olaf van der Spek
Statement::session()
42
    session().my_ok();
1100.3.48 by Padraig O'Sullivan
Extracted the FLUSH command into its own class and implementation files.
43
  }
44
45
  return false;
46
}
47
48
bool statement::Flush::reloadCache()
49
{
50
  bool result= false;
2224.2.8 by Olaf van der Spek
Statement::lex()
51
  TableList *tables= (TableList *) lex().select_lex.table_list.first;
1100.3.48 by Padraig O'Sullivan
Extracted the FLUSH command into its own class and implementation files.
52
1315.2.17 by Stewart Smith
move FLUSH statement to use boolean values in statement::Flush instead of overloading Lex->type with REFRESH_STATUS and others.
53
  if (flush_log)
1100.3.48 by Padraig O'Sullivan
Extracted the FLUSH command into its own class and implementation files.
54
  {
1152.1.3 by Brian Aker
refactored drizzled::plugin::StorageEngine::flushLogs()
55
    if (plugin::StorageEngine::flushLogs(NULL))
1100.3.48 by Padraig O'Sullivan
Extracted the FLUSH command into its own class and implementation files.
56
    {
57
      result= true;
58
    }
59
  }
60
  /*
61
    Note that if REFRESH_READ_LOCK bit is set then REFRESH_TABLES is set too
62
    (see sql_yacc.yy)
63
  */
1315.2.18 by Stewart Smith
fix flush tables
64
  if (flush_tables || flush_tables_with_read_lock)
1100.3.48 by Padraig O'Sullivan
Extracted the FLUSH command into its own class and implementation files.
65
  {
2227.4.2 by Olaf van der Spek
Statement::session()
66
    if (&session() && flush_tables_with_read_lock)
1100.3.48 by Padraig O'Sullivan
Extracted the FLUSH command into its own class and implementation files.
67
    {
2227.4.1 by Olaf van der Spek
Statement::session()
68
      if (session().lockGlobalReadLock())
1100.3.48 by Padraig O'Sullivan
Extracted the FLUSH command into its own class and implementation files.
69
      {
70
        return true; /* Killed */
71
      }
2227.4.1 by Olaf van der Spek
Statement::session()
72
      result= session().close_cached_tables(tables, true, true);
1315.2.17 by Stewart Smith
move FLUSH statement to use boolean values in statement::Flush instead of overloading Lex->type with REFRESH_STATUS and others.
73
2227.4.1 by Olaf van der Spek
Statement::session()
74
      if (session().makeGlobalReadLockBlockCommit()) /* Killed */
1100.3.48 by Padraig O'Sullivan
Extracted the FLUSH command into its own class and implementation files.
75
      {
76
        /* Don't leave things in a half-locked state */
2227.4.1 by Olaf van der Spek
Statement::session()
77
        session().unlockGlobalReadLock();
1100.3.48 by Padraig O'Sullivan
Extracted the FLUSH command into its own class and implementation files.
78
        return true;
79
      }
80
    }
81
    else
82
    {
2227.4.1 by Olaf van der Spek
Statement::session()
83
      result= session().close_cached_tables(tables, true, false);
1100.3.48 by Padraig O'Sullivan
Extracted the FLUSH command into its own class and implementation files.
84
    }
85
  }
86
2227.4.2 by Olaf van der Spek
Statement::session()
87
  if (&session() && flush_status)
1100.3.48 by Padraig O'Sullivan
Extracted the FLUSH command into its own class and implementation files.
88
  {
2227.4.1 by Olaf van der Spek
Statement::session()
89
    session().refresh_status();
1100.3.48 by Padraig O'Sullivan
Extracted the FLUSH command into its own class and implementation files.
90
  }
91
2227.4.2 by Olaf van der Spek
Statement::session()
92
  if (&session() && flush_global_status)
1900.3.1 by Andrew Hutchings
Add FLUSH GLOBAL STATUS; command
93
  {
94
    memset(&current_global_counters, 0, sizeof(current_global_counters));
2227.4.2 by Olaf van der Spek
Statement::session()
95
    plugin::Logging::resetStats(&session());
2227.4.1 by Olaf van der Spek
Statement::session()
96
    session().refresh_status();
1900.3.1 by Andrew Hutchings
Add FLUSH GLOBAL STATUS; command
97
  }
98
99
  return result;
1100.3.48 by Padraig O'Sullivan
Extracted the FLUSH command into its own class and implementation files.
100
}
1130.3.12 by Monty Taylor
using namespace drizzled; to namespace drizzled { in statement/
101
102
}