Skip to content

Commit b688b5a

Browse files
author
Hideki Itakura
authored
Merge pull request #1583 from couchbase/fix/1581
Fixed #1581 - Replication failures when running Sync Gateway in distr…
2 parents 6808fce + 1bb36ad commit b688b5a

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/main/java/com/couchbase/lite/replicator/PullerInternal.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ private void queueDownloadedRevision(RevisionInternal rev) {
476476
// if queue memory size is more than maximum, force flush the queue.
477477
if (queuedMemorySize.get() > MAX_QUEUE_MEMORY_SIZE) {
478478
Log.d(TAG, "Flushing queued memory size at: " + queuedMemorySize);
479-
downloadsToInsert.flushAll(true);
479+
downloadsToInsert.flushAllAndWait();
480480
}
481481
}
482482

@@ -744,7 +744,7 @@ public void onCompletion(Response httpResponse, Object result, Throwable e) {
744744
// if queue memory size is more than maximum, force flush the queue.
745745
if (queuedMemorySize.get() > MAX_QUEUE_MEMORY_SIZE) {
746746
Log.d(TAG, "Flushing queued memory size at: " + queuedMemorySize);
747-
downloadsToInsert.flushAll(true);
747+
downloadsToInsert.flushAllAndWait();
748748
}
749749
}
750750

src/main/java/com/couchbase/lite/support/Batcher.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class Batcher<T> {
5353

5454
private final Object mutex = new Object();
5555
private final Object processMutex = new Object();
56+
private final Object flushAllMutext = new Object();
5657

5758
///////////////////////////////////////////////////////////////////////////
5859
// Constructors
@@ -161,6 +162,12 @@ public void queueObjects(List<T> objects) {
161162
}
162163
}
163164

165+
public void flushAllAndWait() {
166+
synchronized (flushAllMutext) {
167+
flushAll(true);
168+
}
169+
}
170+
164171
/**
165172
* Sends _all_ the queued objects at once to the processor block.
166173
* After this method returns, all inbox objects will be processed.

0 commit comments

Comments
 (0)