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

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Won't Fix
    • Priority: Minor - P4
    • None
    • Affects Version/s: 3.0.0
    • Component/s: Replication, Shell
    • None
    • ALL
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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.

      Unable to find source-code formatter for language: diff. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      --- 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);
      

            Assignee:
            DO NOT USE - Backlog - Platform Team
            Reporter:
            Kevin Pulo
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: