in automation/tinc/main/ext/qautils/gppylib/programs/clsSystemState.py [0:0]
def __showSummaryOfSegmentsWhichRequireAttention(self, gpEnv, gpArray):
"""
Prints out the current status of the cluster.
@param gpEnv the GpMasterEnvironment object
@param gpArray the array to display
returns the exit code
"""
exitCode = 0
if gpArray.getFaultStrategy() != gparray.FAULT_STRATEGY_FILE_REPLICATION:
logger.info("Physical mirroring is not configured")
return 1
primarySegments = [ seg for seg in gpArray.getSegDbList() if seg.isSegmentPrimary(current_role=True) ]
mirrorSegments = [ seg for seg in gpArray.getSegDbList() if seg.isSegmentMirror(current_role=True) ]
contentIdToMirror = GpArray.getSegmentsByContentId(mirrorSegments)
hasWarnings = False
hostNameToResults = self.__fetchAllSegmentData(gpArray)
data = self.__buildGpStateData(gpArray, hostNameToResults)
def logSegments(segments, logAsPairs, additionalFieldsToLog=[]):
"""
helper function for logging a list of primaries, with their mirrors
@param logAsPairs if True, then segments should be primaries only, and we will log corresponding mirror datadir/port
@param additionalFieldsToLog should be a list of FieldDefinition objects
"""
tabLog = TableLogger().setWarnWithArrows(True)
for segment in segments:
if tabLog.getNumLines() == 0:
header = ["Current Primary" if logAsPairs else "Segment", "Port"]
header.extend([f.getShortLabel() for f in additionalFieldsToLog])
if logAsPairs:
header.extend(["Mirror", "Port"])
tabLog.info(header)
line = []
line.extend([segment.getSegmentAddress(), str(segment.getSegmentPort())])
for key in additionalFieldsToLog:
line.append(data.getStrValue(segment, key))
if logAsPairs:
mirror = contentIdToMirror[segment.getSegmentContentId()][0]
line.extend([mirror.getSegmentAddress(), str(mirror.getSegmentPort())])
tabLog.info(line)
tabLog.outputTable()
logger.info("----------------------------------------------------")
logger.info("Segment Mirroring Status Report")
# segment pairs that are in wrong roles
primariesInWrongRole = [s for s in gpArray.getSegDbList() if s.isSegmentPrimary(current_role=True) and \
not s.isSegmentPrimary(current_role=False)]
if primariesInWrongRole:
logger.info("----------------------------------------------------")
logger.info("Segments with Primary and Mirror Roles Switched")
logSegments(primariesInWrongRole, logAsPairs=True)
exitCode = 1
else:
pass # logger.info( "No segment pairs with switched roles")
# segment pairs that are in changetracking
primariesInChangeTracking = [s for s in gpArray.getSegDbList() if s.isSegmentPrimary(current_role=True) and \
s.isSegmentModeInChangeLogging()]
if primariesInChangeTracking:
logger.info("----------------------------------------------------")
logger.info("Primaries in Change Tracking")
logSegments(primariesInChangeTracking, logAsPairs=True, additionalFieldsToLog=[VALUE__CHANGE_TRACKING_DATA_SIZE])
exitCode = 1
else:
pass # logger.info( "No segment pairs are in change tracking")
# segments that are in resync
primariesInResync = [s for s in gpArray.getSegDbList() if s.isSegmentPrimary(current_role=True) and \
s.isSegmentModeInResynchronization()]
if primariesInResync:
logger.info("----------------------------------------------------")
logger.info("Segment Pairs in Resynchronization")
logSegments(primariesInResync, logAsPairs=True, additionalFieldsToLog=[VALUE__RESYNC_MODE, \
VALUE__RESYNC_EST_PROGRESS_WITH_MIRROR, VALUE__RESYNC_DATA_SYNCHRONIZED, \
VALUE__RESYNC_EST_TOTAL_DATA, VALUE__RESYNC_EST_COMPLETION_TIME, VALUE__CHANGE_TRACKING_DATA_SIZE])
exitCode = 1
else:
pass # logger.info( "No segment pairs are in resynchronization")
# segments that are down (excluding those that are part of changetracking)
changeTrackingMirrors = [contentIdToMirror[s.getSegmentContentId()][0] for s in primariesInChangeTracking]
changeTrackingMirrorsByDbId = GpArray.getSegmentsGroupedByValue(changeTrackingMirrors, gparray.GpDB.getSegmentDbId)
segmentsThatAreDown = [s for s in gpArray.getSegDbList() if \
not s.getSegmentDbId() in changeTrackingMirrorsByDbId and \
data.isSegmentProbablyDown(s)]
if segmentsThatAreDown:
logger.info("----------------------------------------------------")
logger.info("Downed Segments (this excludes mirrors whose primaries are in change tracking" )
logger.info(" -- these, if any, are reported separately above")
logger.info(" also, this may include segments where status could not be retrieved)")
logSegments(segmentsThatAreDown, False, [VALUE__MASTER_REPORTS_STATUS, VALUE__SEGMENT_STATUS])
exitCode = 1
else:
pass # logger.info( "No segments are down")
self.__addClusterDownWarning(gpArray, data)
# final output -- no errors, then log this message
if exitCode == 0:
logger.info("----------------------------------------------------")
logger.info("All segments are running normally")
return exitCode