diff --git a/mtools/mloginfo/sections/rs_info_section.py b/mtools/mloginfo/sections/rs_info_section.py index b43785e0..bcc61b21 100644 --- a/mtools/mloginfo/sections/rs_info_section.py +++ b/mtools/mloginfo/sections/rs_info_section.py @@ -35,5 +35,8 @@ def run(self): print(" rs version: %s" % (self.mloginfo.logfile.repl_set_version if self.mloginfo.logfile.repl_set_version else "unknown")) + print("rs protocol: %s" + % (self.mloginfo.logfile.repl_set_protocol + if self.mloginfo.logfile.repl_set_protocol else "unknown")) else: print(" no rs info changes found") diff --git a/mtools/test/logfiles/rsinfo_36.log b/mtools/test/logfiles/rsinfo_36.log new file mode 100644 index 00000000..2def763e --- /dev/null +++ b/mtools/test/logfiles/rsinfo_36.log @@ -0,0 +1 @@ +2018-07-04T13:06:03.521+1000 I REPL [replexec-0] New replica set config in use: { _id: "replset", version: 1, protocolVersion: 1, members: [ { _id: 0, host: "localhost:27017", arbiterOnly: false, buildIndexes: true, hidden: false, priority: 1.0, tags: {}, slaveDelay: 0, votes: 1 }, { _id: 1, host: "localhost:27018", arbiterOnly: false, buildIndexes: true, hidden: false, priority: 1.0, tags: {}, slaveDelay: 0, votes: 1 }, { _id: 2, host: "localhost:27019", arbiterOnly: false, buildIndexes: true, hidden: false, priority: 1.0, tags: {}, slaveDelay: 0, votes: 1 } ], settings: { chainingAllowed: true, heartbeatIntervalMillis: 2000, heartbeatTimeoutSecs: 10, electionTimeoutMillis: 10000, catchUpTimeoutMillis: -1, catchUpTakeoverDelayMillis: 30000, getLastErrorModes: {}, getLastErrorDefaults: { w: 1, wtimeout: 0 }, replicaSetId: ObjectId('5b3c39990a36dcde5b8ad9d2') } } diff --git a/mtools/test/test_mloginfo.py b/mtools/test/test_mloginfo.py index 1796dedd..4db594e9 100644 --- a/mtools/test/test_mloginfo.py +++ b/mtools/test/test_mloginfo.py @@ -358,32 +358,6 @@ def test_rsinfo(self): 'rs version': 'unknown', 'rs members': rsmembers}) - def test_rsstate_26_2(self): - logfile_path = os.path.join(os.path.dirname(mtools.__file__), - 'test/logfiles/', 'mongod_26.log') - self._test_rsinfo(logfile_path, - **{'rs name': 'shard01', - 'rs version': '1', - 'rs members': ('[ { _id: 0, ' - 'host: "enter.local:27019" }, ' - '{ _id: 1, ' - 'host: "enter.local:27020" }, ' - '{ _id: 2, ' - 'host: "enter.local:27021" } ]')}) - - def test_rsstate_24(self): - logfile_path = os.path.join(os.path.dirname(mtools.__file__), - 'test/logfiles/', 'mongod-2411.log') - self._test_rsinfo(logfile_path, - **{'rs name': 'repl1', - 'rs version': 'unknown', - 'rs members': ('[ { host: "hostname.local:37018",' - ' _id: 0, votes: 1 }, ' - '{ host: "hostname.local:37019", ' - '_id: 1, votes: 1 }, { host: ' - '"hostname.local:37020", _id: 2, ' - 'arbiterOnly: true } ]')}) - def test_rsstate_mongos_2(self): logfile_path = os.path.join(os.path.dirname(mtools.__file__), 'test/logfiles/', 'mongos.log') diff --git a/mtools/test/test_util_logfile.py b/mtools/test/test_util_logfile.py index 67daebad..40f39a96 100644 --- a/mtools/test/test_util_logfile.py +++ b/mtools/test/test_util_logfile.py @@ -84,6 +84,17 @@ def test_storage_engine_detection(self): logfile = LogFile(wiredtiger) assert logfile.storage_engine == 'wiredTiger' + def test_rsinfo(self): + """LogFile: test if replication info is detected (MongoDB 3.2+) """ + + logfile_path = os.path.join(os.path.dirname(mtools.__file__), + 'test/logfiles/', 'rsinfo_36.log') + rslog = open(logfile_path, 'rb') + logfile = LogFile(rslog) + assert logfile.repl_set == 'replset' + assert logfile.repl_set_version == '1' + assert logfile.repl_set_protocol == '1' + def test_hostname_port(self): # mongod logfile_path = os.path.join(os.path.dirname(mtools.__file__), diff --git a/mtools/util/logfile.py b/mtools/util/logfile.py index ec7d418a..7b247cb1 100644 --- a/mtools/util/logfile.py +++ b/mtools/util/logfile.py @@ -35,6 +35,7 @@ def __init__(self, filehandle): self._repl_set = None self._repl_set_members = None self._repl_set_version = None + self._repl_set_protocol = None self._storage_engine = None @@ -191,6 +192,13 @@ def repl_set_version(self): self._iterate_lines() return self._repl_set_version + @property + def repl_set_protocol(self): + """Return the replSet protocolVersion (if available).""" + if not self._num_lines: + self._iterate_lines() + return self._repl_set_protocol + @property def storage_engine(self): """Return storage engine if available.""" @@ -311,7 +319,7 @@ def _iterate_lines(self): """ For 3.2 the "[initandlisten] options:" no longer contains the "engine" field So now we have to look for the "[initandlisten] wiredtiger_open config:" which was present in 3.0, but would - now tell us definatively that wiredTiger is being used + now tell us definitively that wiredTiger is being used """ if "[initandlisten] wiredtiger_open config:" in line: self._storage_engine = 'wiredTiger' @@ -323,15 +331,17 @@ def _iterate_lines(self): self._repl_set = match.group('replSet') self._repl_set_members = match.group('replSetMembers') - new_config = ("replSet info saving a newer config version " - "to local.system.replset: ") + # Replica set config logging in MongoDB 3.0+ + new_config = ("New replica set config in use: ") if new_config in line: match = re.search('{ _id: "(?P\S+)", ' 'version: (?P\d+), ' + '(protocolVersion: (?P\d+), )?' 'members: (?P[^]]+ ])', line) if match: self._repl_set = match.group('replSet') self._repl_set_members = match.group('replSetMembers') + self._repl_set_protocol = match.group('replSetProtocol') self._repl_set_version = match.group('replSetVersion') # if ("is now in state" in line and