From 2563dd8d437a995e47bf6fbbb9ff391068923a89 Mon Sep 17 00:00:00 2001 From: Burak Serdar Date: Wed, 21 Jun 2017 23:14:03 -0600 Subject: [PATCH 1/2] If streaming, don't compute result set size --- .../lightblue/mongo/crud/BasicDocFinder.java | 55 ++++++++++++------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/mongo/src/main/java/com/redhat/lightblue/mongo/crud/BasicDocFinder.java b/mongo/src/main/java/com/redhat/lightblue/mongo/crud/BasicDocFinder.java index b9662ebc0..be21c70e0 100644 --- a/mongo/src/main/java/com/redhat/lightblue/mongo/crud/BasicDocFinder.java +++ b/mongo/src/main/java/com/redhat/lightblue/mongo/crud/BasicDocFinder.java @@ -85,7 +85,7 @@ public long find(CRUDOperationContext ctx, cursor.setReadPreference(readPreference); } - if (maxQueryTimeMS > 0) { + if (maxQueryTimeMS > 0&&ctx.isLimitQueryTime()) { cursor.maxTime(maxQueryTimeMS, TimeUnit.MILLISECONDS); } @@ -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.isComputeMatchCount()) { + 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(t0) { - 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()numMatched) { + nRetrieve=numMatched-f+1; + } + } + cursor.limit(nRetrieve); + } + } else { + cursor.skip(f); + if(ctx.isComputeMatchCount()) { + nRetrieve=numMatched-f+1; + } + } + if(!empty) { + if (ctx.isComputeMatchCount() && 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 { @@ -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 { From 5629a4cd991b245d8bfacca2d6deec5628524591 Mon Sep 17 00:00:00 2001 From: Burak Serdar Date: Thu, 22 Jun 2017 10:01:47 -0600 Subject: [PATCH 2/2] Rename flag --- .../com/redhat/lightblue/mongo/crud/BasicDocFinder.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mongo/src/main/java/com/redhat/lightblue/mongo/crud/BasicDocFinder.java b/mongo/src/main/java/com/redhat/lightblue/mongo/crud/BasicDocFinder.java index be21c70e0..af8d32cc6 100644 --- a/mongo/src/main/java/com/redhat/lightblue/mongo/crud/BasicDocFinder.java +++ b/mongo/src/main/java/com/redhat/lightblue/mongo/crud/BasicDocFinder.java @@ -99,7 +99,7 @@ public long find(CRUDOperationContext ctx, int numMatched=0; int nRetrieve=0; - if(ctx.isComputeMatchCount()) { + if(ctx.isComputeCounts()) { numMatched = cursor.count(); } @@ -116,7 +116,7 @@ public long find(CRUDOperationContext ctx, } else { cursor.skip(f); nRetrieve=to.intValue()-f+1; - if(ctx.isComputeMatchCount()) { + if(ctx.isComputeCounts()) { if(to.intValue()>numMatched) { nRetrieve=numMatched-f+1; } @@ -125,12 +125,12 @@ public long find(CRUDOperationContext ctx, } } else { cursor.skip(f); - if(ctx.isComputeMatchCount()) { + if(ctx.isComputeCounts()) { nRetrieve=numMatched-f+1; } } if(!empty) { - if (ctx.isComputeMatchCount() && maxResultSetSize > 0 && nRetrieve > maxResultSetSize) { + 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));