google-code-export / morphia

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

mapReduce conflicts with multiple threads #390

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Using Morphia 0.99, I am doing a mapReduce like this:

    final MapreduceResults<ResultEntity> mrRes;
    try {
      mrRes = ds.mapReduce(MapreduceType.REPLACE, query, map, reduce, null, initial, ResultEntity.class);
    } catch (MongoException e) {
      throw new RuntimeException("Error querying with conditions: " + query, e);
    }

and with:

  @Entity(value = "wfh-results", noClassnameStored = true)
  private static class ResultEntity extends ResultBase<String, Double> {

  }

However, when this gets run concurrently from multiple threads the results get 
overwritten. I remember seeing some temporary collections named like 
"tmp.mr.COLLNAME_SOMENUMBER_inc" but haven't seen any for this collection.

Original issue reported on code.google.com by nic%tran...@gtempaccount.com on 17 Mar 2012 at 11:09

GoogleCodeExporter commented 9 years ago
This is a server issue. If you run concurrent map/reduce operations with the 
same destination only the last one will be valid when they have all finished. 
In the mean time what data you get back is undefined and dependent on the 
timing of the concurrent operations.

Please file a mongodb jira server issue: http://jira.mongodb.org/

Original comment by scotthernandez on 17 Mar 2012 at 1:38

GoogleCodeExporter commented 9 years ago
Hmm... ok. I guess the server-side is by design? Inline is not part of Morphia, 
yet, right? But I could instead do:

    MapReduceCommand cmd = new MapReduceCommand(dbColl, map, reduce, null,
            MapReduceCommand.OutputType.INLINE, qi.getQueryObject());

myself and avoid the problem that way?

Original comment by nic%tran...@gtempaccount.com on 17 Mar 2012 at 5:43

GoogleCodeExporter commented 9 years ago
Yes, inline will work as long as you have less than 16MB of data returned. 

Original comment by scotthernandez on 17 Mar 2012 at 5:55