Locate Aerospike node id from a record

Hi Friends, In an Aerospike cluster, is there a method (ideally java client API) which can locate the node id(s) of the host where a given record is store? For example, I know a record with namespace, set and PK, how can I find out in which node(s) the record is stored?


1 Like

I haven’t tested, but looking at the Java client it seems you would create a either a WriteCommand or ReadCommand with the applicable policy and key and then call the commands getNode method. For this you will need access to the client’s cluster object which is protected by default so you would need to extend the AerospikeClient to expose the cluster.

Something like

public class MyClient extends AerospikeClient {
    public Cluster getCluster() {
        return this.cluster;

MyClient client = new MyClient("", 3000);
Key key = new Key("test", "test-set", "test-key");

WriteCommand cmd = new WriteCommand(client.getCluster(), key, NULLL, NULL);
Node node = cmd.getNode();

My java is a bit rusty, hopefully this is close to something that will work.

Hi kporter, Thanks for the reply.

I looked at AerospikeClient class but the getNode() method requires string NodeName as parameter. So I doubt if it will work.

I’m calling the getNode command on the WriteCommand class.

Here is a hack… :frowning: … (key1 is the record of interest, I am assuming it exists on the cluster already - so this is expected to fail. AerospikeException can retrieve the node.)

                  WritePolicy wp = new WritePolicy();
                  Bin b1 = Bin.asNull("b1");
                  client.put(wp, key1, b1);
                catch(AerospikeException e){

Understood and that works! Thanks a lot. :smiley:

Have not yet tried but looks like a simpler solution! :smiley:

Here comes the further question: Is it possible to get a list of master and replica nodes in which the record is stored?

Technically, the java client does know who the replica node is for this key. You will have to dig into the java client source code to figure that one out, as far as I know. Never seen a request for such info. Why does your application need it? May be there is another way to achieve what you are trying to achieve at the application level.

Hm, again this isn’t something that the client exposes by default so you will need to extend the WriteCommand and expose the protected partition so that you can access partition.replicas.

public class MyCommand extends WriteCommand {
    public AtomicReferenceArray<Node>[] getReplicas() {
        return this.partition.replicas;

Could you share what it is you need this information for? I assume this is for testing?

1 Like

Yes, this is for testing purpose and also support engineers want to know for some reason.

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.

I’ve put together a utility which can help with some of these functions particularly for testing purposes. You can find it at GitHub - aerospike-examples/debug-aerospike-client: Implementation of the IAerospikeClient interface which allows debug code and timing metrics, and it has a couple of functions like being able to monitor latency from the client side like you can from the server side with asloglatency.

However, there is also a ClusterUtilities class which has functions like getting the partition id for a key, finding a key which has a master and replica of given nodes and I’ve just added what you’re after – given a key find the master and replica nodes.

There is also a main() function so it can be built as a jar and it exposes these utilities to the command line so you can use it as a helper for testing. Very useful if you want to test strong consistency in the face of a network split and you need to know how to force the network split to see what happens when the master and replica fall into different sub-clusters for example.

1 Like