[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: How can I lock a record using php-ldap?

Quoting Alan Sparks <asparks@doublesparks.net>:

> No, there's no such operation (at least that I've ever seen, cover myself).
> Not sure you was the subtlety of the proposed operation.  The clients do
> have to fetch the value in a separate query, true.  But each makes an
> update that depends on deleting the original value (uidnumber=42).  One
> client will succeed, and atomically (i.e., in the same ldapmodify
> operation) change uidnumber=43.  Other clients following, those with the
> original uidnumber=42, will fail the whole thing because they cannot
> delete the attribute/value uidnumber=42.
> Yes, the failing clients need to requery the uidnumber, choose another,
> and resubmit the modify.  As I said, such is life.
> While there's no locking protocol officially, one might simulate something
> similar by defining an attribute and an auxiliary class to mix into the
> objects where "locking" is needed.  This objectclass could have the
> attribute as a SINGLE-VALUE type attribute.  Clients could then add an
> instance of this attribute as a simulation of a locking call -- if it
> succeeds, ok; if it fails (because the attribute already exists), the
> "lock" fails.  Be careful to delete the lock attribute when update is
> done!

Is this any different?  It would just shift the event where the conflict could
occur (or at least my newbie mind sees it that way).

I think it would only work as a pseudo lock if one was to attempt to add this
lock attribute before querying for the initial values.  If done the other way
around, the task of getting the values and setting the lock would not be atomic.
 But that is probably what you meant in the first place ;-)


> Jim C said:
> > Yes but don't we have to retrieve 42 first before we can make changes to
> >  it?  The race condition occurs in the script because we have more than
> > one step involved in the retrieve and modify cycle in the script.  Is
> > there an atomic function of which I am unaware that will allow one to
> > retrieve an attribute and alter it's value in the database
> > simultaneously?  If not then we are stuck.
> >
> >> changetype: modify
> >> delete: uidnumber=42
> >> add: uidnumber=43

Ryan T. Gallagher
International Studies Abroad