xbar 0.0.1 → 0.4.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.
Files changed (80) hide show
  1. data/Appraisals +25 -0
  2. data/README.mkdn +215 -0
  3. data/Rakefile +337 -1
  4. data/examples/README +5 -0
  5. data/examples/config/simple.json +22 -0
  6. data/examples/example1.rb +34 -0
  7. data/examples/migrations/1_create_users.rb +10 -0
  8. data/examples/setup.rb +43 -0
  9. data/gemfiles/rails3.gemfile +8 -0
  10. data/gemfiles/rails3.gemfile.lock +74 -0
  11. data/gemfiles/rails31.gemfile +8 -0
  12. data/gemfiles/rails31.gemfile.lock +83 -0
  13. data/gemfiles/rails32.gemfile +7 -0
  14. data/gemfiles/rails32.gemfile.lock +117 -0
  15. data/gemfiles/rails4.gemfile +9 -0
  16. data/gemfiles/rails4.gemfile.lock +134 -0
  17. data/lib/migrations/1_create_usage_statistics.rb +23 -0
  18. data/lib/xbar/association.rb +49 -0
  19. data/lib/xbar/association_collection.rb +69 -0
  20. data/lib/xbar/colors.rb +32 -0
  21. data/lib/xbar/has_and_belongs_to_many_association.rb +17 -0
  22. data/lib/xbar/logger.rb +14 -0
  23. data/lib/xbar/mapper.rb +304 -0
  24. data/lib/xbar/migration.rb +76 -0
  25. data/lib/xbar/model.rb +165 -0
  26. data/lib/xbar/proxy.rb +249 -0
  27. data/lib/xbar/rails2/association.rb +133 -0
  28. data/lib/xbar/rails2/persistence.rb +39 -0
  29. data/lib/xbar/rails3/arel.rb +13 -0
  30. data/lib/xbar/rails3/association.rb +112 -0
  31. data/lib/xbar/rails3/persistence.rb +37 -0
  32. data/lib/xbar/rails3.1/singular_association.rb +34 -0
  33. data/lib/xbar/scope_proxy.rb +55 -0
  34. data/lib/xbar/shard.rb +95 -0
  35. data/lib/xbar/version.rb +2 -2
  36. data/lib/xbar.rb +121 -2
  37. data/run +27 -0
  38. data/spec/config/acme.json +53 -0
  39. data/spec/config/connection.rb +2 -0
  40. data/spec/config/default.json +160 -0
  41. data/spec/config/duplicate_shard.json +21 -0
  42. data/spec/config/missing_key.json +20 -0
  43. data/spec/config/new_shards.json +29 -0
  44. data/spec/config/no_master_shard.json +19 -0
  45. data/spec/config/not_entire_sharded.json +23 -0
  46. data/spec/config/octopus.json +27 -0
  47. data/spec/config/octopus_rails.json +25 -0
  48. data/spec/config/production_fully_replicated.json +21 -0
  49. data/spec/config/production_raise_error.json +17 -0
  50. data/spec/config/simple.json +22 -0
  51. data/spec/config/single_adapter.json +20 -0
  52. data/spec/console.rb +15 -0
  53. data/spec/migrations/10_create_users_using_replication.rb +12 -0
  54. data/spec/migrations/11_add_field_in_all_slaves.rb +11 -0
  55. data/spec/migrations/12_create_users_using_block.rb +23 -0
  56. data/spec/migrations/13_create_users_using_block_and_using.rb +15 -0
  57. data/spec/migrations/1_create_users_on_master.rb +9 -0
  58. data/spec/migrations/2_create_users_on_canada.rb +11 -0
  59. data/spec/migrations/3_create_users_on_both_shards.rb +11 -0
  60. data/spec/migrations/4_create_users_on_shards_of_a_group.rb +11 -0
  61. data/spec/migrations/5_create_users_on_multiples_groups.rb +11 -0
  62. data/spec/migrations/6_raise_exception_with_invalid_shard_name.rb +11 -0
  63. data/spec/migrations/7_raise_exception_with_invalid_multiple_shard_names.rb +11 -0
  64. data/spec/migrations/8_raise_exception_with_invalid_group_name.rb +11 -0
  65. data/spec/migrations/9_raise_exception_with_multiple_invalid_group_names.rb +11 -0
  66. data/spec/spec_helper.rb +25 -0
  67. data/spec/support/database_models.rb +78 -0
  68. data/spec/support/xbar_helper.rb +42 -0
  69. data/spec/xbar/association_spec.rb +660 -0
  70. data/spec/xbar/controller_spec.rb +40 -0
  71. data/spec/xbar/logger_spec.rb +22 -0
  72. data/spec/xbar/mapper_spec.rb +283 -0
  73. data/spec/xbar/migration_spec.rb +110 -0
  74. data/spec/xbar/model_spec.rb +434 -0
  75. data/spec/xbar/proxy_spec.rb +124 -0
  76. data/spec/xbar/replication_spec.rb +94 -0
  77. data/spec/xbar/scope_proxy_spec.rb +22 -0
  78. data/spec/xbar/shard_spec.rb +36 -0
  79. data/xbar.gemspec +13 -3
  80. metadata +231 -10
data/lib/xbar/shard.rb ADDED
@@ -0,0 +1,95 @@
1
+ # For debugging.
2
+ require File.expand_path(File.join(File.dirname(__FILE__), 'colors'))
3
+
4
+ module XBar
5
+ class Shard
6
+ include Colors
7
+
8
+ # Methods that we invoke on the proxy.
9
+ [:current_model, :in_block_scope?].each do |meth|
10
+ define_method(meth) {@proxy.send(meth)}
11
+ end
12
+
13
+ attr_reader :shard_name, :master, :proxy, :slaves
14
+
15
+ def initialize(proxy, name, master, slaves)
16
+ @master = master # a connection pool
17
+ @shard_name = name
18
+ @slaves = slaves # an array of connection pools
19
+ @proxy = proxy # our parent proxy
20
+ @slave_index = 0
21
+ end
22
+
23
+ def run_queries(method, *args, &block)
24
+ if XBar.debug
25
+ puts("Shard##{BLUE_TEXT}run_queries#{RESET_COLORS}: " +
26
+ "method = #{RED_TEXT}#{method}#{RESET_COLORS}, " +
27
+ "shard= #{shard_name}, " +
28
+ "block_scope = #{in_block_scope?}")
29
+ end
30
+ if method.to_s =~ /select/ && !in_block_scope? # XXX needed???, eventual flag??
31
+ # OK to send the query to a slave
32
+ run_queries_on_slave(method, *args, &block)
33
+ else
34
+ # Use the master.
35
+ run_queries_on_replica(master, method, *args, &block)
36
+ end
37
+ end
38
+
39
+ def transaction(options, &block)
40
+ if XBar.debug
41
+ config = master.spec.config
42
+ puts("\nShard##{BLUE_TEXT}transaction#{RESET_COLORS}: " +
43
+ "shard_name=master, shard=#{shard_name}, " +
44
+ "Host=#{config[:host]}, Port=#{config[:port]}, Database=#{config[:database]}")
45
+ end
46
+ proxy.enter_statistics(@shard_name, master.spec.config, 'transaction')
47
+ prepare_connection_pool(master)
48
+ master.connection.transaction(options, &block)
49
+ end
50
+
51
+ def schema_cache
52
+ # defined by attr_reader in AbstractAdapter class.
53
+ master.connection.schema_cache
54
+ end
55
+
56
+ def quote_table_name(table_name)
57
+ master.connection.quote_table_name(table_name)
58
+ end
59
+
60
+ private
61
+
62
+ def prepare_connection_pool(pool)
63
+ pool.automatic_reconnect = true if XBar.rails31?
64
+ pool.verify_active_connections! if Mapper.options[:verify_connection]
65
+ end
66
+
67
+ def run_queries_on_replica(replica, method, *args, &block)
68
+ if XBar.debug
69
+ config = replica.spec.config
70
+ puts("Shard##{BLUE_TEXT}run_queries_on_replica#{RESET_COLORS}: " +
71
+ "shard_name=#{shard_name}, " +
72
+ "Host=#{config[:host]}, Port=#{config[:port]}, " +
73
+ "Database=#{config[:database]}")
74
+ end
75
+ # proxy.enter_statistics(@shard_name, replica.spec.config, method) changes the shard
76
+ prepare_connection_pool(replica)
77
+ replica.connection.send(method, *args, &block)
78
+ end
79
+
80
+ def run_queries_on_slave(method, *args, &block)
81
+ if current_model.unreplicated_model? || @slaves.empty?
82
+ replica = @master
83
+ else
84
+ if XBar.debug
85
+ puts "Shard##{BLUE_TEXT}run_queries_on_slave#{RESET_COLORS}: " +
86
+ "slave_index=#{@slave_index}"
87
+ end
88
+ replica = @slaves[@slave_index]
89
+ @slave_index = (@slave_index + 1) % @slaves.length
90
+ end
91
+ run_queries_on_replica(replica, method, *args, &block) # return sql
92
+ end
93
+
94
+ end
95
+ end
data/lib/xbar/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- module Xbar
2
- VERSION = "0.0.1"
1
+ module XBar
2
+ VERSION = '0.4.0'
3
3
  end
