Merge lp:~brianaker/drizzle/libdrizzle-startup-issue into lp:drizzle/7.1

Proposed by Brian Aker
Status: Merged
Approved by: Brian Aker
Approved revision: not available
Merged at revision: 2540
Proposed branch: lp:~brianaker/drizzle/libdrizzle-startup-issue
Merge into: lp:drizzle/7.1
Diff against target: 416 lines (+208/-33) (has conflicts)
12 files modified
Makefile.am (+1/-0)
configure.ac (+6/-20)
drizzled/drizzled.cc (+31/-7)
libdrizzle-1.0/drizzle_client.h (+1/-0)
libdrizzle-1.0/include.am (+1/-0)
libdrizzle-1.0/version.h.in (+41/-0)
libdrizzle/conn.cc (+91/-0)
libdrizzle/drizzle.cc (+1/-1)
m4/libdrizzle_version.m4 (+30/-0)
support-files/drizzle.pc.in (+1/-1)
support-files/libdrizzle-1.0.pc.in (+2/-2)
support-files/libdrizzle.pc.in (+2/-2)
Text conflict in configure.ac
To merge this branch: bzr merge lp:~brianaker/drizzle/libdrizzle-startup-issue
Reviewer Review Type Date Requested Status
Drizzle Trunk Pending
Review via email: mp+102242@code.launchpad.net

Description of the change

