Commit a19f2eac authored by Wandenberg Peixoto's avatar Wandenberg Peixoto

fix to not lose shared memory content after reload the server changing the...

fix to not lose shared memory content after reload the server changing the shared memory size, has to do a reload to change the size
parent 79eb641f
...@@ -223,6 +223,7 @@ typedef struct { ...@@ -223,6 +223,7 @@ typedef struct {
ngx_int_t last_message_tag; ngx_int_t last_message_tag;
} ngx_http_push_stream_shm_data_t; } ngx_http_push_stream_shm_data_t;
ngx_uint_t ngx_http_push_stream_shm_size;
ngx_shm_zone_t *ngx_http_push_stream_shm_zone = NULL; ngx_shm_zone_t *ngx_http_push_stream_shm_zone = NULL;
ngx_http_push_stream_main_conf_t *ngx_http_push_stream_module_main_conf = NULL; ngx_http_push_stream_main_conf_t *ngx_http_push_stream_module_main_conf = NULL;
......
...@@ -27,6 +27,6 @@ ...@@ -27,6 +27,6 @@
#define NGX_HTTP_PUSH_STREAM_MODULE_VERSION_H_ #define NGX_HTTP_PUSH_STREAM_MODULE_VERSION_H_
static const ngx_str_t NGX_HTTP_PUSH_STREAM_TAG = ngx_string("0.3.4"); static const ngx_str_t NGX_HTTP_PUSH_STREAM_TAG = ngx_string("0.3.4");
static const ngx_str_t NGX_HTTP_PUSH_STREAM_COMMIT = ngx_string("baed4ca743e3da679f2ad90bdf02ac4444d72643"); static const ngx_str_t NGX_HTTP_PUSH_STREAM_COMMIT = ngx_string("79eb641fa567a24cd87603256cd7d03a19e45aeb");
#endif /* NGX_HTTP_PUSH_STREAM_MODULE_VERSION_H_ */ #endif /* NGX_HTTP_PUSH_STREAM_MODULE_VERSION_H_ */
...@@ -361,8 +361,11 @@ ngx_http_push_stream_postconfig(ngx_conf_t *cf) ...@@ -361,8 +361,11 @@ ngx_http_push_stream_postconfig(ngx_conf_t *cf)
ngx_conf_log_error(NGX_LOG_WARN, cf, 0, "The push_stream_shared_memory_size value must be at least %udKiB", shm_size_limit >> 10); ngx_conf_log_error(NGX_LOG_WARN, cf, 0, "The push_stream_shared_memory_size value must be at least %udKiB", shm_size_limit >> 10);
shm_size = shm_size_limit; shm_size = shm_size_limit;
} }
if (ngx_http_push_stream_shm_zone && ngx_http_push_stream_shm_zone->shm.size != shm_size) {
if (ngx_http_push_stream_shm_size && ngx_http_push_stream_shm_size != shm_size) {
ngx_conf_log_error(NGX_LOG_WARN, cf, 0, "Cannot change memory area size without restart, ignoring change"); ngx_conf_log_error(NGX_LOG_WARN, cf, 0, "Cannot change memory area size without restart, ignoring change");
} else {
ngx_http_push_stream_shm_size = shm_size;
} }
ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "Using %udKiB of shared memory for push stream module", shm_size >> 10); ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "Using %udKiB of shared memory for push stream module", shm_size >> 10);
...@@ -386,7 +389,7 @@ ngx_http_push_stream_postconfig(ngx_conf_t *cf) ...@@ -386,7 +389,7 @@ ngx_http_push_stream_postconfig(ngx_conf_t *cf)
*(aux + len) = '\0'; *(aux + len) = '\0';
} }
return ngx_http_push_stream_set_up_shm(cf, shm_size); return ngx_http_push_stream_set_up_shm(cf, ngx_http_push_stream_shm_size);
} }
......
...@@ -3,7 +3,7 @@ require File.expand_path('base_test_case', File.dirname(__FILE__)) ...@@ -3,7 +3,7 @@ require File.expand_path('base_test_case', File.dirname(__FILE__))
class TestSendSignals < Test::Unit::TestCase class TestSendSignals < Test::Unit::TestCase
include BaseTestCase include BaseTestCase
def config_test_send_hup_signal def global_configuration
ENV['NGINX_WORKERS'] = '1' ENV['NGINX_WORKERS'] = '1'
@memory_cleanup_timeout = '40s' @memory_cleanup_timeout = '40s'
@min_message_buffer_timeout = '60s' @min_message_buffer_timeout = '60s'
...@@ -107,4 +107,50 @@ class TestSendSignals < Test::Unit::TestCase ...@@ -107,4 +107,50 @@ class TestSendSignals < Test::Unit::TestCase
add_test_timeout(60) add_test_timeout(60)
} }
end end
def test_reload_with_different_shared_memory_size
headers = {'accept' => 'application/json'}
channel = 'ch_test_reload_with_different_shared_memory_size'
body = 'body'
EventMachine.run do
publish_message_inline(channel, headers, body)
# check statistics
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers, :timeout => 30
pub_1.callback do
assert_equal(200, pub_1.response_header.status, "Don't get channels statistics")
assert_not_equal(0, pub_1.response_header.content_length, "Don't received channels statistics")
resp_1 = JSON.parse(pub_1.response)
assert(resp_1.has_key?("channels"), "Didn't received the correct answer with channels info")
assert_equal(1, resp_1["channels"].to_i, "Didn't create channel")
assert_equal(1, resp_1["published_messages"].to_i, "Didn't create messages")
@max_reserved_memory = '20m'
create_config_file
# send reload signal
`#{ nginx_executable } -c #{ config_filename } -s reload > /dev/null 2>&1`
sleep 5
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers, :timeout => 30
pub_2.callback do
assert_equal(200, pub_2.response_header.status, "Don't get channels statistics")
assert_not_equal(0, pub_2.response_header.content_length, "Don't received channels statistics")
resp_2 = JSON.parse(pub_2.response)
assert(resp_2.has_key?("channels"), "Didn't received the correct answer with channels info")
assert_equal(1, resp_2["channels"].to_i, "Didn't create channel")
assert_equal(1, resp_2["published_messages"].to_i, "Didn't create messages")
error_log = File.read(@main_error_log)
assert(error_log.include?("Cannot change memory area size without restart, ignoring change"), "Didn't log error message")
EventMachine.stop
end
end
add_test_timeout(10)
end
end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment