Fixed the bug in random seq allocator code - always do "+1" because .netxInt(10) method can return 0, and the id in this case will be equal the id already present in the DB.

This commit is contained in:
alena 2011-10-07 09:52:49 -07:00 committed by kishan
parent 334eeccd2c
commit 1c02374708
1 changed files with 2 additions and 2 deletions

View File

@ -47,6 +47,7 @@ import com.cloud.utils.concurrency.NamedThreadFactory;
public class SequenceFetcher {
private final static Logger s_logger = Logger.getLogger(SequenceFetcher.class);
ExecutorService _executors;
private final static Random random = new Random();
public <T> T getNextSequence(Class<T> clazz, TableGenerator tg) {
return getNextSequence(clazz, tg, null, false);
@ -115,8 +116,7 @@ public class SequenceFetcher {
PreparedStatement updateStmt = txn.prepareStatement(sql.toString());
if(isRandom){
Random random = new Random();
updateStmt.setInt(2, random.nextInt(10));
updateStmt.setInt(2, random.nextInt(10) + 1);
} else {
updateStmt.setInt(2, _tg.allocationSize());
}