If you try to connect to the database while it is starting up, the connection will fail.

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 'Makefile.am'
2--- Makefile.am 2012-02-10 22:39:36 +0000
3+++ Makefile.am 2012-04-17 06:13:20 +0000
4@@ -162,6 +162,7 @@
5 fi
6
7 clean-local:
8+ rm libdrizzle-1.0/version.h
9 find . -name '*.gcno' | xargs rm -f
10 -rm -rf docs/api docs/dev docs/_build docs/doctrees
11 rm -Rf $(SPHINX_BUILDDIR)/html $(SPHINX_BUILDDIR)/dirhtml $(SPHINX_BUILDDIR)/singlehtml \
12
13=== modified file 'configure.ac'
14--- configure.ac 2012-02-23 15:39:59 +0000
15+++ configure.ac 2012-04-17 06:13:20 +0000
16@@ -26,26 +26,7 @@
17
18 PANDORA_CANONICAL_TARGET(less-warnings, require-cxx, force-gcc42, version-from-vc)
19
20-LIBDRIZZLE_LIBRARY_VERSION=4:0:0
21-# | | |
22-# +------+ | +---+
23-# | | |
24-# current:revision:age
25-# | | |
26-# | | +- increment if interfaces have been added
27-# | | set to zero if interfaces have been
28-# | | removed or changed
29-# | +- increment if source code has changed
30-# | set to zero if current is incremented
31-# +- increment if interfaces have been added, removed or
32-# changed
33-AC_SUBST(LIBDRIZZLE_LIBRARY_VERSION)
34-
35-# libdrizzle versioning when linked with GNU ld.
36-AS_IF([test "$lt_cv_prog_gnu_ld" = "yes"],[
37- LD_VERSION_SCRIPT="-Wl,--version-script=\$(top_srcdir)/config/drizzle.ver"
38- ])
39-AC_SUBST(LD_VERSION_SCRIPT)
40+m4_include([m4/libdrizzle_version.m4])
41
42 dnl Set the default datadir location to /usr/local/var/drizzle. If a
43 dnl localstatedir is explicitly given, just use that.
44@@ -154,7 +135,12 @@
45 AC_CONFIG_FILES(Makefile dnl
46 tests/Makefile dnl
47 drizzled/plugin/version.h dnl
48+<<<<<<< TREE
49 support-files/rpm/SPECS/drizzle.spec dnl
50+=======
51+ libdrizzle-1.0/version.h dnl
52+ support-files/drizzle.spec dnl
53+>>>>>>> MERGE-SOURCE
54 support-files/drizzle.pc dnl
55 support-files/libdrizzle.pc dnl
56 support-files/libdrizzle-1.0.pc dnl
57
58=== modified file 'drizzled/drizzled.cc'
59--- drizzled/drizzled.cc 2012-04-03 13:19:08 +0000
60+++ drizzled/drizzled.cc 2012-04-17 06:13:20 +0000
61@@ -389,6 +389,25 @@
62 PANDORA_RELEASE_VERSION, HOST_VENDOR, HOST_OS, HOST_CPU, COMPILATION_COMMENT);
63 }
64
65+extern "C" {
66+
67+ char at_exit_pid_file[1024 * 4]= { 0 };
68+
69+ static void remove_pidfile(void)
70+ {
71+ if (at_exit_pid_file[0])
72+ {
73+ if (unlink(at_exit_pid_file) == -1)
74+ {
75+ std::cerr << "Could not remove pidfile: " << at_exit_pid_file << "(" << strerror(errno) << ")" << std::endl;
76+ }
77+
78+ at_exit_pid_file[0]= 0;
79+ }
80+ }
81+
82+}
83+
84 /**
85 Create file to store pid number.
86 */
87@@ -405,6 +424,8 @@
88 {
89 if (close(file) != -1)
90 {
91+ snprintf(at_exit_pid_file, sizeof(at_exit_pid_file), "%s", pid_file.file_string().c_str());
92+ atexit(remove_pidfile);
93 return;
94 }
95 }
96@@ -535,8 +556,6 @@
97 google::protobuf::ShutdownProtobufLibrary();
98 #endif
99
100- (void) unlink(pid_file.file_string().c_str()); // This may not always exist
101-
102 if (print_message && server_start_time)
103 {
104 errmsg_printf(drizzled::error::INFO, _(ER(ER_SHUTDOWN_COMPLETE)),internal::my_progname);
105@@ -2179,13 +2198,18 @@
106 }
107
108 {
109- fs::path pid_file_path(pid_file);
110- if (pid_file_path.root_path().string() == "")
111+ if (pid_file.string().size() and pid_file.string()[0] == '/')
112+ { } // Do nothing if the file starts with a slash
113+ else
114 {
115- pid_file_path= getDataHome();
116- pid_file_path /= pid_file;
117+ fs::path pid_file_path(pid_file);
118+ if (pid_file_path.root_path().string() == "")
119+ {
120+ pid_file_path= getDataHome();
121+ pid_file_path /= pid_file;
122+ }
123+ pid_file= fs::system_complete(pid_file_path);
124 }
125- pid_file= fs::system_complete(pid_file_path);
126 }
127
128 const char *tmp_string= getenv("TMPDIR");
129
130=== modified file 'libdrizzle-1.0/drizzle_client.h'
131--- libdrizzle-1.0/drizzle_client.h 2012-01-05 06:31:25 +0000
132+++ libdrizzle-1.0/drizzle_client.h 2012-04-17 06:13:20 +0000
133@@ -42,6 +42,7 @@
134
135 #pragma once
136
137+#include <libdrizzle-1.0/version.h>
138 #include <libdrizzle-1.0/drizzle.h>
139 #include <libdrizzle-1.0/conn_client.h>
140 #include <libdrizzle-1.0/handshake_client.h>
141
142=== modified file 'libdrizzle-1.0/include.am'
143--- libdrizzle-1.0/include.am 2012-02-17 20:27:53 +0000
144+++ libdrizzle-1.0/include.am 2012-04-17 06:13:20 +0000
145@@ -64,6 +64,7 @@
146 libdrizzle/sha1.cc \
147 libdrizzle/state.cc
148
149+nobase_include_HEADERS+= libdrizzle-1.0/version.h
150 nobase_include_HEADERS+= \
151 libdrizzle-1.0/column.h \
152 libdrizzle-1.0/column_client.h \
153
154=== added file 'libdrizzle-1.0/version.h.in'
155--- libdrizzle-1.0/version.h.in 1970-01-01 00:00:00 +0000
156+++ libdrizzle-1.0/version.h.in 2012-04-17 06:13:20 +0000
157@@ -0,0 +1,41 @@
158+/*
159+ * Drizzle Client & Protocol Library
160+ *
161+ * Copyright (C) 2012 Drizzle Project
162+ * All rights reserved.
163+ *
164+ * Redistribution and use in source and binary forms, with or without
165+ * modification, are permitted provided that the following conditions are
166+ * met:
167+ *
168+ * * Redistributions of source code must retain the above copyright
169+ * notice, this list of conditions and the following disclaimer.
170+ *
171+ * * Redistributions in binary form must reproduce the above
172+ * copyright notice, this list of conditions and the following disclaimer
173+ * in the documentation and/or other materials provided with the
174+ * distribution.
175+ *
176+ * * The names of its contributors may not be used to endorse or
177+ * promote products derived from this software without specific prior
178+ * written permission.
179+ *
180+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
181+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
183+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
184+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
185+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
186+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
187+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
188+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
189+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
190+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
191+ *
192+ */
193+
194+
195+#pragma once
196+
197+#define LIBDRIZZLE_VERSION_STRING "@LIBDRIZZLE_VERSION@"
198+#define LIBDRIZZLE_VERSION_HEX @LIBDRIZZLE_HEX_VERSION@
199
200=== modified file 'libdrizzle/conn.cc'
201--- libdrizzle/conn.cc 2012-01-30 05:36:54 +0000
202+++ libdrizzle/conn.cc 2012-04-17 06:13:20 +0000
203@@ -58,6 +58,86 @@
204 */
205 static drizzle_return_t _con_setsockopt(drizzle_con_st *con);
206
207+static bool connect_poll(drizzle_con_st *con)
208+{
209+ struct pollfd fds[1];
210+ fds[0].fd= con->fd;
211+ fds[0].events= POLLOUT;
212+
213+ size_t loop_max= 5;
214+ while (--loop_max) // Should only loop on cases of ERESTART or EINTR
215+ {
216+ int error= poll(fds, 1, con->drizzle->timeout);
217+ switch (error)
218+ {
219+ case 1:
220+ {
221+ int err;
222+ socklen_t len= sizeof (err);
223+ // We replace errno with err if getsockopt() passes, but err has been
224+ // set.
225+ if (getsockopt(con->fd, SOL_SOCKET, SO_ERROR, &err, &len) == 0)
226+ {
227+ // We check the value to see what happened wth the socket.
228+ if (err == 0)
229+ {
230+ return true;
231+ }
232+ errno= err;
233+ }
234+
235+ // "getsockopt() failed"
236+ return false;
237+ }
238+
239+ case 0:
240+ {
241+ // "timeout occurred while trying to connect"
242+ return false;
243+ }
244+
245+ default: // A real error occurred and we need to completely bail
246+ switch (get_socket_errno())
247+ {
248+#ifdef TARGET_OS_LINUX
249+ case ERESTART:
250+#endif
251+ case EINTR:
252+ continue;
253+
254+ case EFAULT:
255+ case ENOMEM:
256+ // "poll() failure"
257+ return false;
258+
259+ case EINVAL:
260+ // "RLIMIT_NOFILE exceeded, or if OSX the timeout value was invalid"
261+ return false;
262+
263+ default: // This should not happen
264+ if (fds[0].revents & POLLERR)
265+ {
266+ int err;
267+ socklen_t len= sizeof (err);
268+ (void)getsockopt(con->fd, SOL_SOCKET, SO_ERROR, &err, &len);
269+ errno= err;
270+ }
271+ else
272+ {
273+ errno= get_socket_errno();
274+ }
275+
276+ //"socket error occurred");
277+ return false;
278+ }
279+ }
280+ }
281+
282+ // This should only be possible from ERESTART or EINTR;
283+ // "connection failed (error should be from either ERESTART or EINTR"
284+ return false;
285+}
286+
287 /** @} */
288
289 /*
290@@ -700,13 +780,17 @@
291
292 *ret_ptr= drizzle_con_connect(con);
293 if (*ret_ptr != DRIZZLE_RETURN_OK)
294+ {
295 return result;
296+ }
297 }
298
299 if (drizzle_state_none(con))
300 {
301 if (con->options & (DRIZZLE_CON_RAW_PACKET | DRIZZLE_CON_NO_RESULT_READ))
302+ {
303 con->result= NULL;
304+ }
305 else
306 {
307 for (old_result= con->result_list; old_result != NULL; old_result= old_result->next)
308@@ -743,7 +827,9 @@
309
310 *ret_ptr= drizzle_state_loop(con);
311 if (*ret_ptr == DRIZZLE_RETURN_PAUSE)
312+ {
313 *ret_ptr= DRIZZLE_RETURN_OK;
314+ }
315 else if (*ret_ptr != DRIZZLE_RETURN_OK &&
316 *ret_ptr != DRIZZLE_RETURN_IO_WAIT &&
317 *ret_ptr != DRIZZLE_RETURN_ERROR_CODE)
318@@ -1300,6 +1386,11 @@
319
320 if (errno == EINPROGRESS)
321 {
322+ if (connect_poll(con))
323+ {
324+ drizzle_state_pop(con);
325+ return DRIZZLE_RETURN_OK;
326+ }
327 drizzle_state_pop(con);
328 drizzle_state_push(con, drizzle_state_connecting);
329 return DRIZZLE_RETURN_OK;
330
331=== modified file 'libdrizzle/drizzle.cc'
332--- libdrizzle/drizzle.cc 2012-01-30 05:36:54 +0000
333+++ libdrizzle/drizzle.cc 2012-04-17 06:13:20 +0000
334@@ -69,7 +69,7 @@
335
336 const char *drizzle_version(void)
337 {
338- return PACKAGE_VERSION;
339+ return LIBDRIZZLE_VERSION_STRING;
340 }
341
342 const char *drizzle_bugreport(void)
343
344=== added file 'm4/libdrizzle_version.m4'
345--- m4/libdrizzle_version.m4 1970-01-01 00:00:00 +0000
346+++ m4/libdrizzle_version.m4 2012-04-17 06:13:20 +0000
347@@ -0,0 +1,30 @@
348+#
349+# Version information for libdrizzle
350+#
351+#
352+LIBDRIZZLE_VERSION=1.0.1
353+LIBDRIZZLE_LIBRARY_VERSION=4:0:0
354+# | | |
355+# +------+ | +---+
356+# | | |
357+# current:revision:age
358+# | | |
359+# | | +- increment if interfaces have been added
360+# | | set to zero if interfaces have been
361+# | | removed or changed
362+# | +- increment if source code has changed
363+# | set to zero if current is incremented
364+# +- increment if interfaces have been added, removed or
365+# changed
366+AC_SUBST(LIBDRIZZLE_LIBRARY_VERSION)
367+AC_SUBST(LIBDRIZZLE_VERSION)
368+AC_DEFINE_UNQUOTED([LIBDRIZZLE_VERSION],[$LIBDRIZZLE_VERSION], [libdrizzle version])
369+
370+# libdrizzle versioning when linked with GNU ld.
371+AS_IF([test "$lt_cv_prog_gnu_ld" = "yes"],[
372+ LD_VERSION_SCRIPT="-Wl,--version-script=\$(top_srcdir)/config/drizzle.ver"
373+ ])
374+AC_SUBST(LD_VERSION_SCRIPT)
375+
376+LIBDRIZZLE_HEX_VERSION=`echo $LIBDRIZZLE_VERSION | sed 's|[\-a-z0-9]*$||' | awk -F. '{printf "0x%0.2d%0.3d%0.3d", $[]1, $[]2, $[]3}'`
377+AC_SUBST([LIBDRIZZLE_HEX_VERSION])
378
379=== modified file 'support-files/drizzle.pc.in'
380--- support-files/drizzle.pc.in 2012-02-08 22:20:27 +0000
381+++ support-files/drizzle.pc.in 2012-04-17 06:13:20 +0000
382@@ -7,5 +7,5 @@
383 Description: Drizzle CLI
384 Version: @VERSION@
385 URL: http://drizzle.org/
386-Cflags: -I${pkgincludedir}
387+Cflags:
388
389
390=== modified file 'support-files/libdrizzle-1.0.pc.in'
391--- support-files/libdrizzle-1.0.pc.in 2011-11-07 15:04:16 +0000
392+++ support-files/libdrizzle-1.0.pc.in 2012-04-17 06:13:20 +0000
393@@ -5,7 +5,7 @@
394
395 Name: libdrizzle-1.0
396 Description: Drizzle Protocol Library
397-Version: @PANDORA_RELEASE_VERSION@
398+Version: @LIBDRIZZLE_VERSION@
399 Libs: -L${libdir} -ldrizzle
400 URL: http://drizzle.org/
401-Cflags: -I$@includedir@/libdrizzle-1.0
402+Cflags: -I${includedir}
403
404=== modified file 'support-files/libdrizzle.pc.in'
405--- support-files/libdrizzle.pc.in 2011-11-07 15:04:16 +0000
406+++ support-files/libdrizzle.pc.in 2012-04-17 06:13:20 +0000
407@@ -5,7 +5,7 @@
408
409 Name: libdrizzle
410 Description: Drizzle Protocol Library
411-Version: @PANDORA_RELEASE_VERSION@
412+Version: @LIBDRIZZLE_VERSION@
413 Libs: -L${libdir} -ldrizzle
414 URL: http://drizzle.org/
415-Cflags: -I$@includedir@
416+Cflags: -I${includedir}

Subscribers

People subscribed via source and target branches

to all changes: