Skip to content

Commit 0bf4e2b

Browse files
Alter Rust bindings to make investigation easier, reproduce issue 63
This patch introduces a PHP script in DEBUG-sfalvo where I am able to reproduce the OP's issue. To do this, I needed to make a small adjustment to the Rust binding code. After speaking with Khosrow, he recommended adding a few utility methods to the Expiration class ("We probably need a few methods in there, including neverExpire() -> bool, serverDefault() -> bool in addition to inSeconds() (in seconds should be an i64 that can be negative for the two above values.)). For now, this is just a research branch; DO NOT merge into main.
1 parent 53754a3 commit 0bf4e2b

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

DEBUG-sfalvo/put.php

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
namespace Aerospike;
4+
5+
////////////////////////////////////////////////////////////////////////////////
6+
//
7+
// Creating Client, persisting in permanent storage, retriving from there
8+
//
9+
////////////////////////////////////////////////////////////////////////////////
10+
11+
$socket = "/tmp/asld_grpc.sock";
12+
13+
$client = Client::connect($socket);
14+
15+
////////////////////////////////////////////////////////////////////////////////
16+
//
17+
// Key object
18+
//
19+
////////////////////////////////////////////////////////////////////////////////
20+
21+
$key = new Key("test", "test", 1);
22+
23+
////////////////////////////////////////////////////////////////////////////////
24+
//
25+
// client->truncate
26+
//
27+
////////////////////////////////////////////////////////////////////////////////
28+
29+
// $ip = new InfoPolicy();
30+
// $client->truncate($ip, "test", "test");
31+
32+
////////////////////////////////////////////////////////////////////////////////
33+
//
34+
// client->put
35+
//
36+
////////////////////////////////////////////////////////////////////////////////
37+
38+
echo "============= PUT ===============\n";
39+
40+
$wp = new WritePolicy();
41+
$wp->setExpiration(Expiration::Seconds(10));
42+
43+
$bin1 = new Bin("bin1", 111);
44+
45+
for ($x = 0; $x < 10; $x++) {
46+
$key = new Key("test", "test", $x);
47+
$bin1 = new Bin("bin1", $x);
48+
echo "/";
49+
$client->put($wp, $key, [$bin1]);
50+
}
51+
echo "\n";
52+
53+
////////////////////////////////////////////////////////////////////////////////
54+
//
55+
// client->get
56+
//
57+
////////////////////////////////////////////////////////////////////////////////
58+
59+
echo "============= GET ===============\n";
60+
61+
$rp = new ReadPolicy();
62+
63+
$rp->setMaxRetries(3);
64+
$timeInMillis = 3000;
65+
$rp->timeout = $timeInMillis;
66+
67+
var_dump($rp);
68+
69+
for ($x = 0; $x <= 10; $x++) {
70+
sleep(1);
71+
$record = $client->get($rp, $key, ["bin1"]);
72+
if ($record) {
73+
echo "RECORD " . $x . " TTL = " . ($record->getTtl()) . "\n";
74+
echo "RECORD " . $x . " EXP = " . ($record->getExpiration()->inSeconds()) . "\n";
75+
}
76+
else {
77+
echo "Record " . $x . " expired.\n";
78+
}
79+
}
80+
81+
$record = $client->get($rp, $key);
82+
var_dump($record->bins);
83+
var_dump($record->generation);
84+
var_dump($record->key);
85+
86+
////////////////////////////////////////////////////////////////////////////////
87+
//
88+
// $client->delete
89+
//
90+
////////////////////////////////////////////////////////////////////////////////
91+
92+
$deleted = $client->delete($wp, $key);
93+
var_dump($deleted);
94+
95+
$exists = $client->exists($rp, $key);
96+
var_dump($exists);
97+

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,12 @@ impl Expiration {
16571657
_as: _Expiration::DontUpdate,
16581658
}
16591659
}
1660+
1661+
/// Answers with the expiration's configured value in units of seconds.
1662+
#[getter]
1663+
pub fn in_seconds(&self) -> u32 {
1664+
self.into()
1665+
}
16601666
}
16611667

16621668
impl From<&Expiration> for u32 {
@@ -9744,6 +9750,7 @@ impl Client {
97449750
/// Write record bin(s). The policy specifies the transaction timeout, record expiration and
97459751
/// how the transaction is handled when the record already exists.
97469752
pub fn put(&self, policy: &WritePolicy, key: &Key, bins: Vec<&Bin>) -> PhpResult<()> {
9753+
eprintln!("LBPUT001 put() entered");
97479754
let bins: Vec<proto::Bin> = bins.into_iter().map(|b| b.into()).collect();
97489755

97499756
let request = tonic::Request::new(proto::AerospikePutRequest {
@@ -9761,6 +9768,7 @@ impl Client {
97619768
} => Ok(()),
97629769
pe => {
97639770
let error: AerospikeException = pe.into();
9771+
eprintln!("LBPUT002 Error detected: {:?}", error);
97649772
throw_object(error.into_zval(true)?)?;
97659773
Ok(())
97669774
}

0 commit comments

Comments
 (0)