~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
 *
4
 *  Copyright (C) 2009 Sun Microsystems
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
21
#include <drizzled/server_includes.h>
22
#include <drizzled/show.h>
23
#include <drizzled/session.h>
24
#include <drizzled/lock.h>
25
#include <drizzled/statement/flush.h>
26
1130.3.12 by Monty Taylor
using namespace drizzled; to namespace drizzled { in statement/
27
namespace drizzled
28
{
1100.3.48 by Padraig O'Sullivan
Extracted the FLUSH command into its own class and implementation files.
29
30
bool statement::Flush::execute()
31
{
32
  /*
33
   * reloadCache() will tell us if we are allowed to write to the
34
   * binlog or not.
35
   */
36
  if (! reloadCache())
37
  {
38
    /*
39
     * We WANT to write and we CAN write.
40
     * ! we write after unlocking the table.
41
     *
42
     * Presumably, RESET and binlog writing doesn't require synchronization
43
     */
1172 by Brian Aker
Update to delete table to centralize the replication logic.
44
    write_bin_log(session, session->query, session->query_length);
1100.3.48 by Padraig O'Sullivan
Extracted the FLUSH command into its own class and implementation files.
45
    session->my_ok();
46
  }
47
48
  return false;
49
}
50
51
bool statement::Flush::reloadCache()
52
{
53
  bool result= false;
54
  ulong options= session->lex->type;
55
  TableList *tables= (TableList *) session->lex->select_lex.table_list.first;
56
57
  if (options & REFRESH_LOG)
58
  {
1152.1.3 by Brian Aker
refactored drizzled::plugin::StorageEngine::flushLogs()
59
    if (plugin::StorageEngine::flushLogs(NULL))
1100.3.48 by Padraig O'Sullivan
Extracted the FLUSH command into its own class and implementation files.
60
    {
61
      result= true;
62
    }
63
  }
64
  /*
65
    Note that if REFRESH_READ_LOCK bit is set then REFRESH_TABLES is set too
66
    (see sql_yacc.yy)
67
  */
68
  if (options & (REFRESH_TABLES | REFRESH_READ_LOCK))
69
  {
70
    if ((options & REFRESH_READ_LOCK) && session)
71
    {
72
      if (lock_global_read_lock(session))
73
      {
74
        return true; /* Killed */
75
      }
76
      result= session->close_cached_tables(tables, 
77
                                           (options & REFRESH_FAST) ?  false : true, 
78
                                           true);
79
      if (make_global_read_lock_block_commit(session)) /* Killed */
80
      {
81
        /* Don't leave things in a half-locked state */
82
        unlock_global_read_lock(session);
83
        return true;
84
      }
85
    }
86
    else
87
    {
88
      result= session->close_cached_tables(tables, 
89
                                           (options & REFRESH_FAST) ?  false : true, 
90
                                           false);
91
    }
92
  }
93
94
  if (session && (options & REFRESH_STATUS))
95
  {
96
    session->refresh_status();
97
  }
98
99
 return result;
100
}
1130.3.12 by Monty Taylor
using namespace drizzled; to namespace drizzled { in statement/
101
102
}