Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SequenceStyleGenerator generator badly triggering batcher with Stateless Sessions #2309

Open
gokhanabatay opened this issue Jan 28, 2020 · 3 comments

Comments

@gokhanabatay
Copy link
Contributor

gokhanabatay commented Jan 28, 2020

We have a database(Oracle) sequence that increments 100 at a time, sequence mapped with below method so 1000 Entity Save method access calls 10 times to database for new Sequence.nextval.

Wit a stateless session (and adonet.batch_size = 1000, order_updates = true in hibernate.cfg.xml), every 100 + 1 calls, Save triggers the batcher. It's uses same Batcher instance with SequenceStyleGenerator. Why "SequenceStyleGenerator" needs batcher at all, just to reads one line of data?

(With a statefull session (and adonet.batch_size = 1000, order_updates = true in hibernate.cfg.xml), every 100 Save calls just triggers Sequence.nextval. Batcher waits until batch size(1000) to get triggered.)

Fluent Mapping:

Id(x => x.Guid).Column("GUID").GeneratedBy.PooledSequence(100); 
 public static TParent PooledSequence<TParent>(this IdentityGenerationStrategyBuilder<TParent> generationStrategyBuilder, int allocationSize = 1, string sequenceName = "")
 {
            return generationStrategyBuilder.Custom<SequenceStyleGenerator>(p =>
            {
                p.AddParam("sequence_name", string.IsNullOrEmpty(sequenceName) ? DefaultPooledSequenceName : sequenceName);
                p.AddParam("value_column", "NEXT_VALUE");
                p.AddParam("optimizer", "pooled");
                p.AddParam("increment_size", allocationSize.ToString());
            });
 }
@gokhanabatay gokhanabatay changed the title Batch insert when using SequenceStyleGenerator with stateless sessions? Batch insert adonet.batch_size issue when using SequenceStyleGenerator with Stateless Sessions Jan 28, 2020
@fredericDelaporte fredericDelaporte changed the title Batch insert adonet.batch_size issue when using SequenceStyleGenerator with Stateless Sessions SequenceStyleGenerator generator badly triggering batcher with Stateless Sessions Jan 29, 2020
@hazzik
Copy link
Member

hazzik commented Feb 7, 2020

Somehow related to this: hibernate/hibernate-orm@b006a6c

@hazzik
Copy link
Member

hazzik commented Mar 11, 2020

I was looking into this. It's quite a mess. The fix should be easy.

@gokhanabatay would you be able to submit failing test(s)?

@gokhanabatay
Copy link
Contributor Author

gokhanabatay commented May 14, 2021

Hi @hazzik sorry for late response, I need to know how to check batcher access count and how to create custom sequence via nhibernate mappings.

But I think issue is clear let me tell you.

In StatelessSessionImpl.Insert method
object id = persister.IdentifierGenerator.Generate(this, entity); uses directly Batcher so existing waiting commands will be flushed instant.

In SessionImpl uses ActionQueue so accessing Batcher in AbstractSaveEventListener.SaveWithGeneratedId method object generatedId = persister.IdentifierGenerator.Generate(source, entity) for sequences does not trigger waiting inserts/updates/deletes.

For better batching support I think, identity generators should use different batcher, is it realy necessary use Batcher with identity generators at all?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants