mysql2 0.2.18-x86-mingw32 → 0.3.9-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,132 +0,0 @@
1
- # Necessary monkeypatching to make AR fiber-friendly.
2
-
3
- module ActiveRecord
4
- module ConnectionAdapters
5
-
6
- def self.fiber_pools
7
- @fiber_pools ||= []
8
- end
9
- def self.register_fiber_pool(fp)
10
- fiber_pools << fp
11
- end
12
-
13
- class FiberedMonitor
14
- class Queue
15
- def initialize
16
- @queue = []
17
- end
18
-
19
- def wait(timeout)
20
- t = timeout || 5
21
- fiber = Fiber.current
22
- x = EM::Timer.new(t) do
23
- @queue.delete(fiber)
24
- fiber.resume(false)
25
- end
26
- @queue << fiber
27
- Fiber.yield.tap do
28
- x.cancel
29
- end
30
- end
31
-
32
- def signal
33
- fiber = @queue.pop
34
- fiber.resume(true) if fiber
35
- end
36
- end
37
-
38
- def synchronize
39
- yield
40
- end
41
-
42
- def new_cond
43
- Queue.new
44
- end
45
- end
46
-
47
- # ActiveRecord's connection pool is based on threads. Since we are working
48
- # with EM and a single thread, multiple fiber design, we need to provide
49
- # our own connection pool that keys off of Fiber.current so that different
50
- # fibers running in the same thread don't try to use the same connection.
51
- class ConnectionPool
52
- def initialize(spec)
53
- @spec = spec
54
-
55
- # The cache of reserved connections mapped to threads
56
- @reserved_connections = {}
57
-
58
- # The mutex used to synchronize pool access
59
- @connection_mutex = FiberedMonitor.new
60
- @queue = @connection_mutex.new_cond
61
-
62
- # default 5 second timeout unless on ruby 1.9
63
- @timeout = spec.config[:wait_timeout] || 5
64
-
65
- # default max pool size to 5
66
- @size = (spec.config[:pool] && spec.config[:pool].to_i) || 5
67
-
68
- @connections = []
69
- @checked_out = []
70
- @automatic_reconnect = true
71
- @tables = {}
72
-
73
- @columns = Hash.new do |h, table_name|
74
- h[table_name] = with_connection do |conn|
75
-
76
- # Fetch a list of columns
77
- conn.columns(table_name, "#{table_name} Columns").tap do |columns|
78
-
79
- # set primary key information
80
- columns.each do |column|
81
- column.primary = column.name == primary_keys[table_name]
82
- end
83
- end
84
- end
85
- end
86
-
87
- @columns_hash = Hash.new do |h, table_name|
88
- h[table_name] = Hash[columns[table_name].map { |col|
89
- [col.name, col]
90
- }]
91
- end
92
-
93
- @primary_keys = Hash.new do |h, table_name|
94
- h[table_name] = with_connection do |conn|
95
- table_exists?(table_name) ? conn.primary_key(table_name) : 'id'
96
- end
97
- end
98
- end
99
-
100
- def clear_stale_cached_connections!
101
- cache = @reserved_connections
102
- keys = Set.new(cache.keys)
103
-
104
- ActiveRecord::ConnectionAdapters.fiber_pools.each do |pool|
105
- pool.busy_fibers.each_pair do |object_id, fiber|
106
- keys.delete(object_id)
107
- end
108
- end
109
-
110
- keys.each do |key|
111
- next unless cache.has_key?(key)
112
- checkin cache[key]
113
- cache.delete(key)
114
- end
115
- end
116
-
117
- private
118
-
119
- def current_connection_id #:nodoc:
120
- Fiber.current.object_id
121
- end
122
-
123
- def checkout_and_verify(c)
124
- @checked_out << c
125
- c.run_callbacks :checkout
126
- c.verify!
127
- c
128
- end
129
- end
130
-
131
- end
132
- end
@@ -1,11 +0,0 @@
1
- module Arel
2
- module SqlCompiler
3
- class Mysql2Compiler < GenericCompiler
4
- def limited_update_conditions(conditions, taken)
5
- conditions << " LIMIT #{taken}"
6
- conditions
7
- end
8
- end
9
- end
10
- end
11
-
@@ -1,31 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'mysql2/em'
4
- require 'fiber'
5
-
6
- module Mysql2
7
- module EM
8
- module Fiber
9
- class Client < ::Mysql2::EM::Client
10
- def query(sql, opts={})
11
- if ::EM.reactor_running?
12
- deferable = super(sql, opts)
13
-
14
- fiber = ::Fiber.current
15
- deferable.callback do |result|
16
- fiber.resume(result)
17
- end
18
- deferable.errback do |err|
19
- fiber.resume(err)
20
- end
21
- ::Fiber.yield.tap do |result|
22
- raise result if result.is_a?(::Exception)
23
- end
24
- else
25
- super(sql, opts)
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,22 +0,0 @@
1
- # encoding: UTF-8
2
- if defined? EventMachine && defined? Fiber
3
- require 'spec_helper'
4
- require 'mysql2/em_fiber'
5
-
6
- describe Mysql2::EM::Fiber::Client do
7
- it 'should support queries' do
8
- results = []
9
- EM.run do
10
- Fiber.new {
11
- client1 = Mysql2::EM::Fiber::Client.new
12
- results = client1.query "SELECT sleep(0.1) as first_query"
13
- EM.stop_event_loop
14
- }.resume
15
- end
16
-
17
- results.first.keys.should include("first_query")
18
- end
19
- end
20
- else
21
- puts "Either EventMachine or Fibers not available. Skipping tests that use them."
22
- end