[DAS] Unique IDs for Model Instances (Was Initial Context?)
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > Apache Server configuration support > Apache Directory Project > [DAS] Unique IDs for Model Instances (Was Initial Context?)




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    [DAS] Unique IDs for Model Instances (Was Initial Context?)  
Ole Ersoy


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-19-07 06:11 AM

I think I got it.

Here's the challenge:

We have a DN like this:

DN: cn=accounts, cn=users, cn=example, ou=com

That corresponds to a model namespace like this:

http://example.com/users/accounts

So under the RDN cn=accounts there are several model
instances stored.

What should the RDN for each of these instances be?

Here's what I'm thinking the process is:

For each model instance we generate a surrogate key.

We do that by getting the total number of children that
the context cn=accounts, cn=users, cn=example, ou=com
has, and then add 1.  So if there are 14 children, the
new child gets a surrogate key assigned to it which is
15.

Then we write the surrogate key, along with a descriptive human
readable/identifiable string (Like "Alex Karasulu") taken from one of
the root object's attributes a file designated
by the DAS's configuration.  This is so that if the server
crashes (Hardware - never ADS), we'll know because we did
not write a completion flag into the file, and next time we run
the DAS it can recover.


Then we create the subcontext like this (dirContext is
cn=accounts, cn=users, cn=example, ou=com):

dirContext.createSubcontext("cn=15", attributes);

Originally I was was thinking generate a surrogate key using a hash,
but I think this is better.

So I'm going to go for it, unless anyone has a better idea.

Cheers,
- Ole









[ Post a follow-up to this message ]



    Re: [DAS] Unique IDs for Model Instances (Was Initial Context?)  
Stefan Seelmann


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-19-07 12:11 PM

Hi Ole,

Ole Ersoy wrote:

> Here's what I'm thinking the process is:
>
> For each model instance we generate a surrogate key.
>
> We do that by getting the total number of children that
> the context cn=accounts, cn=users, cn=example, ou=com
> has, and then add 1.  So if there are 14 children, the
> new child gets a surrogate key assigned to it which is
> 15.
>
> Then we write the surrogate key, along with a descriptive human
> readable/identifiable string (Like "Alex Karasulu") taken from one of
> the root object's attributes a file designated
> by the DAS's configuration.  This is so that if the server
> crashes (Hardware - never ADS), we'll know because we did
> not write a completion flag into the file, and next time we run
> the DAS it can recover.
>
> Then we create the subcontext like this (dirContext is
> cn=accounts, cn=users, cn=example, ou=com):
>
> dirContext.createSubcontext("cn=15", attributes);
>
The are some (LDAP-related) problems with this approach:
- This operation isn't atomic. There is some time between you calculate
the key and the real write operation. If there are many concurrent
threads writing model instances you will get an
NameAlreadyBoundException. Then you have to try again. I think with
random keys there are less collisions.
- There is no count(*) in LDAP. So to determine the number of children
you have to retrieve all children and count them within the DAS. Imagine
you have thousands or millions of children all of the DNs must be
transfered over the wire. This can take some time and will slow down the
system and doesn't scale well.

Regards,
Stefan







[ Post a follow-up to this message ]



    Re: [DAS] Unique IDs for Model Instances (Was Initial Context?)  
Emmanuel Lecharny


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-19-07 12:11 PM

Ole Ersoy a écrit :

> What should the RDN for each of these instances be?

Try to associate an *unique* key to each object, and used it

>
>
> We do that by getting the total number of children that
> the context cn=accounts, cn=users, cn=example, ou=com
> has, and then add 1.  So if there are 14 children, the
> new child gets a surrogate key assigned to it which is
> 15.

There is no way to get the number of entries in the server, but getting
all the entries and count them. Not really fast.
Forget about your idea, it does not work.

>
> Then we write the surrogate key, along with a descriptive human
> readable/identifiable string (Like "Alex Karasulu") taken from one of
> the root object's attributes

Just use this object's attribute as the RDN.

> <snip>

> Originally I was was thinking generate a surrogate key using a hash,

Don't. Hash are not guaranteed to be unique. Java HashCode is just a
speedup for comparisons.
o1.hashcode != o2.hashcode() => o1 != o2
but
o1.hashcode == o2.hashcode() does not implies that o1 == o2

Emmanuel






[ Post a follow-up to this message ]



    Re: [DAS] Unique IDs for Model Instances (Was Initial Context?)  
Ole Ersoy


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-19-07 06:11 PM

Stefan, Emmanuel,

Excellent thoughts.

OK - I'll scrap that idea.
I saw something about generating a unique
id based on current time on onjava.com
I'll see if I can find that article.

Thanks,
- Ole



Emmanuel Lecharny wrote:
> Ole Ersoy a écrit :
> 
>
> Try to associate an *unique* key to each object, and used it
> 
>
> There is no way to get the number of entries in the server, but getting
> all the entries and count them. Not really fast.
> Forget about your idea, it does not work.
> 
>
> Just use this object's attribute as the RDN.
> 
> 
>
> Don't. Hash are not guaranteed to be unique. Java HashCode is just a
> speedup for comparisons.
> o1.hashcode != o2.hashcode() => o1 != o2
> but
> o1.hashcode == o2.hashcode() does not implies that o1 == o2
>
> Emmanuel
>






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 05:52 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register