Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public long find(CRUDOperationContext ctx,
cursor.setReadPreference(readPreference);
}

if (maxQueryTimeMS > 0) {
if (maxQueryTimeMS > 0&&ctx.isLimitQueryTime()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this new isLimitQueryTime flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added that thinking with streaming, there is no need, but that will still be useful if you submit a long running query, so it is there just in case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still don't know why maxQueryTimeMS is not enough in streaming context.

cursor.maxTime(maxQueryTimeMS, TimeUnit.MILLISECONDS);
}

Expand All @@ -96,33 +96,48 @@ public long find(CRUDOperationContext ctx,
cursor = cursor.sort(mongoSort);
LOGGER.debug("Result set sorted");
}
int numMatched = cursor.count();
int nRetrieve=numMatched;

int numMatched=0;
int nRetrieve=0;
if(ctx.isComputeCounts()) {
numMatched = cursor.count();
}

LOGGER.debug("Applying limits: {} - {}", from, to);

// f and t are from and to indexes, both inclusive
int f=from==null?0:from.intValue();
int t=to==null?numMatched-1:to.intValue();
if(f<0)
f=0;
if(t>=numMatched)
t=numMatched-1;
if(t<f)
nRetrieve=0;

if(nRetrieve>0) {
nRetrieve=t-f+1;
cursor.skip(f);
cursor.limit(nRetrieve);
if (maxResultSetSize > 0 && nRetrieve > maxResultSetSize) {
int f=from==null?0:from.intValue();
if(f<0)
f=0;

boolean empty=false;
if(to!=null) {
if(to.intValue()<f) {
empty=true;
} else {
cursor.skip(f);
nRetrieve=to.intValue()-f+1;
if(ctx.isComputeCounts()) {
if(to.intValue()>numMatched) {
nRetrieve=numMatched-f+1;
}
}
cursor.limit(nRetrieve);
}
} else {
cursor.skip(f);
if(ctx.isComputeCounts()) {
nRetrieve=numMatched-f+1;
}
}
if(!empty) {
if (ctx.isComputeCounts() && maxResultSetSize > 0 && nRetrieve > maxResultSetSize) {
LOGGER.warn("Too many results:{} of {}", nRetrieve, numMatched);
RESULTSET_LOGGER.debug("resultset_size={}, requested={}, query={}", numMatched, nRetrieve, mongoQuery);
throw Error.get(MongoCrudConstants.ERR_TOO_MANY_RESULTS, Integer.toString(nRetrieve));
}

LOGGER.debug("Retrieving results");
CursorStream stream=new CursorStream(cursor,translator,mongoQuery,executionTime,f,t);
CursorStream stream=new CursorStream(cursor,translator,mongoQuery,executionTime,f,to==null?-1:to);
ctx.setDocumentStream(stream);
cursorInUse=true;
} else {
Expand All @@ -132,7 +147,7 @@ public long find(CRUDOperationContext ctx,
RESULTSET_LOGGER.debug("execution_time={}, query={}, from={}, to={}",
executionTime,
mongoQuery,
f, t);
from, to);
}
return numMatched;
} finally {
Expand Down