Merge lp:~oleksiyk/gearmand/mysql into lp:gearmand/1.0

Proposed by Oleksiy Krivoshey
Status: Merged
Merged at revision: 500
Proposed branch: lp:~oleksiyk/gearmand/mysql
Merge into: lp:gearmand/1.0
Diff against target: 725 lines (+661/-0)
8 files modified
configure.ac (+4/-0)
libgearman-server/plugins.cc (+5/-0)
libgearman-server/plugins/queue.h (+2/-0)
libgearman-server/plugins/queue/include.am (+1/-0)
libgearman-server/plugins/queue/mysql/include.am (+19/-0)
libgearman-server/plugins/queue/mysql/queue.cc (+435/-0)
libgearman-server/plugins/queue/mysql/queue.h (+48/-0)
m4/ax_lib_mysql.m4 (+147/-0)
To merge this branch: bzr merge lp:~oleksiyk/gearmand/mysql
Reviewer Review Type Date Requested Status
Brian Aker Pending
Review via email: mp+92946@code.launchpad.net

Description of the change

Support for MySQL based persistent queue using libmysqlclient. Uses prepared statements.

Configuration:

$ gearmand -q MySQL --mysql-host <HOSTNAME> --mysql-db <DATABASE> --mysql-user <USER> --mysql-password <PASSWORD> --mysql-table <TABLE>

