google-code-export / morphia

Automatically exported from code.google.com/p/morphia
1 stars 0 forks source link

UpdateResult getN, getUpdatedExisting all throw error #271

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What version are you using? (Morphia/Driver/MongoDB)

Class clazz  = com.mycompany.Dog.class;
boolean yesOnUnique = true;
Query q = factory.datastore.createQuery(clazz).field("_id").equal(object.id);
    UpdateOperations ops = factory.datastore.createUpdateOperations(clazz).add( 
    "toys", "babyduck", yesOnUnique);

String fieldSize = fieldNameOfList+"_size";
//addtional field in row to keep track of list size.

if ( clazz.metaClass.getMetaProperty(fieldSize)!=null ) {
   ops.inc(fieldSize);
}

UpdateResults re = factory.datastore.update(q, ops);

println re.getN();//this errors out
--------------------------------------------
Exception in thread "Thread-449" java.lang.IllegalStateException: The 
connection may have been used since this write, cannot obtain a result
    at com.mongodb.WriteResult.getLastError(WriteResult.java:98)
    at com.mongodb.WriteResult.getLastError(WriteResult.java:72)
    at com.google.code.morphia.query.UpdateResults.getN(UpdateResults.java:33)
    at sun.reflect.GeneratedMethodAccessor1588.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)

Original issue reported on code.google.com by s...@frequency.com on 21 Apr 2011 at 9:43

GoogleCodeExporter commented 9 years ago
This error is a threading/contention issue and not related to Morphia. It just 
comes from the driver. If you have more worker threads than the number of 
sockets then you will have high contention and you can get errors like this.

Original comment by scotthernandez on 21 Apr 2011 at 11:49

GoogleCodeExporter commented 9 years ago
ok this makes sense. i didnt know it was something in the driver. i thought it 
was how morphia used the driver. i guess the authors of the driver would never 
open up the connection pooling api for any special features.

i guess if we need more concurrency, we can add additional mongo objects (pools)

thanks. 

Original comment by s...@frequency.com on 22 Apr 2011 at 12:03

GoogleCodeExporter commented 9 years ago
I guess I should ask, were you able to reproduce this *not* under load, or with 
multiple threads?

You can increase the size of the pool by using the MongoOptions to set the 
connectionsPerHost higher.

The driver is open source and patches are accepted, sometimes :)

Original comment by scotthernandez on 22 Apr 2011 at 12:12