About ids

Forum rules

This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo

Posted on
Fri Jul 01, 2011 12:22 am
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

About ids

Every IOM object has an "id" value. It's pretty clear and straight-forward. But before I code myself into a corner, let me double-check a few things.

Are these id values unique across all object types? Is it possible, if unlikely, for (say) a Device and an Action to end up with the same id value? (I hope not, but now's the time to find out.)

How persistent are those id values? Are there any circumstances under which they may change? How about updates to the Indigo software?

Are those ids reused? If I delete a device and immediately recreate it, may it end up getting the same id? May (say) a newly created action? Or are you throwing once-used ids out, never to be used again in that particular database (at least for a few dozen years :-))?

I'm asking not just what you're doing right now, but what we can rely on for the foreseeable future.

Thanks
-- perry

Posted on
Fri Jul 01, 2011 6:11 am
jay (support) offline
Site Admin
User avatar
Posts: 18225
Joined: Mar 19, 2008
Location: Austin, Texas

Re: About ids

IDs are unique within the DB so a device and trigger will never have the same one (for instance). Note that actions don't have IDs since they don't exist outside of a trigger, schedule, action group or control page.

IDs are randomly generated integers (longs I believe). We don't keep a list of previously used IDs so it is possible to get an ID that was just deleted. Extremely unlikely given the size of a long but theoretically possible.

We have no plans to ever change IDs for existing objects (even during version updates) and no plans to change how we create/manage them, so you can assume they are immutable.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jul 01, 2011 9:10 am
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Re: About ids

So since you're reusing ids (theoretically at least), the follow-up question: can I rely on change notifications to come in proper order? If some plugin deletes a Device (say), and some other plugin creates a trigger that happens to be assigned the same id, will I always get the deletion notification before the creation notification? And will those two always come to the same thread in my plugin?

Out of curiosity, why don't you just assign consecutive ids? That way, they'll be unique and never repeat until we've churned through 4 billion objects or so... Or you could use a suitable PRNG and save the seed for that random appearance?

Cheers
-- perry

Posted on
Fri Jul 01, 2011 9:38 am
jay (support) offline
Site Admin
User avatar
Posts: 18225
Joined: Mar 19, 2008
Location: Austin, Texas

Re: About ids

ID's are assigned by the server on initial save, not by the client and/or host process, so you'll never have objects created with the same id.

The plugin.py file is the central entry-point into your plugin - the host process will always dispatch events from the server to your handlers in the order they were received.

The chances of getting the same random number as something that was just deleted is infinitesimal (roughly 1 in 4 million). Having two different processes creating/deleting objects of your plug type is also quite small. Combine the two together and we're very confident that you'll never encounter a problem.

If you're storing an ID and you try to use it, and somehow it's gotten mutated into a different object type, then when you try to get the object you're going to get an error anyway because there is no way to get a "generic" object in the API - you always have to use one of the class-specific objects (indigo.devices, indigo.triggers, etc) to get the object. If the object isn't that type, then you'll get an error just like you'll get when a user deletes an object who's ID you're storing.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jul 01, 2011 10:07 am
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Re: About ids

Okay. I won't worry about it, then.

Thanks
-- perry

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 5 guests