Skip to content

Commit

Permalink
Fix #648: mloginfo: Add support for MongoDB 3.2+ --rsinfo (#650)
Browse files Browse the repository at this point in the history
  • Loading branch information
stennie authored and sindbach committed Jul 4, 2018
1 parent 0fe5080 commit 5bf5fb1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 29 deletions.
3 changes: 3 additions & 0 deletions mtools/mloginfo/sections/rs_info_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
1 change: 1 addition & 0 deletions mtools/test/logfiles/rsinfo_36.log
Original file line number Diff line number Diff line change
@@ -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') } }
26 changes: 0 additions & 26 deletions mtools/test/test_mloginfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
11 changes: 11 additions & 0 deletions mtools/test/test_util_logfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__),
Expand Down
16 changes: 13 additions & 3 deletions mtools/util/logfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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'
Expand All @@ -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<replSet>\S+)", '
'version: (?P<replSetVersion>\d+), '
'(protocolVersion: (?P<replSetProtocol>\d+), )?'
'members: (?P<replSetMembers>[^]]+ ])', 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
Expand Down

0 comments on commit 5bf5fb1

Please sign in to comment.