-
Notifications
You must be signed in to change notification settings - Fork 930
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
Support multitenancy in id generators #3286
base: master
Are you sure you want to change the base?
Conversation
6b58109
to
2f6d2ba
Compare
Not too keen on the exposing of properties in base classes and interfaces which are just for testing, such as "LastSourceValue" etc. Of course I kept them, but having them in the contract really doesn't serve any purpose. |
@@ -145,27 +164,29 @@ public override object Generate(IAccessCallback callback) | |||
{ | |||
using (_asyncLock.Lock()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally lock should be scoped to tenant too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
The way it's done now, the AsyncLock becomes part of the GenerationState, thereby piggybacking on that resolving part. It works fine, but the name GenerationState feels a bit off with that added. Maybe it's more a Context or something.
public override long LastSourceValue | ||
{ | ||
get { return _lastSourceValue; } | ||
get { return _stateStore.NoTenantGenerationState.LastSourceValue; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should return -1 if not initialized. See
nhibernate-core/src/NHibernate/Id/Enhanced/IOptimizer.cs
Lines 24 to 26 in 79ad5b8
/// The last value we obtained from the underlying source; -1 indicates we have not yet consulted with the source. | |
/// </value> | |
long LastSourceValue { get; } |
Your code throws. New method also doesn't return -1. It generates new state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I follow. Isn't it -1?
With "your code throws", are you referring to the throwing from NoTenantGenerationState? That was copied from Hibernate. The only option to avoid that is to generate new state.
/// <summary> | ||
/// Obtain the tenant identifier (multi-tenancy), if one, associated with this callback. | ||
/// </summary> | ||
string GetTenantIdentifier(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say so, yes. Somehow the tenant identifer must become available to the optimizer. This is the way I cloned from https://github.com/hibernate/hibernate-orm/blob/main/hibernate-core/src/main/java/org/hibernate/id/enhanced/AccessCallback.java , and I don't think there's a better way.
c84556a
to
ff20724
Compare
Fix for #2834
Looked quite a lot at the Java implementation, which has this support added. They have also cleaned up a bit, e.g by replacing old generators with configuration of new ones, but I didn't go that far.
Things to consider: