Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-1174

java heap out of memory when using tailable cursor

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Works as Designed
    • Affects Version/s: 2.11.2, 2.12.0
    • Fix Version/s: None
    • Component/s: Query Operations
    • Labels:
      None
    • Environment:
      java 1.6 and mongodb driver 2.11.2
    • # Replies:
      4
    • Last comment by Customer:
      false

      Description

      when I use this command to query the oplog of MongoDB, I got out of memory issue.

       cursor = oplogColl.find(query).sort(new BasicDBObject("$natural", 1)).addOption(Bytes.QUERYOPTION_TAILABLE).addOption(Bytes.QUERYOPTION_AWAITDATA);

      and through a iterator to get all operation logs.

      DBObject data = cursor.next();

      Exception description

      Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
              at java.util.Arrays.copyOf(Arrays.java:2734)
              at java.util.ArrayList.ensureCapacity(ArrayList.java:167)
              at java.util.ArrayList.add(ArrayList.java:351)
              at com.mongodb.DBApiLayer$Result.init(DBApiLayer.java:369)
              at com.mongodb.DBApiLayer$Result._advance(DBApiLayer.java:429)
              at com.mongodb.DBApiLayer$Result.hasNext(DBApiLayer.java:396)
              at com.mongodb.DBCursor._hasNext(DBCursor.java:464)
              at com.mongodb.DBCursor.hasNext(DBCursor.java:484)
              at com.patsnap.mongodb.dataload.MongoDbDataLoader.hasNext(MongoDbDataLoader.java:128)
              at com.patsnap.mongodb.dataload.MongoDbDataLoader.main(MongoDbDataLoader.java:86)

      the reason is that the size type is List<Integer>, It will become big enough if you iterator more data and eventually out of memory

      _sizes.add( res.size() );

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since reply:
                3 years, 40 weeks, 4 days ago
                Date of 1st Reply: