Articles in this section

How to get the Aerospike partition number from a DIGEST

Context

When doing an analysis of records that have issues, you may wish to see if they are all on the same node, and one easy way to achieve this is to extract the partition-id from the digest. It would be easier and quicker if you didn't have to ask AQL about every digest to extract the partition ID.

Method

As we know, the first 12 bits of a digest are used to store the partition number, so we will use 3 of the first 4 characters of that digest
Once you have the digest, you can simply call this python script to extract the partition number :-
python2 -c 'import sys; print(int(sys.argv[1][3]+sys.argv[1][0:2], 16))' <digest>

This will work as well for python3 as it does for python2

 

For example lets take this record :

aql> explain select * from test where PK=1;
+---------+---------+-------------------+-----+-----------+--------------------------------------------+-----------+--------+-----------+----------------------------+-------------------------+
| TIMEOUT | UDF     | MASTER NODE       | SET | NAMESPACE | DIGEST                                     | PARTITION | STATUS | KEY_TYPE  | POLICY_REPLICA             | POLICY_KEY              |
+---------+---------+-------------------+-----+-----------+--------------------------------------------+-----------+--------+-----------+----------------------------+-------------------------+
| 1000    | "FALSE" | "BB90C0011AC4202" | ""  | "test"    | "A443F05D05D962202B59ABB402AFAE1737DBF66A" | 932       | ""     | "INTEGER" | "AS_POLICY_REPLICA_MASTER" | "AS_POLICY_KEY_DEFAULT" |
+---------+---------+-------------------+-----+-----------+--------------------------------------------+-----------+--------+-----------+----------------------------+-------------------------+

root@test-1:/# python3 -c 'import sys; print(int(sys.argv[1][3]+sys.argv[1][0:2], 16))' A443F05D05D962202B59ABB402AFAE1737DBF66A
932

 


Notes

The partition is stored like this : XX.X in the first 4 characters of the digest.

root@test-1:/# python3 -c 'import sys; print(int(sys.argv[1][3]+sys.argv[1][0:2], 16))' 0001
256
root@test-1:/# python3 -c 'import sys; print(int(sys.argv[1][3]+sys.argv[1][0:2], 16))' 0101
257
root@test-1:/# python3 -c 'import sys; print(int(sys.argv[1][3]+sys.argv[1][0:2], 16))' 0102
513
root@test-1:/# python3 -c 'import sys; print(int(sys.argv[1][3]+sys.argv[1][0:2], 16))' FF0F
4095
You can see from the above that character 4 is the most significant, and character 3 is not part of the equation.

Applies To Earliest Version

Pre 4.9

Applies To Latest Version

Current Version
Was this article helpful?
0 out of 0 found this helpful