Hi there
I am creating a program that needs to increment a counter. Typically a serial number has to be incremented every time I create a certificate.
The problem is to handle concurrent access. Fundamentally I need to 1/ read the counter 2/ increment it. Therefore no one must be provided access to the counter during these two operations.
Therefore I need to set a lock before the read operation and release it after the update. Is there a way to do this with OL ? I am conscious of the ldapmodify features thanks to Clement, however, this will not lock the read.
Thks in adv.
P
Pascal Jakobi wrote:
Hi there
I am creating a program that needs to increment a counter. Typically a serial number has to be incremented every time I create a certificate.
The problem is to handle concurrent access. Fundamentally I need to 1/ read the counter 2/ increment it. Therefore no one must be provided access to the counter during these two operations.
Therefore I need to set a lock before the read operation and release it after the update. Is there a way to do this with OL ? I am conscious of the ldapmodify features thanks to Clement, however, this will not lock the read.
You don't need to do any locking, just use the ldapmodify Increment operator and the value will be incremented atomically.
Howard Chu wrote:
Pascal Jakobi wrote:
Hi there
I am creating a program that needs to increment a counter. Typically a serial number has to be incremented every time I create a certificate.
The problem is to handle concurrent access. Fundamentally I need to 1/ read the counter 2/ increment it. Therefore no one must be provided access to the counter during these two operations.
Therefore I need to set a lock before the read operation and release it after the update. Is there a way to do this with OL ? I am conscious of the ldapmodify features thanks to Clement, however, this will not lock the read.
You don't need to do any locking, just use the ldapmodify Increment operator and the value will be incremented atomically.
On re-reading, I see - you want to read the value and then separately do an increment on it.
In that case you just read the value, then do an ldapmodify with
delete: current value - add: new value -
Then the op will only succeed if the value hasn't changed yet. If the value changed, someone else got in there between your read and your modify, and you'll have to retry the entire sequence until it succeeds.
openldap-technical@openldap.org