~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/flush.cc

Re-org'd the replication stuff into slots.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include "config.h"
 
21
#include <drizzled/server_includes.h>
22
22
#include <drizzled/show.h>
23
23
#include <drizzled/session.h>
24
24
#include <drizzled/lock.h>
25
25
#include <drizzled/statement/flush.h>
26
 
#include "drizzled/sql_table.h"
27
 
#include "drizzled/plugin/logging.h"
28
26
 
29
 
namespace drizzled
30
 
{
 
27
using namespace drizzled;
31
28
 
32
29
bool statement::Flush::execute()
33
30
{
35
32
   * reloadCache() will tell us if we are allowed to write to the
36
33
   * binlog or not.
37
34
   */
38
 
  if (not reloadCache())
 
35
  if (! reloadCache())
39
36
  {
40
37
    /*
41
38
     * We WANT to write and we CAN write.
43
40
     *
44
41
     * Presumably, RESET and binlog writing doesn't require synchronization
45
42
     */
46
 
    write_bin_log(session, *session->getQueryString());
 
43
    write_bin_log(session, false, session->query, session->query_length);
47
44
    session->my_ok();
48
45
  }
49
46
 
53
50
bool statement::Flush::reloadCache()
54
51
{
55
52
  bool result= false;
 
53
  ulong options= session->lex->type;
56
54
  TableList *tables= (TableList *) session->lex->select_lex.table_list.first;
57
55
 
58
 
  if (flush_log)
 
56
  if (options & REFRESH_LOG)
59
57
  {
60
 
    if (plugin::StorageEngine::flushLogs(NULL))
 
58
    if (ha_flush_logs(NULL))
61
59
    {
62
60
      result= true;
63
61
    }
66
64
    Note that if REFRESH_READ_LOCK bit is set then REFRESH_TABLES is set too
67
65
    (see sql_yacc.yy)
68
66
  */
69
 
  if (flush_tables || flush_tables_with_read_lock)
 
67
  if (options & (REFRESH_TABLES | REFRESH_READ_LOCK))
70
68
  {
71
 
    if (session && flush_tables_with_read_lock)
 
69
    if ((options & REFRESH_READ_LOCK) && session)
72
70
    {
73
 
      if (session->lockGlobalReadLock())
 
71
      if (lock_global_read_lock(session))
74
72
      {
75
73
        return true; /* Killed */
76
74
      }
77
 
      result= session->close_cached_tables(tables, true, true);
78
 
 
79
 
      if (session->makeGlobalReadLockBlockCommit()) /* Killed */
 
75
      result= session->close_cached_tables(tables, 
 
76
                                           (options & REFRESH_FAST) ?  false : true, 
 
77
                                           true);
 
78
      if (make_global_read_lock_block_commit(session)) /* Killed */
80
79
      {
81
80
        /* Don't leave things in a half-locked state */
82
 
        session->unlockGlobalReadLock();
 
81
        unlock_global_read_lock(session);
83
82
        return true;
84
83
      }
85
84
    }
86
85
    else
87
86
    {
88
 
      result= session->close_cached_tables(tables, true, false);
 
87
      result= session->close_cached_tables(tables, 
 
88
                                           (options & REFRESH_FAST) ?  false : true, 
 
89
                                           false);
89
90
    }
90
91
  }
91
92
 
92
 
  if (session && flush_status)
93
 
  {
94
 
    session->refresh_status();
95
 
  }
96
 
 
97
 
  if (session && flush_global_status)
98
 
  {
99
 
    memset(&current_global_counters, 0, sizeof(current_global_counters));
100
 
    plugin::Logging::resetStats(session);
101
 
    session->refresh_status();
102
 
  }
103
 
 
104
 
  return result;
105
 
}
106
 
 
 
93
  if (session && (options & REFRESH_STATUS))
 
94
  {
 
95
    session->refresh_status();
 
96
  }
 
97
 
 
98
 return result;
107
99
}