http://marklogic.markmail.org/search/?q=sequence#query:sequence+page:1+mid:rfwwbwmh7sm3zyj4+state:results has a fair amount of previous discussion on this topic. I agree with John that random numbers are best, both for performance and also for security.
Note that sequences are often a source of update contention in the RDBMS world, too. David's suggestion of a dedicated sequence doc will help a bit. Creating more than one sequence doc is even better: for example, you might have ten documents that each start with 1..10, and each increment by tens. But RDBMS applications that need a high insert rate will often avoid sequences completely, and use some other mechanism to generate ids. For MarkLogic, xdmp:random is a good choice. -- Mike On 16 Dec 2011, at 06:05 , John Snelson wrote: > The method you have devised will work as you expect it to. It will also > perform badly as it will lock out concurrent updates. > > You should consider using xdmp:random() to generate a 64 bit random > number for your unique identifier. > > John > > On 16/12/11 13:55, Raghu wrote: >> Hi All, >> I need to auto increment an id (long int) based on the incoming >> concurrent requests. I'll be incrementing the max of existing value by >> 1 and persist the value in the same xml. My assumption is since I'm >> doing this in a single transaction and also I have an update statement >> in this transaction, a lock will be obtained on that xml so that the >> next request will have to wait for the lock to be released and when the >> second request increments the id value from the max of existing values >> it will take the latest value. Am I right? If not, is there some other >> way to do it? Please note that I don't need a timestamp as my ID, I need >> to have an integer. I just need the relational database style auto >> increment feature which should give me unique id even if there are >> concurrent requests.Also note all the requests are from the same user so >> I cannot use a lock acquire for that user. >> Thanks >> Raghu > > -- > John Snelson, Senior Engineer http://twitter.com/jpcs > MarkLogic Corporation http://www.marklogic.com > _______________________________________________ > General mailing list > [email protected] > http://developer.marklogic.com/mailman/listinfo/general > _______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
