Commit Graph

111 Commits

Author SHA1 Message Date
Eric Wong
8e81dcb053 retry connect if interrupted by signals
The MySQL client libraries normally retry system calls when
interrupted by signals.  The lone exception I've found is in the
(infrequent) connection setup where it'll propagate the
connect(2) syscall error all the way back up to the caller.
Fortunately inspection of the MySQL client library reveals it
properly preserves the global "errno" variable even with
debugging enabled.

Note that the net.last_errno member does NOT correspond to the
system "errno".
2010-08-19 15:55:32 -07:00
Eric Wong
8bfbfa2708 fix signal handling when waiting on queries
This reverts the single-threaded select() optimization from
commits 9a63a587c0 and
0190457dbd.

Under Ruby 1.9, the reverted optimization caused signal handlers
to be delayed until the socket became readable.

Under Ruby 1.8, matters are worse as receiving a signal during
select() causes Errno::EINTR to be raised.

There is now a (somewhat fragile) spec for testing signal
handling during a "SELECT sleep(2)" query.

Furthermore, the performance difference I measured on
benchmark/thread_alone.rb was negligible (over 1000 iterations)
between the two:

Ruby 1.8.7-p249
  Rehearsal ----------------------------------------------------
  select             0.040000   0.020000   0.060000 (  0.119448)
  rb_thread_select   0.050000   0.020000   0.070000 (  0.132091)
  ------------------------------------------- total: 0.130000sec

                         user     system      total        real
  select             0.030000   0.030000   0.060000 (  0.116471)
  rb_thread_select   0.050000   0.020000   0.070000 (  0.119874)

Ruby 1.9.2-p0
  Rehearsal ----------------------------------------------------
  select             0.050000   0.030000   0.080000 (  0.134208)
  rb_thread_select   0.080000   0.000000   0.080000 (  0.141316)
  ------------------------------------------- total: 0.160000sec

                         user     system      total        real
  select             0.050000   0.020000   0.070000 (  0.123325)
  rb_thread_select   0.060000   0.010000   0.070000 (  0.124075)

Benchmarks were performed on an _empty_ mysql2_test table to
maximize the relative time for the select(2)-related code path
(vs reading data).  The test was run on Debian Lenny, x86_64 and
a stock 2.6.35.2 Linux kernel.  Hardware was a Core2 Duo @
1.6GHz with the performance CPU governor while on AC power
to eliminate CPU speed fluctuations during the test.
2010-08-18 20:13:13 -07:00
Brian Lopez
cebf9af068 Wrap the MYSQL* again so we can:
1) let mysql_init/mysql_close take care of any/all allocation, thread state and freeing
2) for faster access to the encoding and active state variables for the connection
2010-08-16 02:03:19 -07:00
Lourens Naudé
2609783aeb Avoid INT2NUM overhead when coercing date specific elements for MYSQL_TYPE_TIME + introduce basic infrastructure for measuring GC overhead 2010-08-11 11:25:20 -07:00
Lourens Naudé
d9153b82fc Save on coercion overhead for zero value decimal and float column values 2010-08-11 11:25:20 -07:00
Lourens Naudé
c808e78028 Intern error_number= && sql_state= as well 2010-08-11 11:25:20 -07:00
Lourens Naudé
9a63a587c0 Declare the selector function pointer as per ISO C90 spec + address brian's concern / comment re. rb_thread_alone() 2010-08-11 11:25:20 -07:00
Lourens Naudé
0190457dbd Skip rb_thread_select overhead if we're running in single threaded mode 2010-08-11 11:25:20 -07:00
Lourens Naudé
80810f7e43 Extract a GET_CLIENT mactro to cleanup inline Data_Get_Struct etc. on methods that require client access 2010-08-11 11:25:20 -07:00
Lourens Naudé
f601c3cef8 Skip additional string length access in rb_mysql_client_escape and benchmark escaping "clean" strings as well 2010-08-11 11:25:20 -07:00
Lourens Naudé
931765ee05 Extract a GET_ENCODING macro 2010-08-11 11:25:20 -07:00
Luis Lavena
4c27a1e4fc extconf detect properly mingw. 2010-08-12 02:19:04 +08:00
Brian Lopez
5a9ca9c76f app_timezone defaults to nil 2010-08-09 14:50:58 -07:00
Brian Lopez
b448b98146 move -Wextra to development flags area 2010-08-06 11:19:34 -07:00
Brian Lopez
99af726a58 application_timezone is allowed to be nil 2010-08-06 00:01:09 -07:00
Brian Lopez
ad34357e57 convert :timezone option into two new ones
:database_timezone - the timezone (:utc or :local) Mysql2 will assume time/datetime fields are stored in the db. This modifies what initial timezone your Time objects will be in when creating them from libmysql in C
and
:application_timezone - the timezone (:utc or :local) you'd finally like the Time objects converted to before you get them
2010-08-05 22:50:45 -07:00
Brian Lopez
2514fafa53 add :cast_booleans option for automatically casting tinyint(1) fields into true/false for ruby 2010-08-05 00:39:11 -07:00
Brian Lopez
12c022c8aa move most previously global symbols to static to prevent conflicts (thanks for catching this Eric) 2010-08-04 19:32:14 -07:00
Brian Lopez
2bb8721e84 respect :symbolize_keys option for Mysql2::Result#fields if it's called before the first row is built 2010-08-04 00:54:05 -07:00
Brian Lopez
c0cf2f13a0 let's try that again - libmysql only allows one query be sent at a time per connection, bail early if that's attempted 2010-08-03 20:37:49 -07:00
Brian Lopez
1a70e83a74 Revert "libmysql only allows one query be sent at a time per connection, bail early if that's attempted"
This reverts commit 3ff7baa5f8.
2010-08-03 20:22:44 -07:00
Brian Lopez
3ff7baa5f8 libmysql only allows one query be sent at a time per connection, bail early if that's attempted 2010-08-03 20:21:51 -07:00
Brian Lopez
94ae2a781d no need to carry over options twice as we're already doing it up in rb_mysql_client_async_result 2010-08-03 19:04:30 -07:00
Brian Lopez
fc6c24a20c add support for configuring which timezone Time objects should be created in 2010-08-02 01:20:03 -07:00
Brian Lopez
6142336e59 use a default (year 2000) for TIME field casting to a Time object, like AR does 2010-08-01 20:23:27 -07:00
Brian Lopez
36c243be71 Add cascading options hash at Mysql2::Client.default_query_options, which can be overridden by passing options to Mysql2::Client#query and/or Mysql2::Result#each
Tune up specs, benchmarks and AR adapter to conform
2010-08-01 20:20:48 -07:00
Brian Lopez
c6230c3cec pluck out Mysql2::Client definition into it's own c/h file 2010-07-29 23:25:15 -07:00
Brian Lopez
dd138de8e1 invalidate the file descriptor on close 2010-07-28 11:31:32 -07:00
Brian Lopez
cd1a2bf9ff Revert "force reconnect behavior to true, remove open connection checks since libmysql will handle this for us now"
This reverts commit 70a7298dc3.
2010-07-21 12:13:27 -07:00
Brian Lopez
70a7298dc3 force reconnect behavior to true, remove open connection checks since libmysql will handle this for us now 2010-07-21 11:47:16 -07:00
Brian Lopez
9ab1c90d2b don't raise exception on close, for a closed connection 2010-07-20 09:12:47 -07:00
Brian Lopez
edb742fee7 check for and support field-level encodings
raise an exception for invalid encodings passed to Mysql2::Client#new
2010-07-10 23:15:54 -07:00
Brian Lopez
d8f5f4de1d on second thought, we should make sure we were given a string earlier on 2010-07-10 10:32:46 -07:00
Brian Lopez
645b9a1bef no need to Check_Type in these spots since we're using StringValuePtr as well 2010-07-09 09:59:48 -07:00
Brian Lopez
ab032b99db make sure the query string is converted to the connection's encoding before it's handed to libmysql 2010-07-08 22:51:19 -07:00
Brian Lopez
e385e7cf6b Initial refactor of encoding support to ensure we map Ruby encodings to MySQL encodings properly. 2010-07-08 22:22:20 -07:00
Aaron Patterson
c38525d11a extracting Mysql2::Result class to be inside result.c 2010-07-06 14:21:58 -07:00
Aaron Patterson
a6b1247ede partial implementation of result in Ruby 2010-07-06 13:16:49 -07:00
Aaron Patterson
74e99bae5f refactoring initialize to be done in ruby, adding setter methods for connection options 2010-07-04 19:29:12 -07:00
Aaron Patterson
e7b43a8c41 StringValuePtr() will automatically do Check_Type() for us 2010-07-02 09:58:46 -07:00
Aaron Patterson
ff55ef5c87 remove mysql2_client_wrapper struct, refactor open connection requirement to a macro 2010-07-01 10:01:19 -07:00
Aaron Patterson
8c96aa1fcd refactoring C to use the allocate function 2010-07-01 09:15:52 -07:00
Aaron Patterson
6ef738200d moving the error class to ruby 2010-06-30 10:10:59 -07:00
Aaron Patterson
0b36eae450 moving requires to the .rb files 2010-06-30 09:36:42 -07:00
Aaron Patterson
3468f12a83 small refactor of extconf.rb 2010-06-30 08:53:34 +08:00
Aaron Patterson
04b9fe17cc made extension more rake-compiler friendly, made the spec task depend on "compile" 2010-06-30 08:20:42 +08:00
Brian Lopez
fdf3e53933 add Mysql2::Client#fields method 2010-06-19 16:24:02 -07:00
Brian Lopez
d033823b3c respect Encoding.default_internal for strings returned by Mysql2::Client#info and Mysql2::Client#server_info 2010-06-14 18:14:28 -07:00
Brian Lopez
6751a98873 use Encoding.default_internal 2010-06-13 15:50:03 -07:00
Brian Lopez
bd3c39f819 formatting 2010-06-11 08:51:55 -07:00