~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/slave/replication_schema.cc

  • Committer: Olaf van der Spek
  • Date: 2011-07-04 19:11:47 UTC
  • mto: This revision was merged to the branch mainline in revision 2367.
  • Revision ID: olafvdspek@gmail.com-20110704191147-s99ojek811zi1fzj
Remove unused Name_resolution_context::error_reporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2011 David Shrewsbury
 
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 <config.h>
 
22
#include <plugin/slave/replication_schema.h>
 
23
#include <drizzled/execute.h>
 
24
#include <drizzled/sql/result_set.h>
 
25
#include <string>
 
26
#include <vector>
 
27
#include <boost/lexical_cast.hpp>
 
28
 
 
29
using namespace std;
 
30
using namespace drizzled;
 
31
using namespace boost;
 
32
 
 
33
namespace slave
 
34
{
 
35
 
 
36
bool ReplicationSchema::create()
 
37
{
 
38
  vector<string> sql;
 
39
 
 
40
  sql.push_back("COMMIT");
 
41
  sql.push_back("CREATE SCHEMA IF NOT EXISTS `sys_replication` REPLICATE=FALSE");
 
42
 
 
43
  if (not executeSQL(sql))
 
44
    return false;
 
45
 
 
46
  /*
 
47
   * Create our IO thread state information table if we need to.
 
48
   */
 
49
 
 
50
  sql.clear();
 
51
  sql.push_back("COMMIT");
 
52
  sql.push_back("CREATE TABLE IF NOT EXISTS `sys_replication`.`io_state` ("
 
53
                " `status` VARCHAR(20) NOT NULL,"
 
54
                " `error_msg` VARCHAR(250))"
 
55
                " COMMENT = 'VERSION 1.0'");
 
56
 
 
57
  if (not executeSQL(sql))
 
58
    return false;
 
59
 
 
60
  sql.clear();
 
61
  sql.push_back("SELECT COUNT(*) FROM `sys_replication`.`io_state`");
 
62
 
 
63
  {
 
64
    sql::ResultSet result_set(1);
 
65
    Execute execute(*(_session.get()), true);
 
66
    execute.run(sql[0], result_set);
 
67
    result_set.next();
 
68
    string count= result_set.getString(0);
 
69
 
 
70
    /* Must always be at least one row in the table */
 
71
    if (count == "0")
 
72
    {
 
73
      sql.clear();
 
74
      sql.push_back("INSERT INTO `sys_replication`.`io_state` (`status`)"
 
75
                    " VALUES ('STOPPED')");
 
76
      if (not executeSQL(sql))
 
77
        return false;
 
78
    }
 
79
  }
 
80
 
 
81
  /*
 
82
   * Create our applier thread state information table if we need to.
 
83
   */
 
84
 
 
85
  /*
 
86
   * Table: applier_state
 
87
   * Version 1.0: Initial definition
 
88
   * Version 1.1: Added originating_server_uuid and originating_commit_id
 
89
   */
 
90
 
 
91
  sql.clear();
 
92
  sql.push_back("COMMIT");
 
93
  sql.push_back("CREATE TABLE IF NOT EXISTS `sys_replication`.`applier_state`"
 
94
                " (`last_applied_commit_id` BIGINT NOT NULL PRIMARY KEY,"
 
95
                " `originating_server_uuid` VARCHAR(36) NOT NULL,"
 
96
                " `originating_commit_id` BIGINT NOT NULL,"
 
97
                " `status` VARCHAR(20) NOT NULL,"
 
98
                " `error_msg` VARCHAR(250))"
 
99
                " COMMENT = 'VERSION 1.1'");
 
100
 
 
101
  if (not executeSQL(sql))
 
102
    return false;
 
103
 
 
104
  sql.clear();
 
105
  sql.push_back("SELECT COUNT(*) FROM `sys_replication`.`applier_state`");
 
106
 
 
107
  {
 
108
    sql::ResultSet result_set(1);
 
109
    Execute execute(*(_session.get()), true);
 
110
    execute.run(sql[0], result_set);
 
111
    result_set.next();
 
112
    string count= result_set.getString(0);
 
113
 
 
114
    /* Must always be at least one row in the table */
 
115
    if (count == "0")
 
116
    {
 
117
      sql.clear();
 
118
      sql.push_back("INSERT INTO `sys_replication`.`applier_state`"
 
119
                    " (`last_applied_commit_id`, `originating_server_uuid`,"
 
120
                    "  `originating_commit_id`, `status`)"
 
121
                    " VALUES (0, '', 0, 'STOPPED')");
 
122
      if (not executeSQL(sql))
 
123
        return false;
 
124
    }
 
125
  }
 
126
 
 
127
  /*
 
128
   * Create our message queue table if we need to.
 
129
   * Version 1.0: Initial definition
 
130
   * Version 1.1: Added originating_server_uuid and originating_commit_id
 
131
   */
 
132
 
 
133
  sql.clear();
 
134
  sql.push_back("COMMIT");
 
135
  sql.push_back("CREATE TABLE IF NOT EXISTS `sys_replication`.`queue`"
 
136
                " (`trx_id` BIGINT NOT NULL, `seg_id` INT NOT NULL,"
 
137
                " `commit_order` BIGINT,"
 
138
                " `originating_server_uuid` VARCHAR(36) NOT NULL,"
 
139
                " `originating_commit_id` BIGINT NOT NULL,"
 
140
                " `msg` BLOB,"
 
141
                " PRIMARY KEY(`trx_id`, `seg_id`))"
 
142
                " COMMENT = 'VERSION 1.1'");
 
143
  if (not executeSQL(sql))
 
144
    return false;
 
145
 
 
146
  return true;
 
147
}
 
148
 
 
149
bool ReplicationSchema::setInitialMaxCommitId(uint64_t value)
 
150
{
 
151
  vector<string> sql;
 
152
 
 
153
  sql.push_back("UPDATE `sys_replication`.`applier_state`"
 
154
                " SET `last_applied_commit_id` = "
 
155
                + lexical_cast<string>(value));
 
156
 
 
157
  return executeSQL(sql);
 
158
}
 
159
 
 
160
} /* namespace slave */