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>
27
#include <boost/lexical_cast.hpp>
30
using namespace drizzled;
31
using namespace boost;
36
bool ReplicationSchema::create()
40
sql.push_back("COMMIT");
41
sql.push_back("CREATE SCHEMA IF NOT EXISTS `sys_replication` REPLICATE=FALSE");
43
if (not executeSQL(sql))
47
* Create our IO thread state information table if we need to.
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'");
57
if (not executeSQL(sql))
61
sql.push_back("SELECT COUNT(*) FROM `sys_replication`.`io_state`");
64
sql::ResultSet result_set(1);
65
Execute execute(*(_session.get()), true);
66
execute.run(sql[0], result_set);
68
string count= result_set.getString(0);
70
/* Must always be at least one row in the table */
74
sql.push_back("INSERT INTO `sys_replication`.`io_state` (`status`)"
75
" VALUES ('STOPPED')");
76
if (not executeSQL(sql))
82
* Create our applier thread state information table if we need to.
86
* Table: applier_state
87
* Version 1.0: Initial definition
88
* Version 1.1: Added originating_server_uuid and originating_commit_id
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'");
101
if (not executeSQL(sql))
105
sql.push_back("SELECT COUNT(*) FROM `sys_replication`.`applier_state`");
108
sql::ResultSet result_set(1);
109
Execute execute(*(_session.get()), true);
110
execute.run(sql[0], result_set);
112
string count= result_set.getString(0);
114
/* Must always be at least one row in the table */
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))
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
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,"
141
" PRIMARY KEY(`trx_id`, `seg_id`))"
142
" COMMENT = 'VERSION 1.1'");
143
if (not executeSQL(sql))
149
bool ReplicationSchema::setInitialMaxCommitId(uint64_t value)
153
sql.push_back("UPDATE `sys_replication`.`applier_state`"
154
" SET `last_applied_commit_id` = "
155
+ lexical_cast<string>(value));
157
return executeSQL(sql);
160
} /* namespace slave */