-
Notifications
You must be signed in to change notification settings - Fork 456
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
dev.morphia.Datastore Thread Safety #3035
Comments
In our project, we faced the same issue with lazy mapping of the entities during runtime. Version, which we currently use is 2.4.11. |
I'm hesitant to do too much thread-safety work here as this is a very common method to call. A better fix, on your end, is to not rely on lazy mapping (especially as that is going away) and explicitly map your classes/packages up front. This should eliminate your issues. Please try pre-mapping and see if your issue goes away. If it doesn't, we can talk about this PR. |
That was already a discussion here: #2802 |
@evanchooly Could we please consider fixing the issue at least for 2.4.x versions?
|
We also run into this issue during our migration from 1.6 to 2.4. We also pre-register our entities during startup, but it looks like Mapping all entities upfront wouldn't really work either, since each datasource has its own mapper with Morphia 2.4. If we map all entities on all datasources, that seems quite inefficient (especially since most entities wouldn't be used on all datasources). I don't quite understand why no read/write mutex is used for this, if this is so critical. |
Discussed in #2802
Originally posted by AmitKuGarg December 18, 2023
Describe the bug
When dev.morphia.Datastore shared across thread, I get Two entities have been mapped using the same discriminator value.
To Reproduce
Steps to reproduce the behavior:
Create a sample collection and create the datastore.
Datastore datastore = Morphia.createDatastore(mongo, dbName);
datastore.ensureIndexes();
if(this.packages != null){
for (String packageString : packages) {
datastore.getMapper().map(packageString);
}
}
Create a runnable class and pass the data store and id parameter. In run method load the data from the collection using id and datastore.
class Task implements Runnable {
private String id;
private Datastore mongoDatastore;
Task(String id, Datastore mongoDatastore) {
this.id = id;
this.mongoDatastore = mongoDatastore;
}
@OverRide
public void run() {
}
}
Write main method, create ExecutorService and try to load different documents.
ExecutorService executor = Executors.newFixedThreadPool(10);
executor.execute(new Task("ABC12345", mongoDatastore));
executor.execute(new Task("ABC123456", mongoDatastore));
I get Two entities have been mapped using the same discriminator value.
Try two scenario
The text was updated successfully, but these errors were encountered: