Skip to content

Commit

Permalink
Fixed the issue where connections weren't put back to pool on certain…
Browse files Browse the repository at this point in the history
… non-critical errors
  • Loading branch information
khaf committed May 30, 2015
1 parent f18731b commit f8c2da2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
7 changes: 6 additions & 1 deletion command.go
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,12 @@ func (cmd *baseCommand) execute(ifc command) (err error) {
// 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.
node.InvalidateConnection(cmd.conn)
if KeepConnection(err) {
// Put connection back in pool.
node.PutConnection(cmd.conn)
} else {
node.InvalidateConnection(cmd.conn)
}
return err
}

Expand Down
13 changes: 10 additions & 3 deletions types/result_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,15 @@ const (
)

// Should connection be put back into pool.
func KeepConnection(resultCode int) bool {
switch ResultCode(resultCode) {
case OK, // Exception did not originate on server.
func KeepConnection(err error) bool {
// if error is not an Aerospike Errors, Throw it away
ae, ok := err.(AerospikeError)
if !ok {
return false
}

switch ae.resultCode {
case 0, // Zero Value
QUERY_TERMINATED,
SCAN_TERMINATED,
INVALID_NODE_ERROR,
Expand All @@ -219,6 +225,7 @@ func KeepConnection(resultCode int) bool {
INDEX_OOM,
QUERY_ABORTED,
QUERY_TIMEOUT:

return false

default:
Expand Down

0 comments on commit f8c2da2

Please sign in to comment.