[Opa] Db3 -> Mongo || Db3.fresh_key -> ?
rudy.sicard at mlstate.com
Mon Apr 30 17:57:04 UTC 2012
If collision or compactness of the key range are a serious concern, you
have to maintain a counter somewhere (with both intmap and set)
You can use findAndModify to increment and return a counter atomically
from the db.
Or assuming only one server, you can use a cell (to ensure atomicity)
that is saved in db (for server reload).
I am going to push code for both memory atomic operation, and
So if you go for seconds solutions, let me know, if you are lost, I can
push it sooner.
If for you are using a integer key for bad reason and want to stick to
it for good reason,
and you don't care about compactness of the key range,
and you don't intend to insert more than billions of entries (or
thousands for 32bits machines)
and you are not writing code for a nuclear power plant (i.e. collisions
are not lethal).
Just go with a proven solution, random key (=> e.g. freshkey() =
You can seriously reduce collision to a probability of almost zero just
by checking the key is not already used,
so it is not as bad as you may think.
k = Random.int(max_int)
if check(k) then k
On 30/04/2012 18:38, Matthieu Guffroy wrote:
> How we get a fresh_key with mongo backend ?
> Is there a different way of using it ?
> I think the best would be to insert in a set instead of inserting in a
> intmap with a freshkey. And let mongo autoincrement the primary key...
> Is it possible ? If yes how ?
> Matthieu GUFFROY
> Opa mailing list
> Opa at lists.owasp.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Opa