data/lib/xbar.rb CHANGED
@@ -1,5 +1,124 @@
1
+ if ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR < 2
2
+ require 'active_support/core_ext/class/inheritable_attributes' # Removed in Rails 3.2.beta
3
+ else
4
+ require 'active_support/core_ext/class/attribute' # maybe not needed
5
+ ActiveRecord::Base.send(:class_attribute, :_unreplicated,
6
+ :_establish_connection, :_reset_table_name)
7
+ end
8
+
9
+ require "yaml"
10
+ require "erb"
11
+ require 'active_support/hash_with_indifferent_access'
12
+
13
+ module XBar
14
+
15
+ class ConfigError < StandardError; end
16
+
17
+ class << self
18
+ attr_accessor :debug
19
+ end
20
+
21
+ # There is no corresponding 'setter' method because this is not
22
+ # how the Rails environment is set.
23
+ def self.rails_env
24
+ defined?(Rails) ? Rails.env.to_s : nil
25
+ end
26
+
27
+ def self.config
28
+ XBar::Mapper.config
29
+ end
30
+
31
+ # Returns the Rails.root_to_s when you are using rails
32
+ # Running the current directory in a generic Ruby process
33
+ def self.directory
34
+ @directory ||= defined?(Rails) ? Rails.root.to_s : Dir.pwd
35
+ end
36
+
37
+ def self.directory=(dir)
38
+ @directory = dir
39
+ end
40
+
41
+ def self.enable_stats
42
+ @stats = true
43
+ end
44
+
45
+ def self.disable_stats
46
+ @stats = false
47
+ end
48
+
49
+ def self.collect_stats?
50
+ @stats ||= false
51
+ end
52
+
53
+ # This is the default way to do XBar Setup
54
+
55
+ def self.setup
56
+ yield self
57
+ end
58
+
59
+ def self.environments=(environments)
60
+ @environments = environments.map { |element| element.to_s }
61
+ end
62
+
63
+ def self.environments
64
+ @environments || ['production', 'test', 'development']
65
+ end
66
+
67
+ def self.rails3?
68
+ ActiveRecord::VERSION::MAJOR == 3
69
+ end
70
+
71
+ def self.rails31?
72
+ ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR >= 1
73
+ end
74
+
75
+ def self.rails32?
76
+ ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR >= 2
77
+ end
78
+
79
+ def self.rails?
80
+ defined?(Rails)
81
+ end
82
+
83
+ def self.shards=(shards)
84
+ XBar::Mapper.shards = shards
85
+ end
86
+
87
+ def self.using(shard, &block)
88
+ conn = ActiveRecord::Base.connection
89
+ if conn.is_a?(XBar::Proxy)
90
+ conn.run_queries_on_shard(shard, &block)
91
+ else
92
+ yield
93
+ end
94
+ end
95
+ end
96
+
1
97
  require "xbar/version"
