vlad wrote:
1. When you need to restart the DB, the sequence number will start from 1 after a restart, right?
To the best of my knowledge the last value of a database sequence is persistent and not rolled back. This is even the case in the face of the confusingly named
CACHE attribute. This actually causes sequence numbers to be preallocated on the server side. This also causes the last cached value to be committed. If you do not use all cached values or restart the DB they are not handed out again but lost/wasted.
https://docs.oracle.com/database/122/SQLRF/CREATE-SEQUENCE.htm#SQLRF01314 wrote:
If a system failure occurs, then all cached sequence values that have not been used in committed DML statements are lost. The potential number of lost values is equal to the value of the CACHE parameter.
https://www.postgresql.org/docs/current/static/sql-createsequence.html wrote:
So, any numbers allocated but not used within a session will be lost when that session ends, resulting in "holes" in the sequence.
https://docs.microsoft.com/en-us/sql/t-sql/statements/create-sequence-transact-sql wrote:
When created with the CACHE option, an unexpected shutdown (such as a power failure) may result in the loss of sequence numbers remaining in the cache.
vlad wrote:
2. The identifier generator must work concurrently, so how can you make it available for multiple database connections? Otherwise, each DB connection uses its own generator so you get identifier conflicts.
True but hi/lo, pooled and pooledlo have the same issue. That's why they are all
synchronized. I use a
java.util.concurrent.locks.Lock to achieve the same thing. In theory a
ConcurrentLinkedQueue could be used in order to avoid the locking and avoid a possible spot for contention. As this has not popped up so far for hi/lo, pooled and pooledlo I assumed this is not an issue.