Skip to content

Commit 9fb2935

Browse files
committed
JAVA-1126: Fixed infinite loop in OrderedRunGenerator if write count > max write batch size
1 parent 1550273 commit 9fb2935

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/main/com/mongodb/DBCollectionImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ public Run next() {
570570
private int getStartIndexOfNextRun() {
571571
WriteRequest.Type type = writeRequests.get(curIndex).getType();
572572
for (int i = curIndex; i < writeRequests.size(); i++) {
573-
if (i == db.getConnector().getServerDescription(port.getAddress()).getMaxWriteBatchSize()
573+
if (i == curIndex + db.getConnector().getServerDescription(port.getAddress()).getMaxWriteBatchSize()
574574
|| writeRequests.get(i).getType() != type) {
575575
return i;
576576
}

src/test/com/mongodb/BulkWriteOperationSpecification.groovy

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,34 @@ class BulkWriteOperationSpecification extends FunctionalSpecification {
266266
collection.findOne(new BasicDBObject('_id', 8)) == new BasicDBObject('_id', 8)
267267
}
268268

269+
def 'should split ordered when the number of writes is larger than the match write batch size'() {
270+
given:
271+
def op = collection.initializeOrderedBulkOperation()
272+
(0..2000).each {
273+
op.insert(new BasicDBObject())
274+
}
275+
276+
when:
277+
op.execute()
278+
279+
then:
280+
collection.find().count() == 2001
281+
}
282+
283+
def 'should split unordered when the number of writes is larger than the match write batch size'() {
284+
given:
285+
def op = collection.initializeUnorderedBulkOperation()
286+
(0..2000).each {
287+
op.insert(new BasicDBObject())
288+
}
289+
290+
when:
291+
op.execute()
292+
293+
then:
294+
collection.find().count() == 2001
295+
296+
}
269297
def 'error details should have correct index on unordered write failure'() {
270298
given:
271299
collection.insert(getTestInserts())

0 commit comments

Comments
 (0)