[JAVA-2925] cursor session issue Created: 13/Aug/18  Updated: 13/Aug/18  Resolved: 13/Aug/18

Status: Closed
Project: Java Driver
Component/s: Session Management
Affects Version/s: 3.6.4
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Yogesh VR Assignee: Ross Lawley
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

I am running an aggregate query using executeCommand with batch size and when I am fetching next batches getting the below exception,

Cursor session id (some-id1 - some-session-1) is not the same as the operation context's session id (some-id2 - some-session-1)

 

Mongodb version: 3.6.5

Mongodb java driver version: 3.6.4

 



 Comments   
Comment by Ross Lawley [ 13/Aug/18 ]

Hi yogeshvr,

Thank you for checking, I'm glad that upgrading the Server fixed the issue.

Closing as "Done" even thought this is a server issue and not a Java driver issue.

All the best,

Ross

Comment by Yogesh VR [ 13/Aug/18 ]

Hi  ross.lawley,

It is reproducible and upgrading MongoDB to 3.6.6 prevented it from happening.

String query = "mongo shell aggregate query that I want to run from java";
Document query_db = Document.parse(query);
Document result = MongoDBUtil.aggregateBatched(query_db, "collName", MongoDBUtil.RESULT_BATCH_SIZE, mongoTemplate, ReadPreference.secondaryPreferred());
 
// Below method is a minor customisation of the method taken from 
// org.springframework.data.mongodb.core.MongoTemplate.BatchAggregationLoader#aggregateBatched
public static Document aggregateBatched(Document command, String collectionName, int batchSize, MongoTemplate template, ReadPreference readPreference) {
	List<Document> results = new ArrayList<>();
	Document commandResult = template.executeCommand(command, readPreference);
	results.add(postProcessResult(commandResult));
	while (hasNext(commandResult)) {
		Document getMore = new Document("getMore", getNextBatchId(commandResult))
			.append("collection", collectionName)
			.append(BATCH_SIZE_FIELD, batchSize);
		commandResult = template.executeCommand(getMore, readPreference);
		results.add(postProcessResult(commandResult));
	}
	return mergeAggregationResults(results);
}

Thanks,
Yogesh VR

Comment by Ross Lawley [ 13/Aug/18 ]

Hi yogeshvr

Could you provide more information on how you are creating the error - is it reproducible? That error is a a server error message, when you say:

I am running an aggregate query using executeCommand with batch size

Could you provide some more information or example code?

This could potentially be related to SERVER-34810 which was fixed in MongoDB 3.6.6 - does upgrading to the latest 3.6 release prevent the issue from happening?

Ross

Generated at Thu Feb 08 08:58:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.