Unable to log errors [Resolved]


#1

Hello,

I have a save function that return an error, but I can’t see which one because it always prints this:

Fatal error: Cannot access private property Aerospike::$errorno in /some dirs/DBClass.php on line 162

Which looks like:

static public function set($ns, $set, $key_name, $bins) { $client = self::getDb();

    $key = $client->initKey($ns, $set, $key_name);

    $status = $client->put($key, $bins);
    if ($status != Aerospike::OK) {
        LogClass::log("Error writing {$ns}, {$set}, {$key_name}, $client->errorno(), $client->error()");
    }
    return $status;
}

I know that $status value is ERR_BIN_NAME, that’s all I know.

$ns = “users”

$set = “users”

$key_name = a string of about 20 characters

Thanks in advance


#2

I’m not sure what line 162 corresponds to, but both error() and errorno() are public methods of the Aerospike class.

Take a look at the error handling and logging methods in the doc. I’m not sure where the problem is, yet. Error handling seems to be working fine.


#3

Line 162 corresponds to this:

LogClass::log(“Error writing {$ns}, {$set}, {$key_name}, $client->errorno(), $client->error()”);

$client is an instance of Aerospike. If it’s public, then why does my PHP script crashes, telling me that errorno is private?

Also, I don’t understand why there is an error in the first place… Here’s a var_dump of the bins I’m trying to put in:

array(11) { [“diamonds”]=> int(30) [“lives”]=> float(5) [“life_time”]=> float(1441493823) [“last_reward_time”]=> int(1441493823) [“save_time”]=> float(1441493823) [“version”]=> int(0) [“current_level”]=> int(1) [“tutorial_mode”]=> int(1) [“creation_time”]=> int(1441493823) [“prompt_like”]=> bool(true) [“boosters”]=> array(3) { [0]=> int(0) [1]=> int(0) [2]=> int(0) } }


#5

Ok, nevermind. It was a PHP error. Putting $client->errorno() inside the string, it was trying to access $client->errorno, which is indeed a protected attribute.

The error is “Bin name longer than 14 chars”. Indeed, I use a Facebook ID as a key, and Facebook IDs have 16 characters, and sometimes more.

This is a real problem, because this id is the only identifier I have for my users… and I can’t truncate it without risking duplicates…

What can I do to solve this? Is there a way to change this limit?

Thanks in advance.


#6

I’m not sure why you’d use the Facebook ID as the key, seems like it should be the value, and the bin name something like ‘fbid’, no? It doesn’t make sense to me, I wonder if you could explain the thinking behind it.

Be aware that there’s a limit of 32k unique bin names in a namespace. See the FAQ.


#7

The value is actually the user’s data…

It would be like:

"123456789123456789" -> {"name":"kevin", "age":15}
"123456789123456790" -> {"name":"michael", "age":24}
...
"123456789123456889" -> {"name":"john", "age":42}

I took a look at the FAQ about limits… I’m not sure how I am going to scale this to potential millions of users… I guess I can just split the key into several parts, like this:

(12345678912345)(688)(9)
(bin name)(set)(namespace)

Then I would have 14 character key names in each set, 1000 sets per namespace, and 10 namespaces… The total number of users would be limited to 327 670 000 users, which is more than enough.

But it’s a very fragile structure… what if Facebook changes their ids for longer ones? (it wouldn’t be the first time)


#8

Your example makes it look like those FB IDs should be the primary key for a set named ‘facebook’ (or something of that sort). The primary key can be of any length since it actually gets hashed into a 20 byte digest used by the client and server nodes to locate the record.


#9

I thought the bin name and the primary was the same thing… I’m confused. If I take the example from the Quick Guide:

$key = $db->initKey("infosphere", "characters", 3);
$bins = ["name" => "Bender", "Occupation" => "Bender", "age" => 1055];
// store the key data with the record, rather than just its digest
$option = [Aerospike::OPT_POLICY_KEY => Aerospike::POLICY_KEY_SEND];
$db->put($key, $bins, 0, $option);

I see a namespace, a set, a primary key name for the bins, and bins containing keys->values. I looked into the API reference, and the $pk parameter for the initKey method is where I put my Facebook IDs. So if you say thay $pk can have any length… it shouldn’t raise an error…

Edit: nevermind… “last_reward_time” has 16 characters… that’s probably what’s raising the error :facepalm:


#10

Ha. No problem. Take out those underscores.