|
Home > Archive > Apache Directory Project > April 2007 > [DAS] Unique IDs for Model Instances (Was Initial Context?)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
[DAS] Unique IDs for Model Instances (Was Initial Context?)
|
|
| Ole Ersoy 2007-04-19, 1: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
| |
| Stefan Seelmann 2007-04-19, 7:11 am |
| 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
| |
| Emmanuel Lecharny 2007-04-19, 7:11 am |
| 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
| |
| Ole Ersoy 2007-04-19, 1: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
>
|
|
|
|
|