[MUD-Dev] Re: [DevMUD] Re: Database module

J C Lawrence claw at kanga.nu
Mon Dec 21 20:30:42 CET 1998


Crossed to MUD-Dev as the discussion of ObjectID's is generic to
server designe as versus DevMUD.

On Sun, 20 Dec 1998 12:05:57 -0800 
Jon Leonard<jleonard at divcom.slimy.com> wrote:

> Things that we want to look up in the database have numeric IDs to
> identify them, and there are newid() and recycle_id() to allocate
> new ones and to tell the database than an ID is no longer in use.  I
> was planning on using unsigned longs as the ID type (64-bit on
> frost).

I went thru the problem of ObjectID's and their re-use on MUD-Dev
extensively.  A key problem is that there may be pointers or
references to an object after the object has been destructed, and that
once you have an ObjectID->human_readable->ObjectID translation
mapping, you can never guarantee that a reference count is accurate.

  What happens when someone hardcodes a literate human_readable
ObjectID in user code, and that object is deleted and the objectID
recycled?  

You can't track it with reference counting, and you can't guarantee at
the time of coding even that the ObjectID points at the object that
the programmer things it does as versus a newly recycled object.

The solution I came to was that ObjectIDs are comprised of two 32bit
integers.  One 32 bit value is a signed integer, and is used as a
record ID with the high bit used as a "deleted" flag.  The other 32
bits are the time_t at the instant the object was created.  The only
requirement then for objectID recycling are that that an object may
not be deleted and recycled within a period of one second or less.  A
simple deletedID cache in the recycler which imposes wait periods for
ID's handles that one simply enough.

> Within each ID, there's a mapping from keys to values.  I was
> thinking of using strings as keys, and having a few types of
> results.  The functions would be something like:

For human-readable objectID's I came up with a hacked base 64
represenation of the above 64bit keys.  Essentially it is ala
hexadecimal except that I use all 52 upper and lower case letters, the
10 digits, and the punctuation symbols '.' and '-'.

> lookup_type(id,key) lookup_value(id,key) set_value(id,key,value)

For the mapping of arbitrary unique strings to object ID's (eg $box$
to the box base class object), I use an attribute off the root object
(object with a record ID of 0 -- no other peculiarities) of the DB
which contains an associative array of strings and ObjectID's.

--
J C Lawrence                              Internet: claw at kanga.nu
----------(*)                            Internet: coder at kanga.nu
...Honorary Member of Clan McFud -- Teamer's Avenging Monolith...




More information about the mud-dev-archive mailing list