When using Aerospike clients in asynchrous mode it may be advantageous to clean up all outstanding calls during shutdown. What is the proper way to do this?
How you clean up outstanding calls depends upon whether the eventloop concerned is internal or external.
Internal eventloops are created by either
aerospike_close()on all active Aerospike instances from a non-eventloop thread. This means that the client blocks the current thread until active commands are complete on that Aerospike instance. If this is called from an eventloop thread, the client cannot block as it would deadlock the eventloop thread.
aerospike_destroy()on closed Aerospike instances.
as_event_close_loops()to send a close command signal to all event loops. The current thread will be blocked until all eventloops shut down. There is no need to call
as_event_destroy_loops()as it is called implicitly by
- There is no timeout on this and so the thread blocks until all internal eventloops complete.
External eventloops are created using
as_event_set_external_loop(). Use the following steps to shut them down.
aerospike_close()on all active Aerospike instances from a non-eventloop thread. This ensures that the client blocks the current thread until active commands are completed on the Aerospike instance concerned. As with internal eventloops, if an eventloop thread is used to do the close call, it deadlocks the eventloop.
aerospike_destroy()on the now-closed instances.
- Call a
as_event_close_loop()on each eventloop thread.
- Join on all external eventloop threads.
as_event_close_loop()fail if the close command can’t be sent to any event loop. If the close command can’t be pushed onto the event loop queue, the queue may be out of memory as it resizes after it reaches current capacity. This is considered unlikely, though it is possible.
- It is not recommended to retry
as_event_close_loops(). If the application runs out of memory resizing the queue, it is likely that this will cause an application crash.
- If there is a memory leak,
as_event_close_loops()will show up in any memory leak analysis.
EVENTLOOP CLOSE SHUTDOWN ASYNCHRONOUS