@@ -653,26 +653,25 @@ public Map<String, Object> getAllDocs(QueryOptions options) throws CouchbaseLite
653653 iteratorFlags |= IteratorFlags .kIncludeDeleted ;
654654 int total = options .getKeys ().size ();
655655 int read = 0 ;
656- while (total > 0 ) {
657- int plan = Math .min (total , MAX_RECORDS_TO_READ_FROM_FORESTDB_AT_ONCE );
656+ while (total > read ) { // loop till consume all requested docIDs
657+ int plan = Math .min (total - read , MAX_RECORDS_TO_READ_FROM_FORESTDB_AT_ONCE );
658658 String [] docIDs = options .getKeys ().subList (read , read + plan ).toArray (new String [plan ]);
659659 try {
660660 DocumentIterator itr = forest .iterator (docIDs , iteratorFlags );
661661 try {
662662 List <QueryRow > retRows = readFromIterator (itr , options , includeDocs , filter , limit );
663663 rows .addAll (retRows );
664664 limit -= retRows .size ();
665- total -= retRows .size ();
666- read += retRows .size ();
665+ read += plan ; // number of attempted doc IDs as retRows.size() could be smaller than plan.
667666 } finally {
668667 if (itr != null )
669668 itr .close ();
670669 }
671670 } catch (ForestException e ) {
672671 if (e .domain == ForestDBDomain && e .code == FDB_RESULT_HANDLE_BUSY ) {
673- Log .w (TAG , "ForestDB handle is busy, retry it after 500ms . error=%s" , e .toString ());
672+ Log .w (TAG , "ForestDB handle is busy, retry it after 300ms . error=%s" , e .toString ());
674673 try {
675- Thread .sleep (500 ); // 500 ms
674+ Thread .sleep (300 ); // 300 ms
676675 } catch (InterruptedException ie ) {
677676 }
678677 continue ;
0 commit comments