Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Shouldn't cleanup a redis instance when timeout to start it in node i…

…nitialization

Change-Id: I726459f0c8db3fe8b7af249589a36c054a02854d
  • Loading branch information...
commit f54bf75721d4c95b1945a937e6d093aef19a581c 1 parent 8cf0c4a
@tangr1 tangr1 authored
Showing with 47 additions and 24 deletions.
  1. +46 −23 redis/lib/redis_service/redis_node.rb
  2. +1 −1  redis/spec/node_spec.rb
View
69 redis/lib/redis_service/redis_node.rb
@@ -297,16 +297,10 @@ def start_provisioned_instances
next
end
begin
- pid = start_instance(instance)
- instance.pid = pid
+ instance.pid = start_provisioned_instance(instance)
save_instance(instance)
rescue => e
@logger.warn("Error starting instance #{instance.name}: #{e}")
- begin
- cleanup_instance(instance)
- rescue => e2
- # Ignore the rollback exception
- end
end
end
end
@@ -336,22 +330,7 @@ def start_instance(instance, db_file = nil)
@logger.debug("Service #{instance.name} started with pid #{pid}")
# In parent, detch the child
Process.detach(pid)
- # Wait enough time for the redis server starting
- redis = Redis.new({:port => instance.port, :password => instance.password})
- (@redis_start_timeout * 10).times do
- begin
- redis.echo("")
- return pid
- rescue => e
- sleep 0.1
- next
- ensure
- begin
- redis.quit if redis
- rescue => e
- end
- end
- end
+ return pid if wait_service_start(instance)
@logger.error("Timeout to start redis server for instance #{instance.name}")
# Stop the instance if it is running
instance.pid = pid
@@ -394,6 +373,50 @@ def start_instance(instance, db_file = nil)
raise RedisError.new(RedisError::REDIS_START_INSTANCE_FAILED, instance.inspect)
end
+ def start_provisioned_instance(instance)
+ @logger.debug("Starting: #{instance.inspect} on port #{instance.port}")
+
+ pid = fork
+ if pid
+ @logger.debug("Service #{instance.name} started with pid #{pid}")
+ # In parent, detch the child
+ Process.detach(pid)
+ # Just record a timeout error here, the instance could finish starting eventually,
+ # or the node will report error in varz details
+ @logger.error("Timeout to start redis server for instance #{instance.name}") unless wait_service_start(instance)
+ return pid
+ else
+ $0 = "Starting Redis instance: #{instance.name}"
+ close_fds
+
+ dir = instance_dir(instance.name)
+ config_path = File.join(dir, "redis.conf")
+ exec("#{@redis_server_path} #{config_path}")
+ end
+ rescue => e
+ raise RedisError.new(RedisError::REDIS_START_INSTANCE_FAILED, instance.inspect)
+ end
+
+ def wait_service_start(instance)
+ # Wait enough time for the redis server starting
+ redis = Redis.new({:port => instance.port, :password => instance.password})
+ (@redis_start_timeout * 10).times do
+ begin
+ redis.echo("")
+ return true
+ rescue => e
+ sleep 0.1
+ next
+ ensure
+ begin
+ redis.quit if redis
+ rescue => e
+ end
+ end
+ end
+ false
+ end
+
def stop_instance(instance)
stop_redis_server(instance)
EM.defer do
View
2  redis/spec/node_spec.rb
@@ -122,7 +122,7 @@ class Node
@instance.pid = @node.start_instance(@instance)
@instance.plan = 1
@instance.save
- @node.stop_instance(@instance)
+ @node.stop_redis_server(@instance)
sleep 1
@node.start_provisioned_instances
sleep 1
Please sign in to comment.
Something went wrong with that request. Please try again.