98
+ require "xbar/mapper"
99
+ require "xbar/model"
100
+ require "xbar/migration"
101
+ require "xbar/association_collection"
102
+ require "xbar/has_and_belongs_to_many_association"
103
+ require "xbar/association"
2
104
 
3
- module Xbar
4
- # Your code goes here...
105
+ if XBar.rails3?
106
+ require "xbar/rails3/association"
107
+ require "xbar/rails3/persistence"
108
+ require "xbar/rails3/arel"
109
+ else
110
+ require "xbar/rails2/association"
111
+ require "xbar/rails2/persistence"
5
112
  end
113
+
114
+ if XBar.rails31?
115
+ require "xbar/rails3.1/singular_association"
116
+ end
117
+
118
+ require "xbar/shard"
119
+ require "xbar/proxy"
120
+ require "xbar/scope_proxy"
121
+ require "xbar/logger"
122
+
123
+ ActiveRecord::Base.send(:include, XBar::Model)
124
+ class XBarModel < ActiveRecord::Base; end; # used only in migrations
data/run ADDED
@@ -0,0 +1,27 @@
1
+ #!/bin/bash
2
+ #RUBY=/usr/local/rvm/rubies/ruby-1.9.3-p0/bin/ruby
3
+ RDEBUG=/usr/local/rvm/gems/ruby-1.9.3-p0@edge/bin/rdebug
4
+ RSPEC=/usr/local/rvm/gems/ruby-1.9.3-p0@edge/bin/rspec
5
+ SPEC_DIR="spec/xbar"
6
+
7
+ export BUNDLE_GEMFILE=/Volumes/Opt/projects/xbar/gemfiles/rails32.gemfile
8
+
9
+ SPEC=$1
10
+ LINE=$2
11
+
12
+ if [ -n "$SPEC" ]
13
+ then
14
+ TEST="$SPEC_DIR/${SPEC}_spec.rb"
15
+ else
16
+ echo "run.sh spec [line]"
17
+ exit 1
18
+ fi
19
+
20
+ if [ -n "$LINE" ]
21
+ then
22
+ TEST="${TEST}:${LINE}"
23
+ fi
24
+
25
+ echo $TEST
26
+
27
+ bundle exec ${RUBY} ${RSPEC} -fd -c ${TEST}
@@ -0,0 +1,53 @@
1
+ {
2
+ "__COMMENT": "Acme Corporation Environments",
3
+
4
+ "connections": {
5
+ "mysql_m": "mysql2://root@localhost:3306/master",
6
+
7
+ "inventory_1": "postgres://postgres@127.0.0.1/russia_1",
8
+ "inventory_2": "postgres://postgres@127.0.0.1/russia_2",
9
+ "inventory_3": "postgres://postgres@127.0.0.1/russia_3",
10
+
11
+ "sales_1": "mysql2://root:graceling@deimos.thirdmode.com:3307/canada",
12
+ "sales_2": "mysql2://root:graceling@deimos.thirdmode.com:3308/canada",
13
+ "sales_3": "mysql2://root:graceling@deimos.thirdmode.com:3309/canada",
14
+
15
+ "common_1": "mysql2://root:graceling@deimos.thirdmode.com:3307/brazil",
16
+ "common_2": "mysql2://root:graceling@deimos.thirdmode.com:3308/brazil",
17
+ "common_3": "mysql2://root:graceling@deimos.thirdmode.com:3309/brazil"
18
+ },
19
+
20
+ "environments": {
21
+ "test": {
22
+ "shards": {
23
+ "master": "mysql_m",
24
+ "sales": "sales_1",
25
+ "inventory": "inventory_1",
26
+ "common": ["common_1", "common_2", "common_3"]
27
+ }
28
+ },
29
+ "development": {
30
+ "shards": {
31
+ "master": "mysql_m",
32
+ "sales": "sales_2",
33
+ "inventory": "inventory_2",
34
+ "common": ["common_1", "common_2", "common_3"]
35
+ }
36
+ },
37
+ "production": {
38
+ "shards": {
39
+ "master": "mysql_m",
40
+ "sales": "sales_3",
41
+ "inventory": "inventory_3",
42
+ "common": ["common_1", "common_2", "common_3"]
43
+ }
44
+ },
45
+ "staging": {
46
+ "shards": {
47
+ "master": "mysql_m",
48
+ "inventory": "inventory_3",
49
+ "common": ["common_1", "common_2", "common_3"]
50
+ }
51
+ }
52
+ }
53
+ }
@@ -0,0 +1,2 @@
1
+ ActiveRecord::Base.establish_connection(:adapter => "mysql2", :database => "master",
2
+ :host => "localhost", :port => 3306, :username => "root", :password => "")
@@ -0,0 +1,160 @@
1
+ {
2
+ "__COMMENT": "Shards for the default meta-environment.",
3
+
4
+ "connections": {
5
+ "mysql_m": "mysql2://root@localhost:3306/master",
6
+ "rogue_s": "mysql2://root@localhost:3306/rogue",
7
+ "london_s": "mysql2://root:graceling@deimos.thirdmode.com:3307/london",
8
+ "moscow_s": "postgres://postgres@127.0.0.1/moscow",
9
+ "paris_s": { "adapter": "sqlite3", "database": "/tmp/paris.sqlite3"},
10
+
11
+ "russia_1": "postgres://postgres@127.0.0.1/russia_1",
12
+ "russia_2": "postgres://postgres@127.0.0.1/russia_2",
13
+ "russia_3": "postgres://postgres@127.0.0.1/russia_3",
14
+
15
+ "canada_1": "mysql2://root:graceling@deimos.thirdmode.com:3307/canada",
16
+ "canada_2": "mysql2://root:graceling@deimos.thirdmode.com:3308/canada",
17
+ "canada_3": "mysql2://root:graceling@deimos.thirdmode.com:3309/canada",
18
+
19
+ "brazil_1": "mysql2://root:graceling@deimos.thirdmode.com:3307/brazil",
20
+ "brazil_2": "mysql2://root:graceling@deimos.thirdmode.com:3308/brazil",
21
+ "brazil_3": "mysql2://root:graceling@deimos.thirdmode.com:3309/brazil",
22
+
23
+ "__COMMENT": "The china database is setup in the MySQL configuration",
24
+ "__COMMENT": "to NOT be replicated.",
25
+ "china_1": "mysql2://root:graceling@deimos.thirdmode.com:3307/china",
26
+ "china_2": "mysql2://root:graceling@deimos.thirdmode.com:3308/china"
27
+ },
28
+
29
+ "environments": {
30
+ "test": {
31
+ "any_option": true,
32
+ "shards": {
33
+ "master": "mysql_m",
34
+
35
+ "__COMMENT": "MySQL singleton shard.",
36
+ "london": "london_s",
37
+
38
+ "__COMMENT": "SQLite singleton shard.",
39
+ "paris": "paris_s",
40
+
41
+ "__COMMENT": "Postgres singleton shard.",
42
+ "moscow": "moscow_s",
43
+
44
+ "__COMMENT": "Postgres unreplicated shard (for now)",
45
+ "__COMMENT": "One server has three different databases.",
46
+ "russia": ["russia_1", "russia_2", "russia_3"],
47
+
48
+ "__COMMENT": "Convenience to get at the shard replicas as shards.",
49
+ "russia_east": "russia_1",
50
+ "russia_central": "russia_2",
51
+ "russia_west": "russia_3",
52
+
53
+ "__COMMENT": "MySQL Fully replicated shard",
54
+ "canada": ["canada_1", "canada_2", "canada_3"],
55
+
56
+ "__COMMENT": "Convenience to get at the shard replicas as shards.",
57
+ "canada_east": "canada_1",
58
+ "canada_central": "canada_2",
59
+ "canada_west": "canada_3",
60
+
61
+ "__COMMENT": "MySQL fully relicated shard",
62
+ "brazil": ["brazil_1", "brazil_2", "brazil_3"],
63
+
64
+ "__COMMENT": "MySQL unreplicated shard",
65
+ "china": ["china_1", "china_2"],
66
+
67
+ "__COMMENT": "Convenience to get at the shard replicas as shards.",
68
+ "__COMMENT": "Two different servers have the same-named database.",
69
+ "china_east": "china_1",
70
+ "china_west": "china_2"
71
+ }
72
+ },
73
+ "development": {
74
+ "verify_connection": true,
75
+ "favorite_color": "blue",
76
+ "shards": {
77
+ "master": "mysql_m",
78
+
79
+ "__COMMENT": "MySQL singleton shard.",
80
+ "london": "london_s",
81
+
82
+ "__COMMENT": "SQLite singleton shard.",
83
+ "paris": "paris_s",
84
+
85
+ "__COMMENT": "Postgres singleton shard.",
86
+ "moscow": "moscow_s",
87
+
88
+ "__COMMENT": "Postgres unreplicated shard (for now)",
89
+ "__COMMENT": "One server has three different databases.",
90
+ "russia": ["russia_1", "russia_2", "russia_3"],
91
+
92
+ "__COMMENT": "Convenience to get at the shard replicas as shards.",
93
+ "russia_east": "russia_1",
94
+ "russia_central": "russia_2",
95
+ "russia_west": "russia_3",
96
+
97
+ "__COMMENT": "MySQL Fully replicated shard",
98
+ "canada": ["canada_1", "canada_2", "canada_3"],
99
+
100
+ "__COMMENT": "Convenience to get at the shard replicas as shards.",
101
+ "canada_east": "canada_1",
102
+ "canada_central": "canada_2",
103
+ "canada_west": "canada_3",
104
+
105
+ "__COMMENT": "MySQL fully relicated shard",
106
+ "brazil": ["brazil_1", "brazil_2", "brazil_3"],
107
+
108
+ "__COMMENT": "MySQL unreplicated shard",
109
+ "china": ["china_1", "china_2"],
110
+
111
+ "__COMMENT": "Convenience to get at the shard replicas as shards.",
112
+ "__COMMENT": "Two different servers have the same-named database.",
113
+ "china_east": "china_1",
114
+ "china_west": "china_2"
115
+ }
116
+ },
117
+ "staging": {
118
+ "shards": {
119
+ "master": "mysql_m",
120
+
121
+ "__COMMENT": "MySQL singleton shard.",
122
+ "london": "london_s",
123
+
124
+ "__COMMENT": "SQLite singleton shard.",
125
+ "paris": "paris_s",
126
+
127
+ "__COMMENT": "Postgres singleton shard.",
128
+ "moscow": "moscow_s",
129
+
130
+ "__COMMENT": "Postgres unreplicated shard (for now)",
131
+ "__COMMENT": "One server has three different databases.",
132
+ "russia": ["russia_1", "russia_2", "russia_3"],
133
+
134
+ "__COMMENT": "Convenience to get at the shard replicas as shards.",
135
+ "russia_east": "russia_1",
136
+ "russia_central": "russia_2",
137
+ "russia_west": "russia_3",
138
+
139
+ "__COMMENT": "MySQL Fully replicated shard",
140
+ "canada": ["canada_1", "canada_2", "canada_3"],
141
+
142
+ "__COMMENT": "Convenience to get at the shard replicas as shards.",
143
+ "canada_east": "canada_1",
144
+ "canada_central": "canada_2",
145
+ "canada_west": "canada_3",
146
+
147
+ "__COMMENT": "MySQL fully relicated shard",
148
+ "brazil": ["brazil_1", "brazil_2", "brazil_3"],
149
+
150
+ "__COMMENT": "MySQL unreplicated shard",
151
+ "china": ["china_1", "china_2"],
152
+
153
+ "__COMMENT": "Convenience to get at the shard replicas as shards.",
154
+ "__COMMENT": "Two different servers have the same-named database.",
155
+ "china_east": "china_1",
156
+ "china_west": "china_2"
157
+ }
158
+ }
159
+ }
160
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "__COMMENT": "Acme Corporation Environments with a duplicate shard error",
3
+
4
+ "connections": {
5
+ "mysql_m": "mysql2://root@localhost:3306/master",
6
+ "inventory_1": "postgres://postgres@127.0.0.1/russia_1",
7
+ "inventory_2": "postgres://postgres@127.0.0.1/russia_2",
8
+ "sales_1": "mysql2://root:graceling@deimos.thirdmode.com:3307/canada"
9
+ },
10
+
11
+ "environments": {
12
+ "test": {
13
+ "shards": {
14
+ "master": "mysql_m",
15
+ "sales": "sales_1",
16
+ "inventory": "inventory_1",
17
+ "inventory": "inventory_2"
18
+ }
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "__COMMENT": "Acme Corporation Environments with a missing key error",
3
+
4
+ "connections": {
5
+ "mysql_m": "mysql2://root@localhost:3306/master",
6
+ "inventory_1": "postgres://postgres@127.0.0.1/russia_1",
7
+ "inventory_2": "postgres://postgres@127.0.0.1/russia_2",
8
+ "sales_1": "mysql2://root:graceling@deimos.thirdmode.com:3307/canada"
9
+ },
10
+
11
+ "environments": {
12
+ "test": {
13
+ "shards": {
14
+ "master": "mysql_m",
15
+ "sales": "sales_1",
16
+ "inventory": "inventory_3"
17
+ }
18
+ }
19
+ }
20
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "connections": {
3
+ "p1": "postgres://user:password@alpha.server.com:5432/mydatabase?encoding=unicode&pool=5",
4
+ "p2": "postgres://user:password@beta.server.com:5432/mydatabase?encoding=unicode&pool=5",
5
+ "m1": "mysql://user:password@alpha.server.com:3306/mydatabase?pool=10",
6
+ "m2": "postgres://user:password@beta.server.com:3306/mydatabase?pool=10",
7
+ "m3": {"database": "xbar_shard5", "adapter": "mysql2", "host": "localhost" }
8
+ },
9
+ "environments": {
10
+ "development": {
11
+ "shards": [
12
+ {"name": "shard_one", "connections": ["p1", "p2"]},
13
+ {"name": "shard_one", "connections": ["p1", "p2"]}
14
+ ]
15
+ },
16
+ "test": {
17
+ "shards": [
18
+ {"name": "shard_one", "connections": ["p1", "p2"]},
19
+ {"name": "shard_one", "connections": ["p1", "p2"]}
20
+ ]
21
+ },
22
+ "production": {
23
+ "shards": [
24
+ {"name": "shard_one", "connections": ["p1", "p2"]},
25
+ {"name": "shard_one", "connections": ["p1", "p2"]}
26
+ ]
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "__COMMENT": "Acme Corporation Environments with a duplicate shard error",
3
+
4
+ "connections": {
5
+ "mysql_m": "mysql2://root@localhost:3306/master",
6
+ "inventory_1": "postgres://postgres@127.0.0.1/russia_1",
7
+ "inventory_2": "postgres://postgres@127.0.0.1/russia_2",
8
+ "sales_1": "mysql2://root:graceling@deimos.thirdmode.com:3307/canada"
9
+ },
10
+
11
+ "environments": {
12
+ "test": {
13
+ "shards": {
14
+ "sales": "sales_1",
15
+ "inventory": ["inventory_1", "inventory_2"]
16
+ }
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "__COMMENT": "Not Entire Sharded",
3
+
4
+ "entire_sharded": false,
5
+
6
+ "connections": {
7
+ "europe": {"database": "xbar_shard2", "adapter": "mysql2", "host": "localhost"},
8
+ "canada": {"database": "xbar_shard3", "adapter": "mysql2", "host": "localhost"},
9
+ "brazil": {"database": "xbar_shard4", "adapter": "mysql2", "host": "localhost"},
10
+ "russia": {"database": "xbar_shard5", "adapter": "mysql2", "host": "localhost"}
11
+ },
12
+
13
+ "environments": {
14
+ "shards": {
15
+ "shards": {
16
+ "europe": "europe",
17
+ "canada": "canada",
18
+ "brazil": "brazil",
19
+ "russia": "russia"
20
+ }
21
+ }
22
+ }
23
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "__COMMENT": "Shards for the XBar meta-environment.",
3
+
4
+ "connections": {
5
+ "alone_shard": "mysql2://localhost/xbar_shard5",
6
+ "aug2009": {"database": "xbar_shard2", "adapter": "mysql2", "host": "localhost"},
7
+ "aug2010": {"database": "xbar_shard3", "adapter": "mysql2", "host": "localhost"},
8
+ "aug2011": {"database": "xbar_shard4", "adapter": "mysql2", "host": "localhost"},
9
+ "postgresql_shard": {"adapter": "postgresql", "username": "postgres", "password": null,
10
+ "database": "xbar_shard1", "encoding": "unicode"},
11
+ "sqlite_shard": { "adapter": "sqlite3", "database": "/tmp/database.sqlite3"},
12
+ "canada": "mysql2://localhost/xbar_shard2",
13
+ "brazil": {"database": "xbar_shard3", "adapter": "mysql2", "host": "localhost"},
14
+ "russia": {"database": "xbar_shard4", "adapter": "mysql2", "host": "localhost"}
15
+ },
16
+ "environments": {
17
+ "shards": {
18
+ "shards": {
19
+ "alone_shard": "alone_shard",
20
+ "postgresql_shard": "postgresql_shard",
21
+ "sqlite_shard": "sqlite_shard",
22
+ "history_shard": ["aug2009", "aug2010", "aug2011"],
23
+ "country_shard": ["canada", "brazil", "russia"]
24
+ }
25
+ }
26
+ }
27
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "__COMMENT": "XBar Rails Mapperuration",
3
+ "replicated": true,
4
+ "verify_connection": true,
5
+ "connections": {
6
+ "slave1": {"database": "xbar_shard2", "adapter": "mysql2", "host": "localhost"},
7
+ "slave2": {"database": "xbar_shard3", "adapter": "mysql2", "host": "localhost"},
8
+ "slave3": {"database": "xbar_shard4", "adapter": "mysql2", "host": "localhost"},
9
+ "slave4": {"database": "xbar_shard5", "adapter": "mysql2", "host": "localhost"}
10
+ },
11
+ "environments": {
12
+ "staging": {
13
+ "shards": {
14
+ "slave1": "slave1",
15
+ "slave2": "slave2"
16
+ }
17
+ },
18
+ "production": {
19
+ "shards": {
20
+ "slave3": "slave3",
21
+ "slave4": "slave4"
22
+ }
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "__COMMENT": "Production Fully Replicated",
3
+ "replicated": true,
4
+ "connections": {
5
+ "slave1": {"database": "xbar_shard2", "adapter": "mysql2", "host": "localhost"},
6
+ "slave2": {"database": "xbar_shard3", "adapter": "mysql2", "host": "localhost"},
7
+ "slave3": {"database": "xbar_shard4", "adapter": "mysql2", "host": "localhost"},
8
+ "slave4": {"database": "xbar_shard5", "adapter": "mysql2", "host": "localhost"}
9
+ },
10
+
11
+ "environments": {
12
+ "shards": {
13
+ "shards": {
14
+ "slave1": "slave1",
15
+ "slave2": "slave2",
16
+ "slave3": "slave3",
17
+ "slave4": "slave4"
18
+ }
19
+ }
20
+ }
21
+ }