Hi,
we came across a problem while performing queries on an index in aerospike via the php client. When we set the key (POLICY_KEY_SEND) for put operations and the same policy later to query the index the client returns this error:
Unable to set policy: Invalid Value for OPT_POLICY_KEY
If I remove the options parameter it returns the matching records, just not with the record key.
$search_domain = 'google.com.my';
$select = Aerospike::predicateEquals ("domain", $search_domain);
$option = [Aerospike::OPT_POLICY_KEY => Aerospike::POLICY_KEY_SEND];
$status = $aero->query("app", "domain_name_log", $select, function ($record) {
var_dump($record);
}, array(), $option);
if($status != 0) { // new domain
$domain_id = createDomainID($aero);
$key = $aero->initKey("app", "domain_name_log", (string) $domain_id);
$bins = ["domain" => $referrer_domain];
$put = $aero->put($key, $bins, 3600, $option);
}
Anyone had a similar problem and knows how we can resolve that?
The query() method does not have that policy (see the documentation). However, I expect it to return the full key if it was first written through a put() that did have Aerospike::OPT_POLICY_KEY => Aerospike::POLICY_KEY_SEND
.
So for example:
<?php
$config = ['hosts'=>[['addr'=>'192.168.119.3','port'=>3000]]];
$db = new Aerospike($config);
function callme($r) {
var_dump($r['key']);
}
$status = $db->addIndex('test', 'discuss', 'id', "test_discuss_id", Aerospike::INDEX_TYPE_DEFAULT, Aerospike::INDEX_NUMERIC);
$key = $db->initKey('test','discuss',1534);
$option = [Aerospike::OPT_POLICY_KEY => Aerospike::POLICY_KEY_SEND];
$status = $db->put($key, ['foo'=>'bar','a'=>1,'id'=>1534], 0, $option);
if ($status !== Aerospike::OK) {
var_dump($status, $db->error());
echo "NOooooo\n";
exit;
}
$where = $db->predicateBetween('id', 1530, 1535);
$status = $db->query('test','discuss', $where, 'callme');
if ($status !== Aerospike::OK) {
var_dump($status, $db->error());
}
?>
Returns:
array(4) {
["ns"]=>
string(4) "test"
["set"]=>
string(7) "discuss"
["key"]=>
int(1534)
["digest"]=>
string(20) "8' ?w?B???I??=?"
}
Thanks for your reply, I checked the documentation I used again and it doesn’t show the limits on policy there. I used this resource: https://github.com/aerospike/aerospike-client-php/blob/master/doc/aerospike_query.md
Your link unfortunately shows me a 404.
I will try to run your sample tomorrow. For me the database had keys stored with KEY SEND policy and did return only bins and digest.
Sorry, I fixed the link. The documentation shows the policies that are available, and you should assume anything that isn’t mentioned is not appropriate. In the case of query() read timeout is the only policy.
If it’s not behaving as expected, it may be a bug. At that point open a new issue with information about your OS, PHP version, client release, server version, and code to reproduce the problem.