1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2011 David Shrewsbury
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.
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.
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
22
#include <plugin/slave/replication_schema.h>
23
#include <drizzled/execute.h>
24
#include <drizzled/sql/result_set.h>
29
using namespace drizzled;
34
bool ReplicationSchema::create()
38
sql.push_back("COMMIT");
39
sql.push_back("CREATE SCHEMA IF NOT EXISTS `sys_replication` REPLICATE=FALSE");
41
if (not executeSQL(sql))
45
* Create our IO thread state information table if we need to.
49
sql.push_back("COMMIT");
50
sql.push_back("CREATE TABLE IF NOT EXISTS `sys_replication`.`io_state` ("
51
" `status` VARCHAR(20) NOT NULL,"
52
" `error_msg` VARCHAR(250))"
53
" COMMENT = 'VERSION 1.0'");
55
if (not executeSQL(sql))
59
sql.push_back("SELECT COUNT(*) FROM `sys_replication`.`io_state`");
62
sql::ResultSet result_set(1);
63
Execute execute(*(_session.get()), true);
64
execute.run(sql[0], result_set);
66
string count= result_set.getString(0);
68
/* Must always be at least one row in the table */
72
sql.push_back("INSERT INTO `sys_replication`.`io_state` (`status`)"
73
" VALUES ('STOPPED')");
74
if (not executeSQL(sql))
80
* Create our applier thread state information table if we need to.
84
sql.push_back("COMMIT");
85
sql.push_back("CREATE TABLE IF NOT EXISTS `sys_replication`.`applier_state`"
86
" (`last_applied_commit_id` BIGINT NOT NULL PRIMARY KEY,"
87
" `status` VARCHAR(20) NOT NULL,"
88
" `error_msg` VARCHAR(250))"
89
" COMMENT = 'VERSION 1.0'");
91
if (not executeSQL(sql))
95
sql.push_back("SELECT COUNT(*) FROM `sys_replication`.`applier_state`");
98
sql::ResultSet result_set(1);
99
Execute execute(*(_session.get()), true);
100
execute.run(sql[0], result_set);
102
string count= result_set.getString(0);
104
/* Must always be at least one row in the table */
108
sql.push_back("INSERT INTO `sys_replication`.`applier_state`"
109
" (`last_applied_commit_id`, `status`)"
110
" VALUES (0, 'STOPPED')");
111
if (not executeSQL(sql))
117
* Create our message queue table if we need to.
121
sql.push_back("COMMIT");
122
sql.push_back("CREATE TABLE IF NOT EXISTS `sys_replication`.`queue`"
123
" (`trx_id` BIGINT NOT NULL, `seg_id` INT NOT NULL,"
124
" `commit_order` BIGINT, `msg` BLOB,"
125
" PRIMARY KEY(`trx_id`, `seg_id`))"
126
" COMMENT = 'VERSION 1.0'");
127
if (not executeSQL(sql))
133
} /* namespace slave */