in automation/tinc/main/ext/qautils/gppylib/gparray.py [0:0]
def isStandardArray(self):
"""
This method will check various aspects of the array to see if it looks like a standard
setup. It returns two values:
True or False depending on if the array looks like a standard array.
If message if the array does not look like a standard array.
"""
try:
# Do all the segments contain the same number of primary and mirrors.
firstNumPrimaries = 0
firstNumMirrors = 0
firstHost = ""
first = True
dbList = self.getDbList(includeExpansionSegs = True)
gpdbByHost = self.getSegmentsByHostName(dbList)
for host in gpdbByHost:
gpdbList = gpdbByHost[host]
if len(gpdbList) == 1 and gpdbList[0].isSegmentQD() == True:
# This host has one master segment and nothing else
continue
if len(gpdbList) == 2 and gpdbList[0].isSegmentQD() and gpdbList[1].isSegmentQD():
# This host has the master segment and its mirror and nothing else
continue
numPrimaries = 0
numMirrors = 0
for gpdb in gpdbList:
if gpdb.isSegmentQD() == True:
continue
if gpdb.isSegmentPrimary() == True:
numPrimaries = numPrimaries + 1
else:
numMirrors = numMirrors + 1
if first == True:
firstNumPrimaries = numPrimaries
firstNumMirrors = numMirrors
firstHost = host
first = False
if numPrimaries != firstNumPrimaries:
raise Exception("The number of primary segments is not consistent across all nodes: %s != %s." % (host, firstHost))
elif numMirrors != firstNumMirrors:
raise Exception("The number of mirror segments is not consistent across all nodes. %s != %s." % (host, firstHost))
# Make sure the address all have the same suffix "-<n>" (like -1, -2, -3...)
firstSuffixList = []
first = True
suffixList = []
for host in gpdbByHost:
gpdbList = gpdbByHost[host]
for gpdb in gpdbList:
if gpdb.isSegmentMaster() == True:
continue
address = gpdb.getSegmentAddress()
if address == host:
if len(suffixList) == 0:
continue
else:
raise Exception("The address value for %s is the same as the host name, but other addresses on the host are not." % address)
suffix = address.split('-')[-1]
if suffix.isdigit() == False:
raise Exception("The address value for %s does not correspond to a standard address." % address)
suffixList.append(suffix)
suffixList.sort()
if first == True:
firstSuffixList = suffixList
first = False
if suffixList != firstSuffixList:
raise Exception("The address list for %s doesn't not have the same pattern as %s." % (str(suffixList), str(firstSuffixList)))
except Exception, e:
# Assume any exception implies a non-standard array
return False, str(e)
return True, ""