in automation/tinc/main/ext/qautils/gppylib/system/ComputeCatalogUpdate.py [0:0]
def __init__(self, gpArray, forceMap, useUtilityMode, allowPrimary):
"""
This class just holds lists of objects in the underlying gpArray.
As such, it has no methods - the constructor does all the computation.
@param gpArray the array containing the goal and db segment states.
@param forceMap a map of dbid->True for mirrors for which we should force updating via remove/add
@param useUtilityMode True if the operations we're doing are expected to run via utility moed
@param allowPrimary True if caller authorizes add/remove primary operations (e.g. gpexpand)
"""
forceMap = forceMap or {}
self.useUtilityMode = useUtilityMode
self.allowPrimary = allowPrimary
# 'dbsegmap' reflects the current state of the catalog
self.dbsegmap = dict([(seg.getSegmentDbId(), seg) for seg in gpArray.getSegmentsAsLoadedFromDb()])
# 'goalsegmap' reflects the desired state of the catalog
self.goalsegmap = dict([(seg.getSegmentDbId(), seg) for seg in gpArray.getDbList(includeExpansionSegs=True)])
# find mirrors and primaries to remove
self.mirror_to_remove = [
seg for seg in self.dbsegmap.values() # segment in database
if seg.isSegmentMirror() # segment is a mirror
and (seg.getSegmentDbId() not in self.goalsegmap) # but not in goal configuration
]
self.debuglog("mirror_to_remove: %s", self.mirror_to_remove)
self.primary_to_remove = [
seg for seg in self.dbsegmap.values() # segment is database
if seg.isSegmentPrimary() # segment is a primary
and (seg.getSegmentDbId() not in self.goalsegmap) # but not in goal configuration
]
self.debuglog("primary_to_remove: %s", self.primary_to_remove)
# find primaries and mirrors to add
self.primary_to_add = [
seg for seg in self.goalsegmap.values() # segment in goal configuration
if seg.isSegmentPrimary() # segment is a primary
and (seg.getSegmentDbId() not in self.dbsegmap) # but not in the database
]
self.debuglog("primary_to_add: %s", self.primary_to_add)
self.mirror_to_add = [
seg for seg in self.goalsegmap.values() # segment in goal configuration
if seg.isSegmentMirror() # segment is a mirror
and (seg.getSegmentDbId() not in self.dbsegmap) # but not in the database
]
self.debuglog("mirror_to_add: %s", self.mirror_to_add)
# find segments to update
initial_segment_to_update = [
seg for seg in self.goalsegmap.values() # segment in goal configuration
if (seg.getSegmentDbId() in self.dbsegmap) # and also in the database
and (seg != self.dbsegmap[ seg.getSegmentDbId() ]) # but some attributes differ
]
self.debuglog("initial_segment_to_update: %s", initial_segment_to_update)
# create a map of the segments which we can't update in the
# ordinary way either because they were on the forceMap or
# they differ in an attribute other than mode, status or replication port
removeandaddmap = {}
for seg in initial_segment_to_update:
dbid = seg.getSegmentDbId()
if dbid in forceMap:
removeandaddmap[dbid] = seg
continue
if not seg.equalIgnoringModeAndStatusAndReplicationPort(self.dbsegmap[dbid]):
removeandaddmap[dbid] = seg
continue
# create list of mirrors to update via remove/add
self.mirror_to_remove_and_add = [seg for seg in removeandaddmap.values()]
self.debuglog("mirror_to_remove_and_add: %s", self.mirror_to_remove_and_add)
# find segments to update in the ordinary way
self.segment_to_update = [
seg for seg in initial_segment_to_update # segments to update
if seg.getSegmentDbId() not in removeandaddmap # that don't require remove/add
]
self.debuglog("segment_to_update: %s", self.segment_to_update)
# find segments that don't need change
self.segment_unchanged = [
seg for seg in self.goalsegmap.values() # segment in goal configuration
if (seg.getSegmentDbId() in self.dbsegmap) # and also in the database
and (seg == self.dbsegmap[ seg.getSegmentDbId() ]) # and attribtutes are all the same
]
self.debuglog("segment_unchanged: %s", self.segment_unchanged)