db-charmer 1.6.1 → 1.6.2
Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
1.6.2 (2010-04-03):
|
2
|
+
|
3
|
+
Bugfix release: Modified our stub connection used on sharded models to fail on db-calling
|
4
|
+
methods only. Proxy the rest to a real shard connection. Another bug fixed in db_block_map
|
5
|
+
sharding method: we didn't increment block counters when assigning blocks to shards.
|
6
|
+
|
7
|
+
----------------------------------------------------------------------------------------
|
1
8
|
1.6.1 (2010-03-31):
|
2
9
|
|
3
10
|
Breaking change from now on all connection-switching methods (both in migrations and in
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.6.
|
1
|
+
1.6.2
|
data/db-charmer.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{db-charmer}
|
8
|
-
s.version = "1.6.
|
8
|
+
s.version = "1.6.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Alexey Kovyrin"]
|
12
|
-
s.date = %q{2010-03
|
12
|
+
s.date = %q{2010-04-03}
|
13
13
|
s.description = %q{ActiveRecord Connections Magic (slaves, multiple connections, etc)}
|
14
14
|
s.email = %q{alexey@kovyrin.net}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -69,11 +69,12 @@ module DbCharmer
|
|
69
69
|
@@db_charmer_database_remappings = Hash.new
|
70
70
|
def db_charmer_remapped_connection
|
71
71
|
return nil if (db_charmer_connection_level || 0) > 0
|
72
|
-
name =
|
73
|
-
|
72
|
+
name = :master
|
73
|
+
proxy = db_charmer_connection_proxy
|
74
|
+
name = proxy.db_charmer_connection_name.to_sym if proxy
|
74
75
|
|
75
76
|
remapped = @@db_charmer_database_remappings[name]
|
76
|
-
|
77
|
+
remapped ? DbCharmer::ConnectionFactory.connect(remapped, true) : nil
|
77
78
|
end
|
78
79
|
|
79
80
|
def db_charmer_database_remappings
|
@@ -18,7 +18,7 @@ module DbCharmer
|
|
18
18
|
return conn.db_charmer_connection_proxy
|
19
19
|
end
|
20
20
|
|
21
|
-
if conn.kind_of?(ActiveRecord::ConnectionAdapters::AbstractAdapter)
|
21
|
+
if conn.kind_of?(ActiveRecord::ConnectionAdapters::AbstractAdapter) || conn.kind_of?(DbCharmer::StubConnection)
|
22
22
|
return conn
|
23
23
|
end
|
24
24
|
|
@@ -26,7 +26,13 @@ module DbCharmer
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def switch_connection_to(conn, require_config_to_exist = true)
|
29
|
-
|
29
|
+
new_conn = coerce_to_connection_proxy(conn, require_config_to_exist)
|
30
|
+
|
31
|
+
if db_charmer_connection_proxy.is_a?(DbCharmer::StubConnection)
|
32
|
+
db_charmer_connection_proxy.set_real_connection(new_conn)
|
33
|
+
end
|
34
|
+
|
35
|
+
self.db_charmer_connection_proxy = new_conn
|
30
36
|
self.hijack_connection!
|
31
37
|
end
|
32
38
|
end
|
@@ -104,6 +104,9 @@ module DbCharmer
|
|
104
104
|
SQL
|
105
105
|
connection.execute(sql, "Allocate new block")
|
106
106
|
|
107
|
+
# Increment the blocks counter on the shard
|
108
|
+
ShardInfo.update_counters(shard.id, :blocks_count => +1)
|
109
|
+
|
107
110
|
# Retry block search after creation
|
108
111
|
block_for_key(key)
|
109
112
|
end
|
@@ -1,9 +1,28 @@
|
|
1
|
+
# This is a simple proxy class used as a default connection on sharded models
|
2
|
+
#
|
3
|
+
# The idea is to proxy all utility method calls to a real connection (set by
|
4
|
+
# the +set_real_connection+ method when we switch shards) and fail on real
|
5
|
+
# database querying calls forcing users to switch shard connections.
|
6
|
+
#
|
1
7
|
module DbCharmer
|
2
|
-
class StubConnection
|
3
|
-
def
|
8
|
+
class StubConnection
|
9
|
+
def set_real_connection(real_conn)
|
10
|
+
@real_conn = real_conn
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_missing(meth, *args, &block)
|
14
|
+
# Fail on database statements
|
15
|
+
if ActiveRecord::ConnectionAdapters::DatabaseStatements.instance_methods.member?(meth.to_s)
|
16
|
+
raise ActiveRecord::ConnectionNotEstablished, "You have to switch connection on your model before using it!"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Fail if no connection has been established yet
|
20
|
+
unless @real_conn
|
21
|
+
raise ActiveRecord::ConnectionNotEstablished, "No real connection to proxy this method to!"
|
22
|
+
end
|
4
23
|
|
5
|
-
|
6
|
-
|
24
|
+
# Proxy the call to our real connection target
|
25
|
+
@real_conn.__send__(meth, *args, &block)
|
7
26
|
end
|
8
27
|
end
|
9
28
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 6
|
8
|
-
-
|
9
|
-
version: 1.6.
|
8
|
+
- 2
|
9
|
+
version: 1.6.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Alexey Kovyrin
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03
|
17
|
+
date: 2010-04-03 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|