Currently the IncrementGenerator is not cluster-safe as it fetches the currently greatest Id in a separate transaction.
By simply changing this behavior to fetch the greatest id in the current transaction, IncrementGenerator can be made cluster-safe:
Code:
private void getNext(ISessionImplementor session)
{
log.Debug("fetching initial value: " + sql);
//Old Code: IDbConnection conn = session.Factory.OpenConnection();
//Old Code: IDbCommand qps = conn.CreateCommand();
IDbCommand qps = session.Connection.CreateCommand();
session.Transaction.Enlist(qps);
...
Of course, this causes the underlying user-created transaction to be initiated immediately, instead of when Commit() is called. This will in turn cause less concurrency in operations on affected tables, but as IncrementGenerator currently cannot handle concurrency at all, this is IMO not a great loss.
Is there a reason not to implement this behavior that I have not thought of?
(note: code above assumes a transaction has been created)