$ gearmand --help should show defaults for options above

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'configure.ac'
--- configure.ac 2012-01-27 06:44:03 +0000
+++ configure.ac 2012-02-14 10:32:50 +0000
@@ -110,6 +110,9 @@
110SOCKET_SEND_FLAGS110SOCKET_SEND_FLAGS
111AX_HAVE_LIBHIREDIS111AX_HAVE_LIBHIREDIS
112112
113AX_LIB_MYSQL([5.0])
114AM_CONDITIONAL(HAVE_MYSQL, test "x${HAVE_MYSQL}" = "x1")
115
113# Checks for programs.116# Checks for programs.
114AC_PROG_AWK117AC_PROG_AWK
115AC_PROG_INSTALL118AC_PROG_INSTALL
@@ -244,5 +247,6 @@
244echo " * Building with libmemcached $ac_enable_libmemcached"247echo " * Building with libmemcached $ac_enable_libmemcached"
245echo " * Building with libpq $ac_cv_libpq"248echo " * Building with libpq $ac_cv_libpq"
246echo " * Building with tokyocabinet $ac_enable_libtokyocabinet"249echo " * Building with tokyocabinet $ac_enable_libtokyocabinet"
250echo " * Building with libmysql $found_mysql"
247echo ""251echo ""
248echo "---"252echo "---"
249253
=== modified file 'libgearman-server/plugins.cc'
--- libgearman-server/plugins.cc 2012-02-10 02:49:36 +0000
+++ libgearman-server/plugins.cc 2012-02-14 10:32:50 +0000
@@ -78,6 +78,11 @@
78 queue::initialize_tokyocabinet();78 queue::initialize_tokyocabinet();
79 }79 }
8080
81 if (HAVE_MYSQL)
82 {
83 queue::initialize_mysql();
84 }
85
81 gearmand::queue::load_options(all);86 gearmand::queue::load_options(all);
82}87}
8388
8489
=== modified file 'libgearman-server/plugins/queue.h'
--- libgearman-server/plugins/queue.h 2011-11-29 05:21:54 +0000
+++ libgearman-server/plugins/queue.h 2012-02-14 10:32:50 +0000
@@ -48,3 +48,5 @@
48#include <libgearman-server/plugins/queue/tokyocabinet/queue.h>48#include <libgearman-server/plugins/queue/tokyocabinet/queue.h>
4949
50#include <libgearman-server/plugins/queue/redis/queue.h>50#include <libgearman-server/plugins/queue/redis/queue.h>
51
52#include <libgearman-server/plugins/queue/mysql/queue.h>
5153
=== modified file 'libgearman-server/plugins/queue/include.am'
--- libgearman-server/plugins/queue/include.am 2011-11-29 05:21:54 +0000
+++ libgearman-server/plugins/queue/include.am 2012-02-14 10:32:50 +0000
@@ -18,3 +18,4 @@
18include libgearman-server/plugins/queue/redis/include.am18include libgearman-server/plugins/queue/redis/include.am
19include libgearman-server/plugins/queue/sqlite/include.am19include libgearman-server/plugins/queue/sqlite/include.am
20include libgearman-server/plugins/queue/tokyocabinet/include.am20include libgearman-server/plugins/queue/tokyocabinet/include.am
21include libgearman-server/plugins/queue/mysql/include.am
2122
=== added directory 'libgearman-server/plugins/queue/mysql'
=== added file 'libgearman-server/plugins/queue/mysql/include.am'
--- libgearman-server/plugins/queue/mysql/include.am 1970-01-01 00:00:00 +0000
+++ libgearman-server/plugins/queue/mysql/include.am 2012-02-14 10:32:50 +0000
@@ -0,0 +1,19 @@
1# Gearman
2# Copyright (C) 2011 Oleksiy Krivoshey
3# All rights reserved.
4#
5# Use and distribution licensed under the BSD license. See
6# the COPYING file in the parent directory for full text.
7#
8# All paths should be given relative to the root
9#
10
11noinst_HEADERS+= \
12 libgearman-server/plugins/queue/mysql/queue.h
13
14libgearman_server_libgearman_server_la_SOURCES+= \
15 libgearman-server/plugins/queue/mysql/queue.cc
16
17libgearman_server_libgearman_server_la_LIBADD+= $(MYSQL_LDFLAGS)
18
19
020
=== added file 'libgearman-server/plugins/queue/mysql/queue.cc'
--- libgearman-server/plugins/queue/mysql/queue.cc 1970-01-01 00:00:00 +0000
+++ libgearman-server/plugins/queue/mysql/queue.cc 2012-02-14 10:32:50 +0000
@@ -0,0 +1,435 @@
1/* Gearman server and library
2 * Copyright (C) 2011 Oleksiy Krivoshey
3 * All rights reserved.
4 *
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
7 */
8
9#include <libgearman-server/common.h>
10#include <libgearman-server/byte.h>
11
12#include <libgearman-server/plugins/queue/mysql/queue.h>
13#include <libgearman-server/plugins/queue/base.h>
14
15#include <mysql/mysql.h>
16#include <mysql/errmsg.h>
17
18/**
19 * Default values.
20 */
21#define GEARMAN_QUEUE_MYSQL_DEFAULT_TABLE "gearman_queue"
22
23namespace gearmand {
24 namespace plugins {
25 namespace queue {
26 class MySQL;
27 }
28 }
29}
30
31static gearmand_error_t _initialize(gearman_server_st *server, gearmand::plugins::queue::MySQL *queue);
32
33namespace gearmand {
34 namespace plugins {
35 namespace queue {
36
37 class MySQL : public gearmand::plugins::Queue {
38 public:
39 MySQL();
40 ~MySQL();
41
42 gearmand_error_t initialize();
43 gearmand_error_t prepareAddStatement();
44 gearmand_error_t prepareDoneStatement();
45
46 MYSQL *con;
47 MYSQL_STMT *add_stmt;
48 MYSQL_STMT *done_stmt;
49 std::string mysql_host;
50 std::string mysql_user;
51 std::string mysql_password;
52 std::string mysql_db;
53 std::string mysql_table;
54 private:
55 };
56
57 MySQL::MySQL() :
58 Queue("MySQL"),
59 con(NULL),
60 add_stmt(NULL) {
61 command_line_options().add_options()
62 ("mysql-host", boost::program_options::value(&mysql_host)->default_value("localhost"), "MySQL host.")
63 ("mysql-user", boost::program_options::value(&mysql_user)->default_value(""), "MySQL user.")
64 ("mysql-password", boost::program_options::value(&mysql_password)->default_value(""), "MySQL user password.")
65 ("mysql-db", boost::program_options::value(&mysql_db)->default_value(""), "MySQL database.")
66 ("mysql-table", boost::program_options::value(&mysql_table)->default_value(GEARMAN_QUEUE_MYSQL_DEFAULT_TABLE), "MySQL table name.");
67 }
68
69 MySQL::~MySQL() {
70 if (add_stmt){
71 mysql_stmt_close(add_stmt);
72 }
73 if (con){
74 mysql_close(con);
75 }
76 }
77
78 gearmand_error_t MySQL::initialize() {
79 return _initialize(&Gearmand()->server, this);
80 }
81
82 gearmand_error_t MySQL::prepareAddStatement() {
83 char query_buffer[1024];
84
85 if((this->add_stmt = mysql_stmt_init(this->con)) == NULL){
86 gearmand_log_error(GEARMAN_DEFAULT_LOG_PARAM, "mysql_stmt_init failed: %s", mysql_error(this->con));
87 return GEARMAN_QUEUE_ERROR;
88 }
89
90 snprintf(query_buffer, sizeof(query_buffer),
91 "INSERT INTO %s "
92 "(unique_key, function_name, priority, data, when_to_run) "
93 "VALUES(?, ?, ?, ?, ?)", this->mysql_table.c_str());
94
95 if (mysql_stmt_prepare(this->add_stmt, query_buffer, strlen(query_buffer))){
96 gearmand_log_error(GEARMAN_DEFAULT_LOG_PARAM, "mysql_stmt_prepare failed: %s", mysql_error(this->con));
97 return GEARMAN_QUEUE_ERROR;
98 }
99
100 return GEARMAN_SUCCESS;
101 }
102
103 gearmand_error_t MySQL::prepareDoneStatement() {
104 char query_buffer[1024];
105
106 if((this->done_stmt = mysql_stmt_init(this->con)) == NULL){
107 gearmand_log_error(GEARMAN_DEFAULT_LOG_PARAM, "mysql_stmt_init failed: %s", mysql_error(this->con));
108 return GEARMAN_QUEUE_ERROR;
109 }
110
111 snprintf(query_buffer, sizeof(query_buffer),
112 "DELETE FROM %s "
113 "WHERE unique_key=? "
114 "AND function_name=?", this->mysql_table.c_str());
115
116 if (mysql_stmt_prepare(this->done_stmt, query_buffer, strlen(query_buffer))){
117 gearmand_log_error(GEARMAN_DEFAULT_LOG_PARAM, "mysql_stmt_prepare failed: %s", mysql_error(this->con));
118 return GEARMAN_QUEUE_ERROR;
119 }
120
121 return GEARMAN_SUCCESS;
122 }
123
124 void initialize_mysql() {
125 static MySQL local_instance;
126 }
127
128 } // namespace queue
129 } // namespace plugin
130} // namespace gearmand
131
132/* Queue callback functions. */
133static gearmand_error_t _mysql_queue_add(gearman_server_st *server, void *context,
134 const char *unique, size_t unique_size,
135 const char *function_name,
136 size_t function_name_size,
137 const void *data, size_t data_size,
138 gearmand_job_priority_t priority,
139 int64_t when);
140
141static gearmand_error_t _mysql_queue_flush(gearman_server_st *server, void *context);
142
143static gearmand_error_t _mysql_queue_done(gearman_server_st *server, void *context,
144 const char *unique,
145 size_t unique_size,
146 const char *function_name,
147 size_t function_name_size);
148
149static gearmand_error_t _mysql_queue_replay(gearman_server_st *server, void *context,
150 gearman_queue_add_fn *add_fn,
151 void *add_context);
152
153
154gearmand_error_t _initialize(gearman_server_st *server,
155 gearmand::plugins::queue::MySQL *queue) {
156
157 MYSQL_RES * result;
158 char query_buffer[1024];
159 my_bool my_true = true;
160
161 gearmand_log_info(GEARMAN_DEFAULT_LOG_PARAM,"Initializing MySQL module");
162
163 gearman_server_set_queue(server, queue, _mysql_queue_add, _mysql_queue_flush, _mysql_queue_done, _mysql_queue_replay);
164
165 queue->con = mysql_init(queue->con);
166
167 mysql_options(queue->con, MYSQL_READ_DEFAULT_GROUP, "gearmand");
168
169 if (!mysql_real_connect(queue->con,
170 queue->mysql_host.c_str(),
171 queue->mysql_user.c_str(),
172 queue->mysql_password.c_str(),
173 queue->mysql_db.c_str(), 0, NULL, 0)) {
174 gearmand_log_error(GEARMAN_DEFAULT_LOG_PARAM, "Failed to connect to database: %s", mysql_error(queue->con));
175
176 return GEARMAN_QUEUE_ERROR;
177 }
178
179 mysql_options(queue->con, MYSQL_OPT_RECONNECT, &my_true);
180
181 if (!(result = mysql_list_tables(queue->con, queue->mysql_table.c_str()))){
182 gearmand_log_error(GEARMAN_DEFAULT_LOG_PARAM, "mysql_list_tables failed: %s", mysql_error(queue->con));
183 return GEARMAN_QUEUE_ERROR;
184 }
185
186 if (mysql_num_rows(result) == 0){
187 snprintf(query_buffer, sizeof(query_buffer),
188 "CREATE TABLE %s"
189 "("
190 "unique_key VARCHAR(%d),"
191 "function_name VARCHAR(255),"
192 "priority INT,"
193 "data LONGBLOB,"
194 "when_to_run INT,"
195 "unique key (unique_key, function_name)"
196 ")",
197 queue->mysql_table.c_str(), GEARMAN_UNIQUE_SIZE);
198
199 gearmand_log_info(GEARMAN_DEFAULT_LOG_PARAM,"MySQL module: creating table %s", queue->mysql_table.c_str());
200
201 if(mysql_real_query(queue->con, query_buffer, strlen(query_buffer))){
202 gearmand_log_error(GEARMAN_DEFAULT_LOG_PARAM, "MySQL module: create table failed: %s", mysql_error(queue->con));
203 return GEARMAN_QUEUE_ERROR;
204 }
205 }
206
207 mysql_free_result(result);
208
209 if(queue->prepareAddStatement() == GEARMAN_QUEUE_ERROR)
210 return GEARMAN_QUEUE_ERROR;
211
212 if(queue->prepareDoneStatement() == GEARMAN_QUEUE_ERROR)
213 return GEARMAN_QUEUE_ERROR;
214
215 return GEARMAN_SUCCESS;
216}
217
218/*
219 * Static definitions
220 */
221
222
223static gearmand_error_t _mysql_queue_add(gearman_server_st *server, void *context,
224 const char *unique, size_t unique_size,
225 const char *function_name,
226 size_t function_name_size,
227 const void *data, size_t data_size,
228 gearmand_job_priority_t priority,
229 int64_t when) {
230
231 MYSQL_BIND bind[5];
232
233 (void) server;
234
235 gearmand::plugins::queue::MySQL *queue = (gearmand::plugins::queue::MySQL *)context;
236
237 gearmand_log_debug(GEARMAN_DEFAULT_LOG_PARAM,"MySQL queue add: %.*s %.*s", (uint32_t) unique_size, (char *) unique,
238 (uint32_t) function_name_size, (char *) function_name);
239
240 bind[0].buffer_type= MYSQL_TYPE_STRING;
241 bind[0].buffer= (char *)unique;
242 bind[0].buffer_length= unique_size;
243 bind[0].is_null= 0;
244 bind[0].length= (unsigned long*)&unique_size;
245
246 bind[1].buffer_type= MYSQL_TYPE_STRING;
247 bind[1].buffer= (char *)function_name;
248 bind[1].buffer_length= function_name_size;
249 bind[1].is_null= 0;
250 bind[1].length= (unsigned long*)&function_name_size;
251
252 bind[2].buffer_type= MYSQL_TYPE_LONG;
253 bind[2].buffer= (char *)&priority;
254 bind[2].is_null= 0;
255 bind[2].length= 0;
256
257 bind[3].buffer_type= MYSQL_TYPE_LONG_BLOB;
258 bind[3].buffer= (char *)data;
259 bind[3].buffer_length= data_size;
260 bind[3].is_null= 0;
261 bind[3].length= (unsigned long*)&data_size;
262
263 bind[4].buffer_type= MYSQL_TYPE_LONG;
264 bind[4].buffer= (char *)&when;
265 bind[4].is_null= 0;
266 bind[4].length= 0;
267
268 while(1){
269 if (mysql_stmt_bind_param(queue->add_stmt, bind)){
270 if ( mysql_stmt_errno(queue->add_stmt) == CR_NO_PREPARE_STMT ){
271 if(queue->prepareAddStatement() == GEARMAN_QUEUE_ERROR){
272 return GEARMAN_QUEUE_ERROR;
273 }
274 continue;
275 } else {
276 gearmand_log_error(GEARMAN_DEFAULT_LOG_PARAM, "mysql_stmt_bind_param failed: %s", mysql_error(queue->con));
277 return GEARMAN_QUEUE_ERROR;
278 }
279 }
280
281 if (mysql_stmt_execute(queue->add_stmt)){
282 if ( mysql_stmt_errno(queue->add_stmt) == CR_SERVER_LOST ){
283 mysql_stmt_close(queue->add_stmt);
284 if(queue->prepareAddStatement() != GEARMAN_QUEUE_ERROR){
285 continue;
286 }
287 }
288 gearmand_log_error(GEARMAN_DEFAULT_LOG_PARAM, "mysql_stmt_execute failed: %s", mysql_error(queue->con));
289 return GEARMAN_QUEUE_ERROR;
290 }
291
292 break;
293 }
294
295 return GEARMAN_SUCCESS;
296}
297
298static gearmand_error_t _mysql_queue_flush(gearman_server_st *server,
299 void *context __attribute__((unused))) {
300
301 (void) server;
302 (void) context;
303
304 gearmand_log_debug(GEARMAN_DEFAULT_LOG_PARAM,"MySQL queue flush");
305
306 return GEARMAN_SUCCESS;
307}
308
309static gearmand_error_t _mysql_queue_done(gearman_server_st *server, void *context,
310 const char *unique,
311 size_t unique_size,
312 const char *function_name,
313 size_t function_name_size) {
314
315 MYSQL_BIND bind[2];
316
317 (void) server;
318
319 gearmand_log_debug(GEARMAN_DEFAULT_LOG_PARAM,"MySQL queue done: %.*s %.*s", (uint32_t) unique_size, (char *) unique,
320 (uint32_t) function_name_size, (char *) function_name);
321
322 gearmand::plugins::queue::MySQL *queue = (gearmand::plugins::queue::MySQL *)context;
323
324 bind[0].buffer_type= MYSQL_TYPE_STRING;
325 bind[0].buffer= (char *)unique;
326 bind[0].buffer_length= unique_size;
327 bind[0].is_null= 0;
328 bind[0].length= (unsigned long*)&unique_size;
329
330 bind[1].buffer_type= MYSQL_TYPE_STRING;
331 bind[1].buffer= (char *)function_name;
332 bind[1].buffer_length= function_name_size;
333 bind[1].is_null= 0;
334 bind[1].length= (unsigned long*)&function_name_size;
335
336 while(1){
337 if (mysql_stmt_bind_param(queue->done_stmt, bind)){
338 if ( mysql_stmt_errno(queue->done_stmt) == CR_NO_PREPARE_STMT ){
339 if(queue->prepareDoneStatement() == GEARMAN_QUEUE_ERROR){
340 return GEARMAN_QUEUE_ERROR;
341 }
342 continue;
343 } else {
344 gearmand_log_error(GEARMAN_DEFAULT_LOG_PARAM, "mysql_stmt_bind_param failed: %s", mysql_error(queue->con));
345 return GEARMAN_QUEUE_ERROR;
346 }
347 }
348
349 if (mysql_stmt_execute(queue->done_stmt)){
350 if ( mysql_stmt_errno(queue->done_stmt) == CR_SERVER_LOST ){
351 mysql_stmt_close(queue->done_stmt);
352 if(queue->prepareDoneStatement() != GEARMAN_QUEUE_ERROR){
353 continue;
354 }
355 }
356 gearmand_log_error(GEARMAN_DEFAULT_LOG_PARAM, "mysql_stmt_execute failed: %s", mysql_error(queue->con));
357 return GEARMAN_QUEUE_ERROR;
358 }
359
360 break;
361 }
362
363 return GEARMAN_SUCCESS;
364}
365
366static gearmand_error_t _mysql_queue_replay(gearman_server_st *server, void *context,
367 gearman_queue_add_fn *add_fn,
368 void *add_context) {
369
370 MYSQL_RES * result;
371 MYSQL_ROW row;
372 char query_buffer[1024];
373
374 (void) server;
375
376 gearmand_log_info(GEARMAN_DEFAULT_LOG_PARAM,"MySQL queue replay");
377
378 gearmand::plugins::queue::MySQL *queue = (gearmand::plugins::queue::MySQL *)context;
379
380 snprintf(query_buffer, sizeof(query_buffer),
381 "SELECT unique_key, function_name, data, priority, when_to_run FROM %s",
382 queue->mysql_table.c_str());
383
384 if(mysql_real_query(queue->con, query_buffer, strlen(query_buffer))){
385 gearmand_log_error(GEARMAN_DEFAULT_LOG_PARAM, "mysql_real_query failed: %s", mysql_error(queue->con));
386 return GEARMAN_QUEUE_ERROR;
387 }
388
389 if(!(result = mysql_store_result(queue->con))){
390 gearmand_log_error(GEARMAN_DEFAULT_LOG_PARAM, "mysql_store_result failed: %s", mysql_error(queue->con));
391 return GEARMAN_QUEUE_ERROR;
392 }
393
394 if(mysql_num_fields(result) < 5){
395 gearmand_log_error(GEARMAN_DEFAULT_LOG_PARAM, "MySQL queue: insufficient row fields in queue table");
396 return GEARMAN_QUEUE_ERROR;
397 }
398
399 gearmand_error_t ret = GEARMAN_SUCCESS;
400
401 while ((row = mysql_fetch_row(result))) {
402 unsigned long *lengths;
403 gearmand_job_priority_t priority = (gearmand_job_priority_t)0;
404 int when = 0;
405
406 lengths = mysql_fetch_lengths(result);
407
408 /* need to make a copy here ... gearman_server_job_free will free it later */
409 size_t data_size= lengths[2];
410 char * data= (char *)malloc(data_size);
411 if (data == NULL){
412 gearmand_perror("malloc failed");
413 return GEARMAN_MEMORY_ALLOCATION_FAILURE;
414 }
415 memcpy(data, row[2], data_size);
416
417 if(lengths[3]) priority = (gearmand_job_priority_t) atoi(row[3]);
418 if(lengths[4]) when = atoi(row[4]);
419
420 ret = (*add_fn)(server, add_context,
421 row[0], (size_t) lengths[0],
422 row[1], (size_t) lengths[1],
423 data, data_size,
424 priority,
425 when);
426
427 if (ret != GEARMAN_SUCCESS) {
428 break;
429 }
430 }
431
432 mysql_free_result(result);
433
434 return ret;
435}
0436
=== added file 'libgearman-server/plugins/queue/mysql/queue.h'
--- libgearman-server/plugins/queue/mysql/queue.h 1970-01-01 00:00:00 +0000
+++ libgearman-server/plugins/queue/mysql/queue.h 2012-02-14 10:32:50 +0000
@@ -0,0 +1,48 @@
1/*
2 * Gearmand client and server library.
3 *
4 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * * The names of its contributors may not be used to endorse or
20 * promote products derived from this software without specific prior
21 * written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 */
36
37#pragma once
38
39
40namespace gearmand {
41namespace plugins {
42namespace queue {
43
44void initialize_mysql();
45
46} // namespace queue
47} // namespace plugin
48} // namespace gearmand
049
=== added file 'm4/ax_lib_mysql.m4'
--- m4/ax_lib_mysql.m4 1970-01-01 00:00:00 +0000
+++ m4/ax_lib_mysql.m4 2012-02-14 10:32:50 +0000
@@ -0,0 +1,147 @@
1# ===========================================================================
2# http://www.gnu.org/software/autoconf-archive/ax_lib_mysql.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7# AX_LIB_MYSQL([MINIMUM-VERSION])
8#
9# DESCRIPTION
10#
11# This macro provides tests of availability of MySQL client library of
12# particular version or newer.
13#
14# AX_LIB_MYSQL macro takes only one argument which is optional. If there
15# is no required version passed, then macro does not run version test.
16#
17# The --with-mysql option takes one of three possible values:
18#
19# no - do not check for MySQL client library
20#
21# yes - do check for MySQL library in standard locations (mysql_config
22# should be in the PATH)
23#
24# path - complete path to mysql_config utility, use this option if
25# mysql_config can't be found in the PATH
26#
27# This macro calls:
28#
29# AC_SUBST(MYSQL_CFLAGS)
30# AC_SUBST(MYSQL_LDFLAGS)
31# AC_SUBST(MYSQL_VERSION)
32#
33# And sets:
34#
35# HAVE_MYSQL
36#
37# LICENSE
38#
39# Copyright (c) 2008 Mateusz Loskot <mateusz@loskot.net>
40#
41# Copying and distribution of this file, with or without modification, are
42# permitted in any medium without royalty provided the copyright notice
43# and this notice are preserved. This file is offered as-is, without any
44# warranty.
45
46#serial 12
47
48AC_DEFUN([AX_LIB_MYSQL],
49[
50 AC_ARG_WITH([mysql],
51 AS_HELP_STRING([--with-mysql=@<:@ARG@:>@],
52 [use MySQL client library @<:@default=yes@:>@, optionally specify path to mysql_config]
53 ),
54 [
55 if test "$withval" = "no"; then
56 want_mysql="no"
57 elif test "$withval" = "yes"; then
58 want_mysql="yes"
59 else
60 want_mysql="yes"
61 MYSQL_CONFIG="$withval"
62 fi
63 ],
64 [want_mysql="yes"]
65 )
66 AC_ARG_VAR([MYSQL_CONFIG], [Full path to mysql_config program])
67
68 MYSQL_CFLAGS=""
69 MYSQL_LDFLAGS=""
70 MYSQL_VERSION=""
71
72 dnl
73 dnl Check MySQL libraries
74 dnl
75
76 if test "$want_mysql" = "yes"; then
77
78 if test -z "$MYSQL_CONFIG" ; then
79 AC_PATH_PROGS([MYSQL_CONFIG], [mysql_config mysql_config5], [no])
80 fi
81
82 if test "$MYSQL_CONFIG" != "no"; then
83 MYSQL_CFLAGS="`$MYSQL_CONFIG --cflags`"
84 MYSQL_LDFLAGS="`$MYSQL_CONFIG --libs`"
85
86 MYSQL_VERSION=`$MYSQL_CONFIG --version`
87
88 found_mysql="yes"
89 else
90 found_mysql="no"
91 fi
92 fi
93
94 dnl
95 dnl Check if required version of MySQL is available
96 dnl
97
98
99 mysql_version_req=ifelse([$1], [], [], [$1])
100
101 if test "$found_mysql" = "yes" -a -n "$mysql_version_req"; then
102
103 AC_MSG_CHECKING([if MySQL version is >= $mysql_version_req])
104
105 dnl Decompose required version string of MySQL
106 dnl and calculate its number representation
107 mysql_version_req_major=`expr $mysql_version_req : '\([[0-9]]*\)'`
108 mysql_version_req_minor=`expr $mysql_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
109 mysql_version_req_micro=`expr $mysql_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
110 if test "x$mysql_version_req_micro" = "x"; then
111 mysql_version_req_micro="0"
112 fi
113
114 mysql_version_req_number=`expr $mysql_version_req_major \* 1000000 \
115 \+ $mysql_version_req_minor \* 1000 \
116 \+ $mysql_version_req_micro`
117
118 dnl Decompose version string of installed MySQL
119 dnl and calculate its number representation
120 mysql_version_major=`expr $MYSQL_VERSION : '\([[0-9]]*\)'`
121 mysql_version_minor=`expr $MYSQL_VERSION : '[[0-9]]*\.\([[0-9]]*\)'`
122 mysql_version_micro=`expr $MYSQL_VERSION : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
123 if test "x$mysql_version_micro" = "x"; then
124 mysql_version_micro="0"
125 fi
126
127 mysql_version_number=`expr $mysql_version_major \* 1000000 \
128 \+ $mysql_version_minor \* 1000 \
129 \+ $mysql_version_micro`
130
131 mysql_version_check=`expr $mysql_version_number \>\= $mysql_version_req_number`
132 if test "$mysql_version_check" = "1"; then
133 AC_MSG_RESULT([yes])
134 else
135 AC_MSG_RESULT([no])
136 fi
137 fi
138
139 if test "$found_mysql" = "yes" ; then
140 AC_DEFINE([HAVE_MYSQL], [1],
141 [Define to 1 if MySQL libraries are available])
142 fi
143
144 AC_SUBST([MYSQL_VERSION])
145 AC_SUBST([MYSQL_CFLAGS])
146 AC_SUBST([MYSQL_LDFLAGS])
147])

Subscribers

People subscribed via source and target branches