[prev in list] [next in list] [prev in thread] [next in thread]
List: openldap-technical
Subject: Re: Counter concurrency access
From: Howard Chu <hyc () symas ! com>
Date: 2024-03-06 16:56:05
Message-ID: 85d6f50e-93a0-43c4-6fd5-3e23c159474c () symas ! com
[Download RAW message or body]
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.
--
-- Howard Chu
CTO, Symas Corp. http://www.symas.com
Director, Highland Sun http://highlandsun.com/hyc/
Chief Architect, OpenLDAP http://www.openldap.org/project/
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic