Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit 7506ca4

Browse files
author
Hideki Itakura
authored
Merge pull request #94 from couchbaselabs/issue/jc/1591
Fixed Java Core 1591 - Additional Fix for Java Core 1585
2 parents e18fd07 + 3709786 commit 7506ca4

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

src/main/java/com/couchbase/lite/store/ForestDBStore.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)