Timeout exception from single-key get v/s multi-key get


#1

I am referring to these methods in the Java client Single-key get: Record com.aerospike.client.AerospikeClient.get(Policy policy, Key key) Multi-key get: Record[] com.aerospike.client.AerospikeClient.get(BatchPolicy policy, Key[] keys)

When I use the single-key method, if Aerospike can’t get the record for whatever reason (typically a timeout), the method throws AerospikeException. This is good for me. I want to know via an exception if the read failed.

Now when I use the multi-key method with 2 keys, it seems that the behavior is that if aerospike fails to read one key (for similar reasons as above), but can successfully read another key, it does not throw AerospikeException. Rather, it returns the key that was read. This is bad for me. If read failed for any key, I want to know about about it, and take a different action.

Is there a way I can get multiple keys in one call and still know if any of the reads failed? Or any workaround?

Thank you!


#2

An exception will be thrown if the timeout for the entire batch is reached. If one record is not found, null will be stored for that record[] entry.

Iterate through the returned records and check for null. If one record entry is null (not found), abort the batch.