Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-20998

db.printReplicationInfo() in 3.0 shell is not compatible with 2.6 or earlier servers

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Minor - P4 Minor - P4
    • None
    • 3.0.0
    • Replication, Shell
    • None
    • ALL

    Description

      With a 2.6 shell:

      > db.printReplicationInfo()
      configured oplog size:   10MB
      log length start to end: 0secs (0hrs)
      oplog first event time:  Mon Oct 19 2015 09:47:48 GMT+1100 (AEDT)
      oplog last event time:   Mon Oct 19 2015 09:47:48 GMT+1100 (AEDT)
      now:                     Mon Oct 19 2015 10:25:53 GMT+1100 (AEDT)
      

      With a 3.0+ shell:

      > db.printReplicationInfo()
      {
              "errmsg" : "Could not get stats for local.oplog.rs collection. collstats returned: {\n\t\"ns\" : \"local.oplog.rs\",\n\t\"count\" : 1,\n\t\"size\" : 88,\n\t\"avgObjSize\" : 88,\n\t\"storageSize\" : 10485760,\n\t\"numExtents\" : 1,\n\t\"nindexes\" : 0,\n\t\"lastExtentSize\" : 10485760,\n\t\"paddingFactor\" : 1,\n\t\"systemFlags\" : 0,\n\t\"userFlags\" : 0,\n\t\"totalIndexSize\" : 0,\n\t\"indexSizes\" : {\n\t\t\n\t},\n\t\"capped\" : true,\n\t\"max\" : NumberLong(\"9223372036854775807\"),\n\t\"ok\" : 1\n}"
      }
      

      Root cause is that inside db.getReplicationInfo(), the maxSize field returned by collstats is used to determine the size of the oplog. However, this field does not exist in the result of collstats in versions before 3.0. (In the 2.6 shell, the code checks options.size returned from a find on system.namespaces, which is of course no good in 3.0+.)

      The simplest fix would be to fallback to storageSize (if capped is true) when maxSize isn't present.

      --- a/src/mongo/shell/db.js
      +++ b/src/mongo/shell/db.js
      @@ -876,6 +876,8 @@ DB.prototype.getReplicationInfo = function() {
           var ol_stats = ol.stats();
           if( ol_stats && ol_stats.maxSize ) {
               result.logSizeMB = ol_stats.maxSize / ( 1024 * 1024 );
      +    } else if( ol_stats && ol_stats.capped && ol_stats.storageSize ) {
      +        result.logSizeMB = ol_stats.storageSize / ( 1024 * 1024 );
           } else {
               result.errmsg  = "Could not get stats for local."+oplog+" collection. " +
                   "collstats returned: " + tojson(ol_stats);
      

      Attachments

        Activity

          People

            backlog-server-platform DO NOT USE - Backlog - Platform Team
            kevin.pulo@mongodb.com Kevin Pulo
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: