-
Notifications
You must be signed in to change notification settings - Fork 40
[Client-618] max connections enforced #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: stage
Are you sure you want to change the base?
Changes from all commits
1898ac8
a0755cb
d20be60
05e2a92
b2379f2
f89032b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ Gem::Specification.new do |s| | |
s.name = "aerospike" | ||
s.version = Aerospike::VERSION | ||
s.platform = Gem::Platform::RUBY | ||
s.authors = [ "Khosrow Afroozeh", "Jan Hecking" ] | ||
s.authors = ["Khosrow Afroozeh", "Jan Hecking", "Sachin Venkatesha Murthy"] | ||
s.email = [ "[email protected]", "[email protected]" ] | ||
s.homepage = "http://www.github.com/aerospike/aerospike-client-ruby" | ||
s.summary = "An Aerospike driver for Ruby." | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -345,14 +345,13 @@ def execute_command(cluster, policy) | |
timeout = 1 | ||
timeout = policy.timeout if policy && policy.timeout > 0 | ||
|
||
conn = node.get_connection(timeout) | ||
|
||
begin | ||
conn = node.get_connection(timeout) | ||
conn.write(@data_buffer, @data_offset) | ||
conn.read(@data_buffer, HEADER_SIZE) | ||
node.put_connection(conn) | ||
rescue => e | ||
conn.close if conn | ||
node.close_connection(conn) if conn | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The better design should be adding a |
||
raise e | ||
end | ||
|
||
|
@@ -377,13 +376,11 @@ def read_users(cluster, policy) | |
status, list = read_user_blocks(conn) | ||
node.put_connection(conn) | ||
rescue => e | ||
conn.close if conn | ||
node.close_connection(conn) if conn | ||
raise e | ||
end | ||
|
||
raise Exceptions::Aerospike.new(status) if status > 0 | ||
|
||
return list | ||
list | ||
end | ||
|
||
def read_user_blocks(conn) | ||
|
@@ -512,13 +509,13 @@ def read_roles(cluster, policy) | |
status, list = read_role_blocks(conn) | ||
node.put_connection(conn) | ||
rescue => e | ||
conn.close if conn | ||
node.close_connection(conn) if conn | ||
raise e | ||
end | ||
|
||
raise Exceptions::Aerospike.new(status) if status > 0 | ||
|
||
return list | ||
list | ||
end | ||
|
||
def read_role_blocks(conn) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -487,6 +487,9 @@ def execute | |
@node = get_node | ||
@conn = @node.get_connection(@policy.timeout) | ||
rescue => e | ||
if e.is_a?(Aerospike::Exceptions::MaxConnectionsExceeded) | ||
Aerospike.logger.error("Maximum connections established. No new connection can be created. #{e}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same issue. Logging without re-raising the exception. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still not addressed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have not re-raised exception here as there is a retry loop here |
||
end | ||
if @node | ||
# Socket connection error has occurred. Decrease health and retry. | ||
@node.decrease_health | ||
|
@@ -510,7 +513,7 @@ def execute | |
|
||
# All runtime exceptions are considered fatal. Do not retry. | ||
# Close socket to flush out possible garbage. Do not put back in pool. | ||
@conn.close if @conn | ||
@node.close_connection(@conn) if @conn | ||
raise e | ||
end | ||
|
||
|
@@ -523,7 +526,7 @@ def execute | |
rescue => e | ||
# IO errors are considered temporary anomalies. Retry. | ||
# Close socket to flush out possible garbage. Do not put back in pool. | ||
@conn.close if @conn | ||
@node.close_connection(@conn) if @conn | ||
|
||
Aerospike.logger.error("Node #{@node.to_s}: #{e}") | ||
# IO error means connection to server @node is unhealthy. | ||
|
@@ -548,7 +551,7 @@ def execute | |
# cancelling/closing the batch/multi commands will return an error, which will | ||
# close the connection to throw away its data and signal the server about the | ||
# situation. We will not put back the connection in the buffer. | ||
@conn.close if @conn | ||
@node.close_connection(@conn) if @conn | ||
raise e | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,14 +84,14 @@ def get_connection(timeout) | |
# Put back a connection to the cache. If cache is full, the connection will be | ||
# closed and discarded | ||
def put_connection(conn) | ||
conn.close if !active? | ||
@connections.cleanup(conn) unless active? | ||
@connections.offer(conn) | ||
end | ||
|
||
# Separate connection for refreshing | ||
def tend_connection | ||
if @tend_connection.nil? || @tend_connection.closed? | ||
@tend_connection = Cluster::CreateConnection.(cluster, host) | ||
@tend_connection = @connections.create | ||
end | ||
@tend_connection | ||
end | ||
|
@@ -177,7 +177,7 @@ def aliases | |
@aliases.value | ||
end | ||
|
||
# Marks node as inactice and closes all cached connections | ||
# Marks node as inactive and closes all cached connections | ||
def close | ||
inactive! | ||
close_connections | ||
|
@@ -224,14 +224,18 @@ def refresh_reset | |
Node::Refresh::Reset.(self) | ||
end | ||
|
||
def close_connection(conn) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed if the suggested changes are applied. |
||
@connections.cleanup(conn) | ||
end | ||
|
||
private | ||
|
||
def close_connections | ||
@tend_connection.close if @tend_connection | ||
@connections.cleanup(@tend_connection) if @tend_connection | ||
# drain connections and close all of them | ||
# non-blocking, does not call create_block when passed false | ||
while conn = @connections.poll(false) | ||
conn.close if conn | ||
while (conn = @connections.poll(create_new: false)) | ||
@connections.cleanup(conn) | ||
end | ||
end | ||
end # class Node | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,4 +101,4 @@ def is_ip?(hostname) | |
end | ||
|
||
end # class | ||
end # module | ||
end # module |
Uh oh!
There was an error while loading. Please reload this page.