data_fabric 1.2.7 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +7 -0
- data/README.rdoc +9 -8
- data/Rakefile +9 -41
- data/TESTING.rdoc +3 -3
- data/example23/Rakefile +28 -27
- data/example23/config/environment.rb +4 -2
- data/example30/Gemfile +5 -0
- data/example30/Gemfile.lock +79 -0
- data/example30/README +256 -0
- data/example30/Rakefile +52 -0
- data/{example → example30}/app/controllers/accounts_controller.rb +0 -0
- data/{example/app/controllers/application.rb → example30/app/controllers/application_controller.rb} +0 -0
- data/{example → example30}/app/controllers/figments_controller.rb +0 -0
- data/example30/app/helpers/application_helper.rb +2 -0
- data/{example → example30}/app/models/account.rb +0 -0
- data/{example → example30}/app/models/figment.rb +0 -0
- data/{example → example30}/app/views/accounts/index.html.erb +2 -2
- data/{example → example30}/app/views/layouts/application.html.erb +0 -0
- data/example30/config.ru +4 -0
- data/example30/config/application.rb +42 -0
- data/example30/config/boot.rb +13 -0
- data/{example → example30}/config/database.yml +0 -0
- data/example30/config/environment.rb +5 -0
- data/example30/config/environments/development.rb +26 -0
- data/example30/config/environments/production.rb +49 -0
- data/example30/config/environments/test.rb +35 -0
- data/example30/config/initializers/backtrace_silencers.rb +7 -0
- data/{example → example30}/config/initializers/inflections.rb +2 -2
- data/{example → example30}/config/initializers/mime_types.rb +0 -0
- data/example30/config/initializers/secret_token.rb +7 -0
- data/example30/config/initializers/session_store.rb +8 -0
- data/example30/config/locales/en.yml +5 -0
- data/example30/config/routes.rb +65 -0
- data/example30/db/development.sqlite3 +0 -0
- data/{example → example30}/db/migrate/20080702154628_create_accounts.rb +0 -0
- data/{example → example30}/db/migrate/20080702154820_create_figments.rb +0 -0
- data/example30/db/s0_development.sqlite3 +0 -0
- data/example30/db/s0_test.sqlite3 +0 -0
- data/example30/db/s1_development.sqlite3 +0 -0
- data/example30/db/s1_test.sqlite3 +0 -0
- data/{example23 → example30}/db/schema.rb +7 -6
- data/example30/db/seeds.rb +7 -0
- data/example30/db/test.sqlite3 +0 -0
- data/example30/log/development.log +132 -0
- data/example30/log/test.log +444 -0
- data/example30/script/rails +6 -0
- data/{example → example30}/test/fixtures/accounts.yml +0 -0
- data/{example → example30}/test/functional/accounts_controller_test.rb +0 -0
- data/{example → example30}/test/integration/account_figments_test.rb +0 -0
- data/example30/test/performance/browsing_test.rb +9 -0
- data/example30/test/test_helper.rb +13 -0
- data/lib/data_fabric.rb +14 -21
- data/lib/data_fabric/{ar22.rb → connection_proxy.rb} +43 -63
- data/lib/data_fabric/extensions.rb +29 -0
- data/lib/data_fabric/version.rb +1 -1
- data/test/connection_test.rb +17 -12
- data/test/database_test.rb +3 -11
- data/test/test_helper.rb +3 -8
- data/test/thread_test.rb +0 -14
- data/test/vr_austin_master.db +0 -0
- data/test/vr_austin_slave.db +0 -0
- data/test/vr_dallas_master.db +0 -0
- data/test/vr_dallas_slave.db +0 -0
- metadata +72 -99
- data/example/Rakefile +0 -58
- data/example/app/helpers/accounts_helper.rb +0 -2
- data/example/app/helpers/application_helper.rb +0 -3
- data/example/app/helpers/figments_helper.rb +0 -2
- data/example/config/boot.rb +0 -109
- data/example/config/environment.rb +0 -67
- data/example/config/environments/development.rb +0 -17
- data/example/config/environments/production.rb +0 -22
- data/example/config/environments/test.rb +0 -22
- data/example/config/initializers/new_rails_defaults.rb +0 -15
- data/example/config/routes.rb +0 -45
- data/example/db/schema.rb +0 -28
- data/example/public/404.html +0 -30
- data/example/public/422.html +0 -30
- data/example/public/500.html +0 -30
- data/example/public/dispatch.cgi +0 -10
- data/example/public/dispatch.fcgi +0 -24
- data/example/public/dispatch.rb +0 -10
- data/example/public/favicon.ico +0 -0
- data/example/public/images/rails.png +0 -0
- data/example/public/robots.txt +0 -5
- data/example/script/about +0 -3
- data/example/script/console +0 -3
- data/example/script/dbconsole +0 -3
- data/example/script/destroy +0 -3
- data/example/script/generate +0 -3
- data/example/script/performance/benchmarker +0 -3
- data/example/script/performance/profiler +0 -3
- data/example/script/performance/request +0 -3
- data/example/script/plugin +0 -3
- data/example/script/process/inspector +0 -3
- data/example/script/process/reaper +0 -3
- data/example/script/process/spawner +0 -3
- data/example/script/runner +0 -3
- data/example/script/server +0 -3
- data/example/test/test_helper.rb +0 -41
- data/example23/db/development.sqlite3 +0 -0
- data/example23/db/s0_development.sqlite3 +0 -0
- data/example23/db/s0_test.sqlite3 +0 -0
- data/example23/db/s1_development.sqlite3 +0 -0
- data/example23/db/s1_test.sqlite3 +0 -0
- data/example23/db/test.sqlite3 +0 -0
- data/example23/log/development.log +0 -295
- data/example23/log/test.log +0 -551
- data/example23/vendor/plugins/data_fabric/init.rb +0 -3
- data/example23/vendor/plugins/data_fabric/lib/data_fabric.rb +0 -106
- data/example23/vendor/plugins/data_fabric/lib/data_fabric/ar20.rb +0 -133
- data/example23/vendor/plugins/data_fabric/lib/data_fabric/ar22.rb +0 -181
- data/example23/vendor/plugins/data_fabric/lib/data_fabric/dash.rb +0 -20
- data/example23/vendor/plugins/data_fabric/lib/data_fabric/version.rb +0 -7
- data/init.rb +0 -3
- data/lib/data_fabric/ar20.rb +0 -133
- data/lib/data_fabric/dash.rb +0 -20
- data/rails/init.rb +0 -1
data/init.rb
DELETED
data/lib/data_fabric/ar20.rb
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
module DataFabric
|
2
|
-
module Extensions
|
3
|
-
def self.included(model)
|
4
|
-
# Wire up ActiveRecord::Base
|
5
|
-
model.extend ClassMethods
|
6
|
-
end
|
7
|
-
|
8
|
-
# Class methods injected into ActiveRecord::Base
|
9
|
-
module ClassMethods
|
10
|
-
def data_fabric(options)
|
11
|
-
proxy = DataFabric::ConnectionProxy.new(self, options)
|
12
|
-
ActiveRecord::Base.active_connections[name] = proxy
|
13
|
-
|
14
|
-
raise ArgumentError, "data_fabric does not support ActiveRecord's allow_concurrency = true" if allow_concurrency
|
15
|
-
DataFabric.log { "Creating data_fabric proxy for class #{name}" }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class ConnectionProxy
|
21
|
-
def initialize(model_class, options)
|
22
|
-
@model_class = model_class
|
23
|
-
@replicated = options[:replicated]
|
24
|
-
@shard_group = options[:shard_by]
|
25
|
-
@prefix = options[:prefix]
|
26
|
-
@role = 'slave' if @replicated
|
27
|
-
|
28
|
-
@model_class.send :include, ActiveRecordConnectionMethods if @replicated
|
29
|
-
end
|
30
|
-
|
31
|
-
delegate :insert, :update, :delete, :create_table, :rename_table, :drop_table, :add_column, :remove_column,
|
32
|
-
:change_column, :change_column_default, :rename_column, :add_index, :remove_index, :initialize_schema_information,
|
33
|
-
:dump_schema_information, :execute, :execute_ignore_duplicate, :to => :master
|
34
|
-
|
35
|
-
delegate :insert_many, :to => :master # ar-extensions bulk insert support
|
36
|
-
|
37
|
-
def transaction(start_db_transaction = true, &block)
|
38
|
-
with_master { connection.transaction(start_db_transaction, &block) }
|
39
|
-
end
|
40
|
-
|
41
|
-
def method_missing(method, *args, &block)
|
42
|
-
DataFabric.log(Logger::DEBUG) { "Calling #{method} on #{connection}" }
|
43
|
-
connection.send(method, *args, &block)
|
44
|
-
end
|
45
|
-
|
46
|
-
def connection_name
|
47
|
-
connection_name_builder.join('_')
|
48
|
-
end
|
49
|
-
|
50
|
-
def disconnect!
|
51
|
-
if connected?
|
52
|
-
connection.disconnect!
|
53
|
-
cached_connections[connection_name] = nil
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def verify!(arg)
|
58
|
-
connection.verify!(arg) if connected?
|
59
|
-
end
|
60
|
-
|
61
|
-
def with_master
|
62
|
-
# Allow nesting of with_master.
|
63
|
-
old_role = @role
|
64
|
-
set_role('master')
|
65
|
-
yield
|
66
|
-
ensure
|
67
|
-
set_role(old_role)
|
68
|
-
end
|
69
|
-
|
70
|
-
private
|
71
|
-
|
72
|
-
def cached_connections
|
73
|
-
@cached_connections ||= {}
|
74
|
-
end
|
75
|
-
|
76
|
-
def connection_name_builder
|
77
|
-
@connection_name_builder ||= begin
|
78
|
-
clauses = []
|
79
|
-
clauses << @prefix if @prefix
|
80
|
-
clauses << @shard_group if @shard_group
|
81
|
-
clauses << StringProxy.new { DataFabric.active_shard(@shard_group) } if @shard_group
|
82
|
-
clauses << RAILS_ENV
|
83
|
-
clauses << StringProxy.new { @role } if @replicated
|
84
|
-
clauses
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def connection
|
89
|
-
name = connection_name
|
90
|
-
if not connected?
|
91
|
-
config = ActiveRecord::Base.configurations[name]
|
92
|
-
raise ArgumentError, "Unknown database config: #{name}, have #{ActiveRecord::Base.configurations.inspect}" unless config
|
93
|
-
DataFabric.log { "Connecting to #{name}" }
|
94
|
-
@model_class.establish_connection(config)
|
95
|
-
cached_connections[name] = @model_class.connection
|
96
|
-
@model_class.active_connections[@model_class.name] = self
|
97
|
-
end
|
98
|
-
cached_connections[name].verify!(3600)
|
99
|
-
cached_connections[name]
|
100
|
-
end
|
101
|
-
|
102
|
-
def connected?
|
103
|
-
DataFabric.shard_active_for?(@shard_group) and cached_connections[connection_name]
|
104
|
-
end
|
105
|
-
|
106
|
-
def set_role(role)
|
107
|
-
@role = role if @replicated
|
108
|
-
end
|
109
|
-
|
110
|
-
def master
|
111
|
-
with_master { return connection }
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
module ActiveRecordConnectionMethods
|
116
|
-
def self.included(base)
|
117
|
-
base.alias_method_chain :reload, :master
|
118
|
-
end
|
119
|
-
|
120
|
-
def reload_with_master(*args, &block)
|
121
|
-
connection.with_master { reload_without_master }
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
class StringProxy
|
126
|
-
def initialize(&block)
|
127
|
-
@proc = block
|
128
|
-
end
|
129
|
-
def to_s
|
130
|
-
@proc.call
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
data/lib/data_fabric/dash.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# A data_fabric recipe for use with the FiveRuns Dash metrics service at
|
2
|
-
# http://dash.fiveruns.com.
|
3
|
-
#
|
4
|
-
# Hook into your Rails application by adding the recipe in your
|
5
|
-
# config/initializers/dash.rb, like so:
|
6
|
-
#
|
7
|
-
# require 'data_fabric/dash'
|
8
|
-
# Fiveruns::Dash::Rails.start :production => 'your-token' do |config|
|
9
|
-
# config.add_recipe :data_fabric, :url => 'http://mikeperham.com'
|
10
|
-
# end
|
11
|
-
#
|
12
|
-
raise ArgumentError, "The Dash recipe for DataFabric is only supported on ActiveRecord 2.2 and greater" if ActiveRecord::VERSION::STRING < '2.2.0'
|
13
|
-
|
14
|
-
Fiveruns::Dash.register_recipe :data_fabric, :url => 'http://mikeperham.com' do |recipe|
|
15
|
-
recipe.absolute :open_connections, 'Open Connections' do
|
16
|
-
DataFabric::ConnectionProxy.shard_pools.values.map do |pool|
|
17
|
-
(pool.instance_variable_get(:@checked_out) || []).size
|
18
|
-
end.sum
|
19
|
-
end
|
20
|
-
end
|
data/rails/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
DataFabric.init
|