Skip to content

Commit cf05fa2

Browse files
committed
legacy servers with sharded clusters
1 parent 2953cfe commit cf05fa2

File tree

12 files changed

+780
-428
lines changed

12 files changed

+780
-428
lines changed

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ env:
77
- test=unit
88
- test=api
99
- test=cmd
10+
- test=legacy
1011

1112
script:
1213
case $test in
@@ -19,4 +20,7 @@ script:
1920
cmd)
2021
rake test:cmd
2122
;;
23+
legacy)
24+
rake test:legacy
25+
;;
2226
esac

Dockerfile

-2
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,3 @@ COPY *.gemspec .
2424
RUN bundle install
2525

2626
COPY . .
27-
28-
CMD bundle exec rspec -f Rfc::Aif

Dockerfile.legacy

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM ubuntu:precise
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
5+
RUN apt-get update
6+
# for apt-add-repository
7+
RUN apt-get install -y python-software-properties
8+
9+
# https://stackoverflow.com/questions/18490591/how-to-install-ruby-2-on-ubuntu-without-rvm
10+
RUN apt-add-repository ppa:brightbox/ruby-ng
11+
12+
RUN apt-get update
13+
RUN apt-get install -y ruby2.4 ruby2.4-dev make gcc curl libsnmp15 procps
14+
15+
RUN mkdir /opt/mongodb
16+
17+
RUN curl -fLo mongodb-linux-x86_64-enterprise-ubuntu1204-2.6.12.tgz \
18+
https://downloads.mongodb.com/linux/mongodb-linux-x86_64-enterprise-ubuntu1204-2.6.12.tgz
19+
RUN tar xf mongodb-linux-x86_64-enterprise-ubuntu1204-2.6.12.tgz
20+
RUN mv mongo*/ /opt/mongodb/2.6
21+
22+
ENV PATH=/opt/mongodb/2.6/bin:$PATH
23+
24+
RUN gem install bundler --no-document
25+
26+
COPY Gemfile .
27+
COPY *.gemspec .
28+
29+
RUN bundle install
30+
31+
COPY . .

Rakefile

+19-2
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,37 @@ task :build do
1515
run(%w(docker build -t mongo-manager .))
1616
end
1717

18+
namespace :build do
19+
task :legacy do
20+
run(%w(docker build -f Dockerfile.legacy -t mongo-manager-legacy .))
21+
end
22+
end
23+
1824
TEST_COMMAND = %w(docker run --tmpfs /db:exec --init -it mongo-manager).freeze
25+
LEGACY_TEST_COMMAND = %w(docker run --tmpfs /db:exec --init -it mongo-manager-legacy).freeze
1926

20-
task test: %w(test:unit test:api test:cmd)
27+
task test: %w(test:unit test:api test:cmd test:legacy)
2128

2229
namespace :test do
2330
task unit: :build do
2431
run(TEST_COMMAND + %w(rspec -f Rfc::Aif spec/mongo_manager))
2532
end
2633

2734
task api: :build do
28-
run(TEST_COMMAND + %w(rspec -f Rfc::Aif spec/integration/api))
35+
run(TEST_COMMAND + %w(rspec -f Rfc::Aif
36+
spec/integration/api/init_spec.rb
37+
spec/integration/api/init_modern_spec.rb
38+
))
2939
end
3040

3141
task cmd: :build do
3242
run(TEST_COMMAND + %w(rspec -f Rfc::Aif spec/integration/cmd))
3343
end
44+
45+
task legacy: 'build:legacy' do
46+
run(LEGACY_TEST_COMMAND + %w(rspec -f Rfc::Aif
47+
spec/integration/api/init_spec.rb
48+
spec/integration/api/init_legacy_spec.rb
49+
))
50+
end
3451
end

doc/internals.md

+6
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,9 @@ sort of a timeout for the other nodes. If any of the other nodes are still
8282
starting and are not yet available, `replSetInitiate` immediately fails.
8383
MM works around this by waiting for each node separately before trying to
8484
initiate the replica set.
85+
86+
## Sharded Clusters
87+
88+
MongoDB 2.6 requires that the config server is a standalone and not a
89+
replica set. mlaunch creates a standalone config server for MongoDB 3.2 and
90+
lower, and replica sets for MongoDB 3.4 and higher.

lib/mongo_manager/executor.rb

+36-21
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,8 @@ def read_config
129129
end
130130

