Hi i would like to understand the difference between the case when in java client we see Error code 2 for KEY NOT FOUND and when we get null record
While using the Aerospike Java client, I am observing two different behaviors:
- The get() call completes successfully, but the returned Record object is null.
- The get() call throws an AerospikeException with result code 2 (KEY_NOT_FOUND), indicating that the key digest was not found.
like for sync get call in aerospike java client ` /**
- Read record header and bins for specified key.
- The policy can be used to specify timeouts.
- @param policy generic configuration parameters, pass in null for defaults
- @param key unique record identifier
- @param binNames bins to retrieve
- @return if found, return record instance. If not found, return null.
- @throws AerospikeException if read fails */ public final Record get(Policy policy, Key key, String... binNames)
`
wanted to understand when records can be null and when we would get Aerospike Exception with error code 2?
Aerospike client version: aerospike-client-jdk21:9.0.5 Aerospike Server version: 6.0.3
Activity
3So batch call throws a Aerospike Exception with error code 2 when Keys is not found
couple of doubts
- will sync single get call wont throw Aerospike Exception with error code 2 in any case?
- if the batch call sets record as null with aerospike exception with error code 2, in that case the record wont be used anyways right, as onFailure() will be triggered in ReadListener, can you suggest a used case where setting record as null is usedfull when error code is 2
-
That is my understanding of the code. Do you have an example where this is not the case?
-
The batch call does not set nor throw an exception on KEY_NOT_FOUND. It just sets the corresponding resultCode to KEY_NOT_FOUND and continues processing. In async batch, onFailure() is not called on KEY_NOT_FOUND or any other server returned resultCode. onFailure() is only called on connectivity errors (like timeout or socket errors) or client parse errors (triggered by data corruption).
Instead, on onSuccess() is called with a status of false which indicates that the server returned an error on one of the batch key requests. This allows the other batch key requests to be returned and processed. Here is an example batch listener.
/**
* Asynchronous result notifications for batch operate commands with variable operations.
*/
public interface BatchOperateListListener {
/**
* This method is called when the command completes successfully.
*
* @param records record instances, {@link com.aerospike.client.BatchRecord#record}
* will be null if an error occurred for that key.
* @param status true if all records returned success.
*/
public void onSuccess(List<BatchRecord> records, boolean status);
/**
* This method is called when the command fails.
*/
public void onFailure(AerospikeException ae);
}
A single record get() will return null if the record does not exist. A batch get() will set
BatchRecord.recordto null andBatchRecord.resultCodeto KEY_NOT_FOUND for the key that is not found.Can you provide a code snippet where get() throws an AerospikeException with result code 2 (KEY_NOT_FOUND)?