Merge lp:~tgates/gearmand/nuodb-queue-adapter into lp:gearmand
- nuodb-queue-adapter
- Merge into 1.2
Proposed by
Tom Gates
Status: | Needs review |
---|---|
Proposed branch: | lp:~tgates/gearmand/nuodb-queue-adapter |
Merge into: | lp:gearmand |
Diff against target: |
833 lines (+768/-0) 8 files modified
configure.ac (+6/-0) libgearman-server/plugins.cc (+7/-0) libgearman-server/plugins/queue.h (+2/-0) libgearman-server/plugins/queue/include.am (+1/-0) libgearman-server/plugins/queue/nuodb/include.am (+23/-0) libgearman-server/plugins/queue/nuodb/queue.cc (+550/-0) libgearman-server/plugins/queue/nuodb/queue.h (+49/-0) m4/ax_lib_nuodb.m4 (+130/-0) |
To merge this branch: | bzr merge lp:~tgates/gearmand/nuodb-queue-adapter |
Related bugs: | |
Related blueprints: |
Add support for NuoDB persistent queues.
(Undefined)
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tangent Trunk | Pending | ||
Review via email: mp+219047@code.launchpad.net |
Commit message
Description of the change
Add support for using NuoDB as a persistent queue for Gearman.
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
1 | === modified file 'configure.ac' | |||
2 | --- configure.ac 2014-02-16 02:15:49 +0000 | |||
3 | +++ configure.ac 2014-05-09 18:35:29 +0000 | |||
4 | @@ -104,6 +104,11 @@ | |||
5 | 104 | [AC_DEFINE([HAVE_LIBSQLITE3],[0],[Have the SQLITE3 library])]) | 104 | [AC_DEFINE([HAVE_LIBSQLITE3],[0],[Have the SQLITE3 library])]) |
6 | 105 | AM_CONDITIONAL([HAVE_LIBSQLITE3],[test "x${WANT_SQLITE3}" = "xyes"]) | 105 | AM_CONDITIONAL([HAVE_LIBSQLITE3],[test "x${WANT_SQLITE3}" = "xyes"]) |
7 | 106 | 106 | ||
8 | 107 | AX_LIB_NUODB | ||
9 | 108 | AS_IF([test "x${WANT_NUODB}" = "xyes"], | ||
10 | 109 | [AC_DEFINE([HAVE_NUODB],[1],[Have the NuoDB library])], | ||
11 | 110 | [AC_DEFINE([HAVE_NUODB],[0],[Have the NuoDB library])]) | ||
12 | 111 | AM_CONDITIONAL([HAVE_NUODB],[test "x${WANT_NUODB}" = "xyes"]) | ||
13 | 107 | 112 | ||
14 | 108 | PANDORA_ENABLE_DTRACE | 113 | PANDORA_ENABLE_DTRACE |
15 | 109 | AX_HAVE_LIBPQ | 114 | AX_HAVE_LIBPQ |
16 | @@ -345,6 +350,7 @@ | |||
17 | 345 | echo " * Debug enabled: $ax_enable_debug" | 350 | echo " * Debug enabled: $ax_enable_debug" |
18 | 346 | echo " * Warnings as failure: $ac_cv_warnings_as_errors" | 351 | echo " * Warnings as failure: $ac_cv_warnings_as_errors" |
19 | 347 | echo " * Building with libsqlite3 $WANT_SQLITE3" | 352 | echo " * Building with libsqlite3 $WANT_SQLITE3" |
20 | 353 | echo " * Building with nuodb $WANT_NUODB" | ||
21 | 348 | echo " * Building with libdrizzle $ac_enable_libdrizzle" | 354 | echo " * Building with libdrizzle $ac_enable_libdrizzle" |
22 | 349 | echo " * Building with libmemcached $ax_enable_libmemcached" | 355 | echo " * Building with libmemcached $ax_enable_libmemcached" |
23 | 350 | echo " * Building with libpq $ac_cv_libpq" | 356 | echo " * Building with libpq $ac_cv_libpq" |
24 | 351 | 357 | ||
25 | === modified file 'libgearman-server/plugins.cc' | |||
26 | --- libgearman-server/plugins.cc 2013-10-20 11:00:25 +0000 | |||
27 | +++ libgearman-server/plugins.cc 2014-05-09 18:35:29 +0000 | |||
28 | @@ -71,6 +71,13 @@ | |||
29 | 71 | } | 71 | } |
30 | 72 | #endif | 72 | #endif |
31 | 73 | 73 | ||
32 | 74 | #if defined(HAVE_NUODB) && HAVE_NUODB | ||
33 | 75 | if (HAVE_NUODB) | ||
34 | 76 | { | ||
35 | 77 | queue::initialize_nuodb(); | ||
36 | 78 | } | ||
37 | 79 | #endif | ||
38 | 80 | |||
39 | 74 | #if defined(HAVE_LIBPQ) && HAVE_LIBPQ | 81 | #if defined(HAVE_LIBPQ) && HAVE_LIBPQ |
40 | 75 | if (HAVE_LIBPQ) | 82 | if (HAVE_LIBPQ) |
41 | 76 | { | 83 | { |
42 | 77 | 84 | ||
43 | === modified file 'libgearman-server/plugins/queue.h' | |||
44 | --- libgearman-server/plugins/queue.h 2012-11-23 09:17:06 +0000 | |||
45 | +++ libgearman-server/plugins/queue.h 2014-05-09 18:35:29 +0000 | |||
46 | @@ -52,3 +52,5 @@ | |||
47 | 52 | #include <libgearman-server/plugins/queue/redis/queue.h> | 52 | #include <libgearman-server/plugins/queue/redis/queue.h> |
48 | 53 | 53 | ||
49 | 54 | #include <libgearman-server/plugins/queue/mysql/queue.h> | 54 | #include <libgearman-server/plugins/queue/mysql/queue.h> |
50 | 55 | |||
51 | 56 | #include <libgearman-server/plugins/queue/nuodb/queue.h> | ||
52 | 55 | 57 | ||
53 | === modified file 'libgearman-server/plugins/queue/include.am' | |||
54 | --- libgearman-server/plugins/queue/include.am 2012-11-23 09:17:06 +0000 | |||
55 | +++ libgearman-server/plugins/queue/include.am 2014-05-09 18:35:29 +0000 | |||
56 | @@ -21,3 +21,4 @@ | |||
57 | 21 | include libgearman-server/plugins/queue/sqlite/include.am | 21 | include libgearman-server/plugins/queue/sqlite/include.am |
58 | 22 | include libgearman-server/plugins/queue/tokyocabinet/include.am | 22 | include libgearman-server/plugins/queue/tokyocabinet/include.am |
59 | 23 | include libgearman-server/plugins/queue/mysql/include.am | 23 | include libgearman-server/plugins/queue/mysql/include.am |
60 | 24 | include libgearman-server/plugins/queue/nuodb/include.am | ||
61 | 24 | 25 | ||
62 | === added directory 'libgearman-server/plugins/queue/nuodb' | |||
63 | === added file 'libgearman-server/plugins/queue/nuodb/include.am' | |||
64 | --- libgearman-server/plugins/queue/nuodb/include.am 1970-01-01 00:00:00 +0000 | |||
65 | +++ libgearman-server/plugins/queue/nuodb/include.am 2014-05-09 18:35:29 +0000 | |||
66 | @@ -0,0 +1,23 @@ | |||
67 | 1 | # vim:ft=automake | ||
68 | 2 | # Gearman | ||
69 | 3 | # Copyright (C) 2011 Data Differential, http://datadifferential.com/ | ||
70 | 4 | # All rights reserved. | ||
71 | 5 | # | ||
72 | 6 | # Use and distribution licensed under the BSD license. See | ||
73 | 7 | # the COPYING file in the parent directory for full text. | ||
74 | 8 | # | ||
75 | 9 | # All paths should be given relative to the root | ||
76 | 10 | # | ||
77 | 11 | |||
78 | 12 | noinst_HEADERS+= libgearman-server/plugins/queue/nuodb/queue.h | ||
79 | 13 | |||
80 | 14 | if HAVE_NUODB | ||
81 | 15 | |||
82 | 16 | libgearman_server_libgearman_server_la_SOURCES+= libgearman-server/plugins/queue/nuodb/queue.cc | ||
83 | 17 | libgearman_server_libgearman_server_la_LIBADD+= $(NUODB_LDFLAGS) | ||
84 | 18 | libgearman_server_libgearman_server_la_CXXFLAGS+= $(NUODB_CFLAGS) | ||
85 | 19 | |||
86 | 20 | gearmand_gearmand_LDADD+= $(NUODB_LDFLAGS) | ||
87 | 21 | |||
88 | 22 | endif | ||
89 | 23 | |||
90 | 0 | 24 | ||
91 | === added file 'libgearman-server/plugins/queue/nuodb/queue.cc' | |||
92 | --- libgearman-server/plugins/queue/nuodb/queue.cc 1970-01-01 00:00:00 +0000 | |||
93 | +++ libgearman-server/plugins/queue/nuodb/queue.cc 2014-05-09 18:35:29 +0000 | |||
94 | @@ -0,0 +1,550 @@ | |||
95 | 1 | /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: | ||
96 | 2 | * | ||
97 | 3 | * Gearmand client and server library. | ||
98 | 4 | * | ||
99 | 5 | * Copyright (C) 2011 Data Differential, http://datadifferential.com/ | ||
100 | 6 | * Copyright (C) 2008 Brian Aker, Eric Day | ||
101 | 7 | * All rights reserved. | ||
102 | 8 | * | ||
103 | 9 | * Redistribution and use in source and binary forms, with or without | ||
104 | 10 | * modification, are permitted provided that the following conditions are | ||
105 | 11 | * met: | ||
106 | 12 | * | ||
107 | 13 | * * Redistributions of source code must retain the above copyright | ||
108 | 14 | * notice, this list of conditions and the following disclaimer. | ||
109 | 15 | * | ||
110 | 16 | * * Redistributions in binary form must reproduce the above | ||
111 | 17 | * copyright notice, this list of conditions and the following disclaimer | ||
112 | 18 | * in the documentation and/or other materials provided with the | ||
113 | 19 | * distribution. | ||
114 | 20 | * | ||
115 | 21 | * * The names of its contributors may not be used to endorse or | ||
116 | 22 | * promote products derived from this software without specific prior | ||
117 | 23 | * written permission. | ||
118 | 24 | * | ||
119 | 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
120 | 26 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
121 | 27 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
122 | 28 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
123 | 29 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
124 | 30 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
125 | 31 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
126 | 32 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
127 | 33 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
128 | 34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
129 | 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
130 | 36 | * | ||
131 | 37 | */ | ||
132 | 38 | |||
133 | 39 | /** | ||
134 | 40 | * @file | ||
135 | 41 | * @brief NuoDB Queue Storage Definitions | ||
136 | 42 | */ | ||
137 | 43 | |||
138 | 44 | #include <gear_config.h> | ||
139 | 45 | #include <libgearman-server/common.h> | ||
140 | 46 | #include <libgearman-server/byte.h> | ||
141 | 47 | #include <libgearman-server/plugins/queue/nuodb/queue.h> | ||
142 | 48 | #include <libgearman-server/plugins/queue/base.h> | ||
143 | 49 | |||
144 | 50 | #pragma GCC diagnostic push | ||
145 | 51 | #pragma GCC diagnostic ignored "-Wundef" | ||
146 | 52 | #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" | ||
147 | 53 | #pragma GCC diagnostic ignored "-Woverloaded-virtual" | ||
148 | 54 | #pragma GCC diagnostic ignored "-Wreorder" | ||
149 | 55 | #pragma GCC diagnostic ignored "-Wunused-parameter" | ||
150 | 56 | #pragma GCC diagnostic ignored "-Wold-style-cast" | ||
151 | 57 | |||
152 | 58 | #include <NuoDB.h> | ||
153 | 59 | #include <cerrno> | ||
154 | 60 | |||
155 | 61 | /** | ||
156 | 62 | * @addtogroup plugins::queue::NuoDB Static NuoDB Queue Storage Definitions | ||
157 | 63 | * @ingroup gearman_queue_nuodb | ||
158 | 64 | * @{ | ||
159 | 65 | */ | ||
160 | 66 | |||
161 | 67 | /** | ||
162 | 68 | * Default values. | ||
163 | 69 | */ | ||
164 | 70 | #define GEARMAND_QUEUE_NUODB_DEFAULT_SCHEMA "gearman" | ||
165 | 71 | #define GEARMAND_QUEUE_NUODB_DEFAULT_TABLE "queue" | ||
166 | 72 | |||
167 | 73 | namespace gearmand { namespace plugins { namespace queue { class Nuodb; }}} | ||
168 | 74 | |||
169 | 75 | static gearmand_error_t _initialize(gearman_server_st& server, gearmand::plugins::queue::Nuodb *queue); | ||
170 | 76 | |||
171 | 77 | namespace gearmand { | ||
172 | 78 | namespace plugins { | ||
173 | 79 | namespace queue { | ||
174 | 80 | |||
175 | 81 | class Nuodb : public gearmand::plugins::Queue { | ||
176 | 82 | public: | ||
177 | 83 | Nuodb(); | ||
178 | 84 | ~Nuodb(); | ||
179 | 85 | |||
180 | 86 | gearmand_error_t initialize(); | ||
181 | 87 | |||
182 | 88 | const std::string &insert() { | ||
183 | 89 | return _insert_query; | ||
184 | 90 | } | ||
185 | 91 | |||
186 | 92 | const std::string &select() { | ||
187 | 93 | return _select_query; | ||
188 | 94 | } | ||
189 | 95 | |||
190 | 96 | const std::string &create() { | ||
191 | 97 | return _create_query; | ||
192 | 98 | } | ||
193 | 99 | |||
194 | 100 | NuoDB::Connection *con; | ||
195 | 101 | std::string nuodb_connect_string; | ||
196 | 102 | std::string nuodb_user; | ||
197 | 103 | std::string nuodb_pw; | ||
198 | 104 | std::string schema; | ||
199 | 105 | std::string table; | ||
200 | 106 | NuoDB::PreparedStatement *_insert_stmt; | ||
201 | 107 | NuoDB::PreparedStatement *_delete_stmt; | ||
202 | 108 | NuoDB::PreparedStatement *_select_stmt; | ||
203 | 109 | |||
204 | 110 | public: | ||
205 | 111 | std::string _insert_query; | ||
206 | 112 | std::string _select_query; | ||
207 | 113 | std::string _create_query; | ||
208 | 114 | |||
209 | 115 | NuoDB::PreparedStatement *insert_stmt() { | ||
210 | 116 | return _insert_stmt; | ||
211 | 117 | } | ||
212 | 118 | |||
213 | 119 | NuoDB::PreparedStatement *delete_stmt() { | ||
214 | 120 | return _delete_stmt; | ||
215 | 121 | } | ||
216 | 122 | |||
217 | 123 | NuoDB::PreparedStatement *select_stmt() { | ||
218 | 124 | return _select_stmt; | ||
219 | 125 | } | ||
220 | 126 | |||
221 | 127 | }; | ||
222 | 128 | |||
223 | 129 | Nuodb::Nuodb() : | ||
224 | 130 | Queue("NuoDB"), | ||
225 | 131 | con(NULL), | ||
226 | 132 | nuodb_connect_string(""), | ||
227 | 133 | nuodb_user(""), | ||
228 | 134 | nuodb_pw(""), | ||
229 | 135 | table(""), | ||
230 | 136 | schema("") | ||
231 | 137 | { | ||
232 | 138 | command_line_options().add_options() | ||
233 | 139 | ("nuodb-conninfo", boost::program_options::value(&nuodb_connect_string)->default_value(""), "NuoDB connection information string.") | ||
234 | 140 | ("nuodb-user", boost::program_options::value(&nuodb_user)->default_value(""), "NuoDB connection username.") | ||
235 | 141 | ("nuodb-password", boost::program_options::value(&nuodb_pw)->default_value(""), "NuoDB connection password.") | ||
236 | 142 | ("nuodb-table", boost::program_options::value(&table)->default_value(GEARMAND_QUEUE_NUODB_DEFAULT_TABLE), "Table to use.") | ||
237 | 143 | ("nuodb-schema", boost::program_options::value(&schema)->default_value(GEARMAND_QUEUE_NUODB_DEFAULT_SCHEMA), "Schema to use."); | ||
238 | 144 | } | ||
239 | 145 | |||
240 | 146 | Nuodb::~Nuodb () | ||
241 | 147 | { | ||
242 | 148 | if (con) { | ||
243 | 149 | con->close(); | ||
244 | 150 | } | ||
245 | 151 | con = NULL; | ||
246 | 152 | } | ||
247 | 153 | |||
248 | 154 | gearmand_error_t Nuodb::initialize() | ||
249 | 155 | { | ||
250 | 156 | _create_query+= "CREATE TABLE " +table +" (unique_key VARCHAR" +"(" + TOSTRING(GEARMAN_UNIQUE_SIZE) +"), "; | ||
251 | 157 | _create_query+= "function_name VARCHAR(255), priority INTEGER, data BLOB, when_to_run INTEGER, UNIQUE (unique_key, function_name))"; | ||
252 | 158 | _insert_query+= "INSERT INTO " +table +" (priority, unique_key, function_name, data, when_to_run) VALUES(?,?,?,?,?)"; | ||
253 | 159 | _select_query+= "SELECT unique_key,function_name,priority,data,when_to_run FROM " +table; | ||
254 | 160 | gearmand_error_t ret= _initialize(Gearmand()->server, this); | ||
255 | 161 | return ret; | ||
256 | 162 | } | ||
257 | 163 | |||
258 | 164 | void initialize_nuodb() | ||
259 | 165 | { | ||
260 | 166 | static Nuodb local_instance; | ||
261 | 167 | } | ||
262 | 168 | |||
263 | 169 | } // namespace queue | ||
264 | 170 | } // namespace plugins | ||
265 | 171 | } // namespace gearmand | ||
266 | 172 | |||
267 | 173 | |||
268 | 174 | /* Queue callback functions. */ | ||
269 | 175 | static gearmand_error_t _nuodb_add(gearman_server_st *server, void *context, | ||
270 | 176 | const char *unique, size_t unique_size, | ||
271 | 177 | const char *function_name, | ||
272 | 178 | size_t function_name_size, | ||
273 | 179 | const void *data, size_t data_size, | ||
274 | 180 | gearman_job_priority_t priority, | ||
275 | 181 | int64_t when); | ||
276 | 182 | |||
277 | 183 | static gearmand_error_t _nuodb_flush(gearman_server_st *server, void *context); | ||
278 | 184 | |||
279 | 185 | static gearmand_error_t _nuodb_done(gearman_server_st *server, void *context, | ||
280 | 186 | const char *unique, | ||
281 | 187 | size_t unique_size, | ||
282 | 188 | const char *function_name, | ||
283 | 189 | size_t function_name_size); | ||
284 | 190 | |||
285 | 191 | static gearmand_error_t _nuodb_replay(gearman_server_st *server, void *context, | ||
286 | 192 | gearman_queue_add_fn *add_fn, | ||
287 | 193 | void *add_context); | ||
288 | 194 | |||
289 | 195 | /** @} */ | ||
290 | 196 | |||
291 | 197 | /* | ||
292 | 198 | * Public definitions | ||
293 | 199 | */ | ||
294 | 200 | |||
295 | 201 | gearmand_error_t _initialize(gearman_server_st& server, | ||
296 | 202 | gearmand::plugins::queue::Nuodb *queue) | ||
297 | 203 | { | ||
298 | 204 | // TODO: use nuodb_connnect_string | ||
299 | 205 | const char *database = queue->nuodb_connect_string.c_str(); | ||
300 | 206 | const char *user = queue->nuodb_user.c_str(); | ||
301 | 207 | const char *pw = queue->nuodb_pw.c_str(); | ||
302 | 208 | const char *schema = queue->schema.c_str(); | ||
303 | 209 | |||
304 | 210 | gearmand_info("Initializing nuodb module"); | ||
305 | 211 | |||
306 | 212 | gearman_server_set_queue(server, queue, _nuodb_add, _nuodb_flush, _nuodb_done, _nuodb_replay); | ||
307 | 213 | |||
308 | 214 | try { | ||
309 | 215 | queue->con = NuoDB::Connection::createUtf8(); | ||
310 | 216 | NuoDB::Properties* properties = queue->con->allocProperties(); | ||
311 | 217 | properties->putValue("user", user); | ||
312 | 218 | properties->putValue("password", pw); | ||
313 | 219 | properties->putValue("schema", schema); | ||
314 | 220 | queue->con->openDatabase(database, properties); | ||
315 | 221 | } catch (NuoDB::SQLException &e) { | ||
316 | 222 | gearman_server_set_queue(server, NULL, NULL, NULL, NULL, NULL); | ||
317 | 223 | return gearmand_log_gerror(GEARMAN_DEFAULT_LOG_PARAM, GEARMAND_QUEUE_ERROR, "NuoDB Connection: [%s] %s", e.getSqlcode(), e.getText()); | ||
318 | 224 | } catch (...) { | ||
319 | 225 | // Unknown error | ||
320 | 226 | queue->con = NULL; | ||
321 | 227 | } | ||
322 | 228 | if (queue->con == NULL) | ||
323 | 229 | { | ||
324 | 230 | gearman_server_set_queue(server, NULL, NULL, NULL, NULL, NULL); | ||
325 | 231 | return gearmand_log_gerror(GEARMAN_DEFAULT_LOG_PARAM, GEARMAND_QUEUE_ERROR, "NuoDB Connection: %s", "Unknown error"); | ||
326 | 232 | } | ||
327 | 233 | |||
328 | 234 | |||
329 | 235 | std::string query("SELECT TABLENAME FROM SYSTEM.TABLES WHERE TYPE = 'TABLE' AND SCHEMA = '" +queue->schema +"' AND TABLENAME = '" +queue->table + "'"); | ||
330 | 236 | |||
331 | 237 | NuoDB::PreparedStatement *stmt = NULL; | ||
332 | 238 | NuoDB::ResultSet *rs = NULL; | ||
333 | 239 | |||
334 | 240 | try { | ||
335 | 241 | stmt = queue->con->prepareStatement(query.c_str()); | ||
336 | 242 | stmt->execute(); | ||
337 | 243 | rs = stmt->getResultSet(); | ||
338 | 244 | } catch (NuoDB::SQLException &e) { | ||
339 | 245 | std::string error_string= "NuoDB:"; | ||
340 | 246 | error_string += "Queue error: ["; | ||
341 | 247 | error_string += e.getSqlcode(); | ||
342 | 248 | error_string += "] "; | ||
343 | 249 | error_string += e.getText(); | ||
344 | 250 | gearmand_gerror(error_string.c_str(), GEARMAND_QUEUE_ERROR); | ||
345 | 251 | return GEARMAND_QUEUE_ERROR; | ||
346 | 252 | } catch (...) { | ||
347 | 253 | // Unknown error | ||
348 | 254 | rs = NULL; | ||
349 | 255 | } | ||
350 | 256 | |||
351 | 257 | if (rs == NULL) { | ||
352 | 258 | std::string error_string= "NuoDB:"; | ||
353 | 259 | error_string+= "No results for query: "; | ||
354 | 260 | error_string+= query.c_str(); | ||
355 | 261 | gearmand_gerror(error_string.c_str(), GEARMAND_QUEUE_ERROR); | ||
356 | 262 | return GEARMAND_QUEUE_ERROR; | ||
357 | 263 | } | ||
358 | 264 | |||
359 | 265 | if (!rs->next()) | ||
360 | 266 | { | ||
361 | 267 | gearmand_log_info(GEARMAN_DEFAULT_LOG_PARAM, "nuodb module creating table '%s'", queue->table.c_str()); | ||
362 | 268 | |||
363 | 269 | bool result = 1; | ||
364 | 270 | const char *sql = queue->create().c_str(); | ||
365 | 271 | try { | ||
366 | 272 | stmt = queue->con->prepareStatement(sql); | ||
367 | 273 | result = stmt->execute(); | ||
368 | 274 | } catch (NuoDB::SQLException &e) { | ||
369 | 275 | std::string error_string= "NuoDB:"; | ||
370 | 276 | error_string += "Table create error: ["; | ||
371 | 277 | error_string += e.getSqlcode(); | ||
372 | 278 | error_string += "] "; | ||
373 | 279 | error_string += e.getText(); | ||
374 | 280 | gearmand_gerror(error_string.c_str(), GEARMAND_QUEUE_ERROR); | ||
375 | 281 | return GEARMAND_QUEUE_ERROR; | ||
376 | 282 | } catch (...) { | ||
377 | 283 | // Unknown error | ||
378 | 284 | std::string error_string= "NuoDB:"; | ||
379 | 285 | error_string+= "Table create error for statement: "; | ||
380 | 286 | error_string+= query.c_str(); | ||
381 | 287 | gearmand_gerror(error_string.c_str(), GEARMAND_QUEUE_ERROR); | ||
382 | 288 | return GEARMAND_QUEUE_ERROR; | ||
383 | 289 | } | ||
384 | 290 | |||
385 | 291 | if (result == 1) | ||
386 | 292 | { | ||
387 | 293 | gearmand_log_error(GEARMAN_DEFAULT_LOG_PARAM, | ||
388 | 294 | "NuoDB:Problem creating table: %s", sql); | ||
389 | 295 | gearman_server_set_queue(server, NULL, NULL, NULL, NULL, NULL); | ||
390 | 296 | return GEARMAND_QUEUE_ERROR; | ||
391 | 297 | } | ||
392 | 298 | } | ||
393 | 299 | |||
394 | 300 | const char *insert_sql = queue->insert().c_str(); | ||
395 | 301 | try { | ||
396 | 302 | queue->_insert_stmt = queue->con->prepareStatement(insert_sql); | ||
397 | 303 | } catch (NuoDB::SQLException &e) { | ||
398 | 304 | std::string error_string= "NuoDB:"; | ||
399 | 305 | error_string += "Error preparing insert statement: ["; | ||
400 | 306 | error_string += e.getSqlcode(); | ||
401 | 307 | error_string += "] "; | ||
402 | 308 | error_string += e.getText(); | ||
403 | 309 | gearmand_gerror(error_string.c_str(), GEARMAND_QUEUE_ERROR); | ||
404 | 310 | return GEARMAND_QUEUE_ERROR; | ||
405 | 311 | } catch (...) { | ||
406 | 312 | // Unknown error | ||
407 | 313 | std::string error_string= "NuoDB:"; | ||
408 | 314 | error_string+= "Error preparing insert statement: "; | ||
409 | 315 | error_string+= insert_sql; | ||
410 | 316 | gearmand_gerror(error_string.c_str(), GEARMAND_QUEUE_ERROR); | ||
411 | 317 | return GEARMAND_QUEUE_ERROR; | ||
412 | 318 | } | ||
413 | 319 | |||
414 | 320 | std::string delete_query; | ||
415 | 321 | delete_query+= "DELETE FROM "; | ||
416 | 322 | delete_query+= queue->table; | ||
417 | 323 | delete_query+= " WHERE unique_key = ?"; | ||
418 | 324 | delete_query+= " AND function_name = ?"; | ||
419 | 325 | const char *delete_sql = delete_query.c_str(); | ||
420 | 326 | try { | ||
421 | 327 | queue->_delete_stmt = queue->con->prepareStatement(delete_sql); | ||
422 | 328 | } catch (NuoDB::SQLException &e) { | ||
423 | 329 | std::string error_string= "NuoDB:"; | ||
424 | 330 | error_string += "Error preparing delete statement: ["; | ||
425 | 331 | error_string += e.getSqlcode(); | ||
426 | 332 | error_string += "] "; | ||
427 | 333 | error_string += e.getText(); | ||
428 | 334 | gearmand_gerror(error_string.c_str(), GEARMAND_QUEUE_ERROR); | ||
429 | 335 | return GEARMAND_QUEUE_ERROR; | ||
430 | 336 | } catch (...) { | ||
431 | 337 | // Unknown error | ||
432 | 338 | std::string error_string= "NuoDB:"; | ||
433 | 339 | error_string+= "Error preparing delete statement: "; | ||
434 | 340 | error_string+= insert_sql; | ||
435 | 341 | gearmand_gerror(error_string.c_str(), GEARMAND_QUEUE_ERROR); | ||
436 | 342 | return GEARMAND_QUEUE_ERROR; | ||
437 | 343 | } | ||
438 | 344 | |||
439 | 345 | std::string select_query("SELECT unique_key,function_name,priority,data,when_to_run FROM " + queue->table); | ||
440 | 346 | const char *select_sql = select_query.c_str(); | ||
441 | 347 | try { | ||
442 | 348 | queue->_select_stmt = queue->con->prepareStatement(select_sql); | ||
443 | 349 | } catch (NuoDB::SQLException &e) { | ||
444 | 350 | std::string error_string= "NuoDB:"; | ||
445 | 351 | error_string += "Error preparing select statement: ["; | ||
446 | 352 | error_string += e.getSqlcode(); | ||
447 | 353 | error_string += "] "; | ||
448 | 354 | error_string += e.getText(); | ||
449 | 355 | gearmand_gerror(error_string.c_str(), GEARMAND_QUEUE_ERROR); | ||
450 | 356 | return GEARMAND_QUEUE_ERROR; | ||
451 | 357 | } catch (...) { | ||
452 | 358 | // Unknown error | ||
453 | 359 | std::string error_string= "NuoDB:"; | ||
454 | 360 | error_string+= "Error preparing select statement: "; | ||
455 | 361 | error_string+= insert_sql; | ||
456 | 362 | gearmand_gerror(error_string.c_str(), GEARMAND_QUEUE_ERROR); | ||
457 | 363 | return GEARMAND_QUEUE_ERROR; | ||
458 | 364 | } | ||
459 | 365 | |||
460 | 366 | rs->close(); | ||
461 | 367 | rs = NULL; | ||
462 | 368 | stmt->close(); | ||
463 | 369 | stmt = NULL; | ||
464 | 370 | return GEARMAND_SUCCESS; | ||
465 | 371 | } | ||
466 | 372 | |||
467 | 373 | /* | ||
468 | 374 | * Static definitions | ||
469 | 375 | */ | ||
470 | 376 | |||
471 | 377 | static gearmand_error_t _nuodb_add(gearman_server_st*, void *context, | ||
472 | 378 | const char *unique, size_t unique_size, | ||
473 | 379 | const char *function_name, | ||
474 | 380 | size_t function_name_size, | ||
475 | 381 | const void *data, size_t data_size, | ||
476 | 382 | gearman_job_priority_t priority, | ||
477 | 383 | int64_t when) | ||
478 | 384 | { | ||
479 | 385 | gearmand::plugins::queue::Nuodb *queue= (gearmand::plugins::queue::Nuodb *)context; | ||
480 | 386 | |||
481 | 387 | gearmand_log_debug(GEARMAN_DEFAULT_LOG_PARAM, "nuodb add: %.*s", (uint32_t)unique_size, (char *)unique); | ||
482 | 388 | |||
483 | 389 | |||
484 | 390 | NuoDB::PreparedStatement *stmt = queue->insert_stmt(); | ||
485 | 391 | |||
486 | 392 | try { | ||
487 | 393 | stmt->setInt(1, static_cast<uint32_t>(priority)); | ||
488 | 394 | stmt->setString(2, unique); | ||
489 | 395 | stmt->setString(3, function_name); | ||
490 | 396 | stmt->setBytes(4, data_size, (const void *) data); | ||
491 | 397 | stmt->setLong(5, when); | ||
492 | 398 | stmt->execute(); | ||
493 | 399 | } catch (NuoDB::SQLException &e) { | ||
494 | 400 | std::string error_string= "NuoDB:"; | ||
495 | 401 | error_string += "Add queue error: ["; | ||
496 | 402 | error_string += e.getSqlcode() + "] "; | ||
497 | 403 | error_string += e.getText(); | ||
498 | 404 | gearmand_gerror(error_string.c_str(), GEARMAND_QUEUE_ERROR); | ||
499 | 405 | return GEARMAND_QUEUE_ERROR; | ||
500 | 406 | } catch (...) { | ||
501 | 407 | // Unknown error | ||
502 | 408 | std::string error_string= "NuoDB:"; | ||
503 | 409 | error_string+= "Unable to add to queue "; | ||
504 | 410 | gearmand_gerror(error_string.c_str(), GEARMAND_QUEUE_ERROR); | ||
505 | 411 | return GEARMAND_QUEUE_ERROR; | ||
506 | 412 | } | ||
507 | 413 | |||
508 | 414 | return GEARMAND_SUCCESS; | ||
509 | 415 | } | ||
510 | 416 | |||
511 | 417 | static gearmand_error_t _nuodb_flush(gearman_server_st *, void *) | ||
512 | 418 | { | ||
513 | 419 | gearmand_debug("nuodb flush"); | ||
514 | 420 | |||
515 | 421 | return GEARMAND_SUCCESS; | ||
516 | 422 | } | ||
517 | 423 | |||
518 | 424 | static gearmand_error_t _nuodb_done(gearman_server_st*, void *context, | ||
519 | 425 | const char *unique, | ||
520 | 426 | size_t unique_size, | ||
521 | 427 | const char *function_name, | ||
522 | 428 | size_t function_name_size) | ||
523 | 429 | { | ||
524 | 430 | (void)function_name_size; | ||
525 | 431 | gearmand::plugins::queue::Nuodb *queue= (gearmand::plugins::queue::Nuodb *)context; | ||
526 | 432 | gearmand_log_debug(GEARMAN_DEFAULT_LOG_PARAM, "nuodb done: %.*s", (uint32_t)unique_size, (char *)unique); | ||
527 | 433 | |||
528 | 434 | NuoDB::PreparedStatement *stmt = queue->delete_stmt(); | ||
529 | 435 | |||
530 | 436 | try { | ||
531 | 437 | stmt->setString(1, unique); | ||
532 | 438 | stmt->setString(2, function_name); | ||
533 | 439 | stmt->execute(); | ||
534 | 440 | } catch (NuoDB::SQLException &e) { | ||
535 | 441 | std::string error_string= "NuoDB:"; | ||
536 | 442 | error_string += "Delete queue error: ["; | ||
537 | 443 | error_string += e.getSqlcode(); | ||
538 | 444 | error_string += "] "; | ||
539 | 445 | error_string += e.getText(); | ||
540 | 446 | gearmand_gerror(error_string.c_str(), GEARMAND_QUEUE_ERROR); | ||
541 | 447 | return GEARMAND_QUEUE_ERROR; | ||
542 | 448 | } catch (...) { | ||
543 | 449 | // Unknown error | ||
544 | 450 | std::string error_string= "NuoDB:"; | ||
545 | 451 | error_string+= "Unable to delete from queue "; | ||
546 | 452 | gearmand_gerror(error_string.c_str(), GEARMAND_QUEUE_ERROR); | ||
547 | 453 | return GEARMAND_QUEUE_ERROR; | ||
548 | 454 | } | ||
549 | 455 | |||
550 | 456 | return GEARMAND_SUCCESS; | ||
551 | 457 | } | ||
552 | 458 | |||
553 | 459 | static gearmand_error_t _nuodb_replay(gearman_server_st *server, void *context, | ||
554 | 460 | gearman_queue_add_fn *add_fn, | ||
555 | 461 | void *add_context) | ||
556 | 462 | { | ||
557 | 463 | gearmand::plugins::queue::Nuodb *queue= (gearmand::plugins::queue::Nuodb *)context; | ||
558 | 464 | |||
559 | 465 | gearmand_info("nuodb replay start"); | ||
560 | 466 | |||
561 | 467 | |||
562 | 468 | NuoDB::PreparedStatement *stmt = queue->select_stmt(); | ||
563 | 469 | NuoDB::ResultSet *rs = NULL; | ||
564 | 470 | |||
565 | 471 | |||
566 | 472 | try { | ||
567 | 473 | stmt->execute(); | ||
568 | 474 | rs = stmt->getResultSet(); | ||
569 | 475 | } catch (NuoDB::SQLException &e) { | ||
570 | 476 | std::string error_string= "NuoDB:"; | ||
571 | 477 | error_string += "Select error: ["; | ||
572 | 478 | error_string += e.getSqlcode(); | ||
573 | 479 | error_string += "] "; | ||
574 | 480 | error_string += e.getText(); | ||
575 | 481 | gearmand_gerror(error_string.c_str(), GEARMAND_QUEUE_ERROR); | ||
576 | 482 | return GEARMAND_QUEUE_ERROR; | ||
577 | 483 | } catch (...) { | ||
578 | 484 | // Unknown error | ||
579 | 485 | rs = NULL; | ||
580 | 486 | } | ||
581 | 487 | |||
582 | 488 | if (rs == NULL) | ||
583 | 489 | { | ||
584 | 490 | std::string error_string= "NuoDB:"; | ||
585 | 491 | error_string+= "No results for query "; | ||
586 | 492 | gearmand_gerror(error_string.c_str(), GEARMAND_QUEUE_ERROR); | ||
587 | 493 | return GEARMAND_QUEUE_ERROR; | ||
588 | 494 | } | ||
589 | 495 | |||
590 | 496 | |||
591 | 497 | while(rs->next()) | ||
592 | 498 | { | ||
593 | 499 | const char *unique_key; | ||
594 | 500 | const char *function_name; | ||
595 | 501 | int priority; | ||
596 | 502 | size_t data_length; | ||
597 | 503 | char *data; | ||
598 | 504 | int when_to_run; | ||
599 | 505 | |||
600 | 506 | unique_key = rs->getString(1); | ||
601 | 507 | gearmand_log_debug(GEARMAN_DEFAULT_LOG_PARAM, | ||
602 | 508 | "nuodb replay: %s", | ||
603 | 509 | unique_key); | ||
604 | 510 | |||
605 | 511 | NuoDB::Blob *blob = rs->getBlob(4); | ||
606 | 512 | if (blob == NULL) | ||
607 | 513 | { | ||
608 | 514 | data= NULL; | ||
609 | 515 | data_length= 0; | ||
610 | 516 | } | ||
611 | 517 | else | ||
612 | 518 | { | ||
613 | 519 | data_length = size_t(blob->length()); | ||
614 | 520 | data= (char *)malloc(data_length); | ||
615 | 521 | if (data == NULL) | ||
616 | 522 | { | ||
617 | 523 | return gearmand_perror(errno, "malloc"); | ||
618 | 524 | } | ||
619 | 525 | blob->getBytes(0, data_length, (unsigned char *)data); | ||
620 | 526 | } | ||
621 | 527 | |||
622 | 528 | gearmand_error_t ret; | ||
623 | 529 | function_name = rs->getString(2); | ||
624 | 530 | priority = rs->getInt(3); | ||
625 | 531 | when_to_run = rs->getInt(5); | ||
626 | 532 | ret= (*add_fn)(server, add_context, unique_key, | ||
627 | 533 | (size_t) strlen(unique_key), | ||
628 | 534 | function_name, | ||
629 | 535 | (size_t) strlen(function_name), | ||
630 | 536 | data, data_length, | ||
631 | 537 | (gearman_job_priority_t) priority, | ||
632 | 538 | when_to_run); | ||
633 | 539 | if (gearmand_failed(ret)) | ||
634 | 540 | { | ||
635 | 541 | rs->close(); | ||
636 | 542 | return ret; | ||
637 | 543 | } | ||
638 | 544 | } | ||
639 | 545 | |||
640 | 546 | rs->close(); | ||
641 | 547 | return GEARMAND_SUCCESS; | ||
642 | 548 | } | ||
643 | 549 | |||
644 | 550 | #pragma GCC diagnostic pop | ||
645 | 0 | 551 | ||
646 | === added file 'libgearman-server/plugins/queue/nuodb/queue.h' | |||
647 | --- libgearman-server/plugins/queue/nuodb/queue.h 1970-01-01 00:00:00 +0000 | |||
648 | +++ libgearman-server/plugins/queue/nuodb/queue.h 2014-05-09 18:35:29 +0000 | |||
649 | @@ -0,0 +1,49 @@ | |||
650 | 1 | /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: | ||
651 | 2 | * | ||
652 | 3 | * Gearmand client and server library. | ||
653 | 4 | * | ||
654 | 5 | * Copyright (C) 2011 Data Differential, http://datadifferential.com/ | ||
655 | 6 | * All rights reserved. | ||
656 | 7 | * | ||
657 | 8 | * Redistribution and use in source and binary forms, with or without | ||
658 | 9 | * modification, are permitted provided that the following conditions are | ||
659 | 10 | * met: | ||
660 | 11 | * | ||
661 | 12 | * * Redistributions of source code must retain the above copyright | ||
662 | 13 | * notice, this list of conditions and the following disclaimer. | ||
663 | 14 | * | ||
664 | 15 | * * Redistributions in binary form must reproduce the above | ||
665 | 16 | * copyright notice, this list of conditions and the following disclaimer | ||
666 | 17 | * in the documentation and/or other materials provided with the | ||
667 | 18 | * distribution. | ||
668 | 19 | * | ||
669 | 20 | * * The names of its contributors may not be used to endorse or | ||
670 | 21 | * promote products derived from this software without specific prior | ||
671 | 22 | * written permission. | ||
672 | 23 | * | ||
673 | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
674 | 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
675 | 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
676 | 27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
677 | 28 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
678 | 29 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
679 | 30 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
680 | 31 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
681 | 32 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
682 | 33 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
683 | 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
684 | 35 | * | ||
685 | 36 | */ | ||
686 | 37 | |||
687 | 38 | #pragma once | ||
688 | 39 | |||
689 | 40 | |||
690 | 41 | namespace gearmand { | ||
691 | 42 | namespace plugins { | ||
692 | 43 | namespace queue { | ||
693 | 44 | |||
694 | 45 | void initialize_nuodb(); | ||
695 | 46 | |||
696 | 47 | } // namespace queue | ||
697 | 48 | } // namespace plugin | ||
698 | 49 | } // namespace gearmand | ||
699 | 0 | 50 | ||
700 | === added file 'm4/ax_lib_nuodb.m4' | |||
701 | --- m4/ax_lib_nuodb.m4 1970-01-01 00:00:00 +0000 | |||
702 | +++ m4/ax_lib_nuodb.m4 2014-05-09 18:35:29 +0000 | |||
703 | @@ -0,0 +1,130 @@ | |||
704 | 1 | # | ||
705 | 2 | # SYNOPSIS | ||
706 | 3 | # | ||
707 | 4 | # AX_LIB_NUODB([MINIMUM-VERSION]) | ||
708 | 5 | # | ||
709 | 6 | # DESCRIPTION | ||
710 | 7 | # | ||
711 | 8 | # This macro provides tests of availability of NuoDB 'libRemote' library | ||
712 | 9 | # of particular version or newer. | ||
713 | 10 | # | ||
714 | 11 | # AX_LIB_NUODB macro takes only one argument which is optional. If | ||
715 | 12 | # there is no required version passed, then macro does not run version | ||
716 | 13 | # test. | ||
717 | 14 | # | ||
718 | 15 | # The --with-nuodb option takes one of three possible values: | ||
719 | 16 | # | ||
720 | 17 | # no - do not check for NuoDB client library | ||
721 | 18 | # | ||
722 | 19 | # yes - do check for NuoDB client library in standard locations | ||
723 | 20 | # | ||
724 | 21 | # path - complete path to NuoDB home directory | ||
725 | 22 | # | ||
726 | 23 | # This macro calls: | ||
727 | 24 | # | ||
728 | 25 | # AC_SUBST(NUODB_CFLAGS) | ||
729 | 26 | # AC_SUBST(NUODB_LDFLAGS) | ||
730 | 27 | # AC_SUBST(NUODB_VERSION) | ||
731 | 28 | # | ||
732 | 29 | # And sets: | ||
733 | 30 | # | ||
734 | 31 | # HAVE_NUODB | ||
735 | 32 | # | ||
736 | 33 | |||
737 | 34 | AC_DEFUN([AX_LIB_NUODB], | ||
738 | 35 | [ | ||
739 | 36 | AC_ARG_WITH([nuodb], | ||
740 | 37 | AS_HELP_STRING([--with-nuodb=@<:@ARG@:>@], | ||
741 | 38 | [use NuoDB libNuoRemote library @<:@default=yes@:>@, optionally specify path to NuoDB Home Directory] | ||
742 | 39 | ), | ||
743 | 40 | [ | ||
744 | 41 | if test "$withval" = "no"; then | ||
745 | 42 | WANT_NUODB="no" | ||
746 | 43 | elif test "$withval" = "yes"; then | ||
747 | 44 | WANT_NUODB="yes" | ||
748 | 45 | NUOHOME="/opt/nuodb" | ||
749 | 46 | else | ||
750 | 47 | WANT_NUODB="yes" | ||
751 | 48 | NUOHOME="$withval" | ||
752 | 49 | fi | ||
753 | 50 | ], | ||
754 | 51 | [WANT_NUODB="yes"] | ||
755 | 52 | ) | ||
756 | 53 | |||
757 | 54 | NUODB_CFLAGS="" | ||
758 | 55 | NUODB_LDFLAGS="" | ||
759 | 56 | NUODB_VERSION="" | ||
760 | 57 | |||
761 | 58 | dnl | ||
762 | 59 | dnl Check NuoDB libraries (libNuoRemote) | ||
763 | 60 | dnl | ||
764 | 61 | |||
765 | 62 | if test "$WANT_NUODB" = "yes"; then | ||
766 | 63 | |||
767 | 64 | if test -z "$NUOHOME" -o test; then | ||
768 | 65 | |||
769 | 66 | AC_MSG_CHECKING([for NuoDB libraries]) | ||
770 | 67 | |||
771 | 68 | NUODB_CFLAGS="-I$NUOHOME/include" | ||
772 | 69 | NUODB_LDFLAGS="-L$NUOHOME/lib64 -lNuoRemote" | ||
773 | 70 | NUODB_VERSION=`$NUOHOME/bin/nuochk --version | sed -e 's#NuoDB Server build ##'` | ||
774 | 71 | AC_DEFINE([HAVE_NUODB], [1], | ||
775 | 72 | [Define to 1 if NuoDB libraries are available]) | ||
776 | 73 | |||
777 | 74 | found_nuodb="yes" | ||
778 | 75 | AC_MSG_RESULT([yes]) | ||
779 | 76 | else | ||
780 | 77 | found_nuodb="no" | ||
781 | 78 | AC_MSG_RESULT([no]) | ||
782 | 79 | fi | ||
783 | 80 | fi | ||
784 | 81 | |||
785 | 82 | dnl | ||
786 | 83 | dnl Check if required version of NuoDB is available | ||
787 | 84 | dnl | ||
788 | 85 | |||
789 | 86 | |||
790 | 87 | nuodb_version_req=ifelse([$1], [], [], [$1]) | ||
791 | 88 | |||
792 | 89 | if test "$found_nuodb" = "yes" -a -n "$nuodb_version_req"; then | ||
793 | 90 | |||
794 | 91 | AC_MSG_CHECKING([if NuoDB version is >= $nuodb_version_req]) | ||
795 | 92 | |||
796 | 93 | dnl Decompose required version string of NuoDB | ||
797 | 94 | dnl and calculate its number representation | ||
798 | 95 | nuodb_version_req_major=`expr $nuodb_version_req : '\([[0-9]]*\)'` | ||
799 | 96 | nuodb_version_req_minor=`expr $nuodb_version_req : '[[0-9]]*\.\([[0-9]]*\)'` | ||
800 | 97 | nuodb_version_req_micro=`expr $nuodb_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'` | ||
801 | 98 | if test "x$nuodb_version_req_micro" = "x"; then | ||
802 | 99 | nuodb_version_req_micro="0" | ||
803 | 100 | fi | ||
804 | 101 | |||
805 | 102 | nuodb_version_req_number=`expr $nuodb_version_req_major \* 1000000 \ | ||
806 | 103 | \+ $nuodb_version_req_minor \* 1000 \ | ||
807 | 104 | \+ $nuodb_version_req_micro` | ||
808 | 105 | |||
809 | 106 | dnl Decompose version string of installed NuoDB | ||
810 | 107 | dnl and calculate its number representation | ||
811 | 108 | nuodb_version_major=`expr $NUODB_VERSION : '\([[0-9]]*\)'` | ||
812 | 109 | nuodb_version_minor=`expr $NUODB_VERSION : '[[0-9]]*\.\([[0-9]]*\)'` | ||
813 | 110 | nuodb_version_micro=`expr $NUODB_VERSION : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'` | ||
814 | 111 | if test "x$nuodb_version_micro" = "x"; then | ||
815 | 112 | nuodb_version_micro="0" | ||
816 | 113 | fi | ||
817 | 114 | |||
818 | 115 | nuodb_version_number=`expr $nuodb_version_major \* 1000000 \ | ||
819 | 116 | \+ $nuodb_version_minor \* 1000 \ | ||
820 | 117 | \+ $nuodb_version_micro` | ||
821 | 118 | |||
822 | 119 | nuodb_version_check=`expr $nuodb_version_number \>\= $nuodb_version_req_number` | ||
823 | 120 | if test "$nuodb_version_check" = "1"; then | ||
824 | 121 | AC_MSG_RESULT([yes]) | ||
825 | 122 | else | ||
826 | 123 | AC_MSG_RESULT([no]) | ||
827 | 124 | fi | ||
828 | 125 | fi | ||
829 | 126 | |||
830 | 127 | AC_SUBST([NUODB_VERSION]) | ||
831 | 128 | AC_SUBST([NUODB_CFLAGS]) | ||
832 | 129 | AC_SUBST([NUODB_LDFLAGS]) | ||
833 | 130 | ]) |