131131
def init_standalone
132-
cmd = [
133-
mongo_path('mongod'),
134-
root_dir.join('mongod.log').to_s,
135-
root_dir.join('mongod.pid').to_s,
136-
'--dbpath', root_dir.to_s,
137-
'--port', base_port.to_s,
138-
] + server_tls_args + (options[:mongod_passthrough_args] || []) + passthrough_args
139-
Helper.spawn_mongo(*cmd)
140-
record_start_command(root_dir, cmd)
132+
dir = root_dir.join('standalone')
133+
spawn_standalone(dir, base_port, [])
141134

142135
if options[:username]
143136
client = Mongo::Client.new(["localhost:#{base_port}"],
@@ -148,12 +141,9 @@ def init_standalone
148141

149142
do_stop
150143

151-
cmd << '--auth'
152-
153-
Helper.spawn_mongo(*cmd)
144+
spawn_standalone(dir, base_port, %w(--auth))
154145
end
155146

156-
record_start_command(root_dir, cmd)
157147
write_config
158148
end
159149

@@ -202,14 +192,18 @@ def init_rs
202192
def init_sharded
203193
maybe_create_key
204194

205-
spawn_replica_set_node(
206-
root_dir.join('csrs'),
207-
base_port + num_mongos,
208-
'csrs',
209-
common_args + %w(--configsvr),
210-
)
195+
if config[:csrs]
196+
spawn_replica_set_node(
197+
root_dir.join('csrs'),
198+
base_port + num_mongos,
199+
'csrs',
200+
common_args + %w(--configsvr),
201+
)
211202

212-
initiate_replica_set(%W(localhost:#{base_port+num_mongos}), 'csrs', configsvr: true)
203+
initiate_replica_set(%W(localhost:#{base_port+num_mongos}), 'csrs', configsvr: true)
204+
else
205+
spawn_standalone(root_dir.join('csrs'), base_port + num_mongos, %w(--configsvr))
206+
end
213207

214208
shard_base_port = base_port + num_mongos + 1
215209

@@ -226,6 +220,12 @@ def init_sharded
226220
initiate_replica_set(%W(localhost:#{port}), shard_name)
227221
end
228222

223+
config_db_opt = if options[:csrs]
224+
"csrs/localhost:#{base_port+num_mongos}"
225+
else
226+
"localhost:#{base_port+num_mongos}"
227+
end
228+
229229
1.upto(num_mongos) do |mongos|
230230
port = base_port - 1 + mongos
231231
dir = root_dir.join('router%02d' % mongos)
@@ -236,7 +236,7 @@ def init_sharded
236236
dir.join('mongos.log').to_s,
237237
dir.join('mongos.pid').to_s,
238238
'--port', port.to_s,
239-
'--configdb', "csrs/localhost:#{base_port+num_mongos}",
239+
'--configdb', config_db_opt,
240240
] + server_tls_args + common_args +
241241
passthrough_args + (options[:mongos_passthrough_args] || [])
242242
Helper.spawn_mongo(*cmd)
@@ -422,6 +422,21 @@ def client_tls_options
422422
end.freeze
423423
end
424424

425+
def spawn_standalone(dir, port, args)
426+
puts("Spawn mongod on port #{port}")
427+
FileUtils.mkdir_p(dir)
428+
cmd = [
429+
mongo_path('mongod'),
430+
dir.join('mongod.log').to_s,
431+
dir.join('mongod.pid').to_s,
432+
'--dbpath', dir.to_s,
433+
'--port', port.to_s,
434+
] + args + server_tls_args +
435+
(options[:mongod_passthrough_args] || []) + passthrough_args
436+
Helper.spawn_mongo(*cmd)
437+
record_start_command(dir, cmd)
438+
end
439+
425440
def spawn_replica_set_node(dir, port, replica_set_name, args)
426441
puts("Spawn mongod on port #{port}")
427442
FileUtils.mkdir(dir)

lib/mongo_manager/main.rb

+7
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ def init(argv)
5757
options[:mongos] = v.to_i
5858
end
5959

60+
opts.on('--csrs NUM', Integer, 'Use a config server replica set with NUM nodes') do |v|
61+
unless v.to_i > 0
62+
usage("invalid --csrs value: #{v}")
63+
end
64+
options[:csrs] = v.to_i
65+
end
66+
6067
opts.on('--bin-dir DIR', String, 'Path to mongod/mongos binaries') do |v|
6168
options[:bin_dir] = v
6269
end

0 commit comments

Comments
 (0)