[SERVER-20998] db.printReplicationInfo() in 3.0 shell is not compatible with 2.6 or earlier servers Created: 18/Oct/15  Updated: 24/Feb/17  Resolved: 24/Feb/17

Status: Closed
Project: Core Server
Component/s: Replication, Shell
Affects Version/s: 3.0.0
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Kevin Pulo Assignee: DO NOT USE - Backlog - Platform Team
Resolution: Won't Fix Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 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);



 Comments   
Comment by Justin Cohler [ 24/Feb/17 ]

The 2.6 server is now EOL. We're not planning on adding any backward compatibility code for this.

Generated at Thu Feb 08 03:55:56 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.