def updateSystemConfig(self, gpArray, textForConfigTable, dbIdToForceMirrorRemoveAdd, useUtilityMode, allowPrimary):
        """
        Update the configuration for the given segments in the underlying
        configuration store to match the current values
    
        Also resets any dirty bits on saved/updated objects

        @param textForConfigTable label to be used when adding to segment configuration history
        @param dbIdToForceMirrorRemoveAdd a map of dbid -> True for mirrors for which we should force updating the mirror
        @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)
        """

        # ensure initializeProvider() was called
        checkNotNone("masterDbUrl", self.__masterDbUrl)

        logger.debug("Validating configuration changes...")

        if not gpArray.is_array_valid():
            logger.critical("Configuration is invalid")
            raise InvalidSegmentConfiguration(gpArray)

        conn = dbconn.connect(self.__masterDbUrl, useUtilityMode, allowSystemTableMods="dml")
        dbconn.execSQL(conn, "BEGIN")

        # compute what needs to be updated
        update = ComputeCatalogUpdate(gpArray, dbIdToForceMirrorRemoveAdd, useUtilityMode, allowPrimary)
        update.validate()

        # put the mirrors in a map by content id so we can update them later
        mirror_map = {}
        for seg in update.mirror_to_add:
            mirror_map[seg.getSegmentContentId()] = seg

        # reset dbId of new primary and mirror segments to -1
        # before invoking the operations which will assign them new ids
        for seg in update.primary_to_add:
            seg.setSegmentDbId(-1)
        for seg in update.mirror_to_add:
            seg.setSegmentDbId(-1)

        # remove mirror segments (e.g. for gpexpand rollback)
        for seg in update.mirror_to_remove:
            self.__updateSystemConfigRemoveMirror(conn, seg, textForConfigTable)

        # remove primary segments (e.g for gpexpand rollback)
        for seg in update.primary_to_remove:
            self.__updateSystemConfigRemovePrimary(conn, seg, textForConfigTable)

        # add new primary segments
        for seg in update.primary_to_add:
            self.__updateSystemConfigAddPrimary(conn, gpArray, seg, textForConfigTable, mirror_map)

        # add new mirror segments
        for seg in update.mirror_to_add:
            self.__updateSystemConfigAddMirror(conn, gpArray, seg, textForConfigTable)

        # remove and add mirror segments necessitated by catalog attribute update
        for seg in update.mirror_to_remove_and_add:
            self.__updateSystemConfigRemoveAddMirror(conn, gpArray, seg, textForConfigTable)

        # apply updates to existing segments
        for seg in update.segment_to_update:
            originalSeg = update.dbsegmap.get(seg.getSegmentDbId())
            self.__updateSystemConfigUpdateSegment(conn, gpArray, seg, originalSeg, textForConfigTable)

        # apply update to fault strategy
        if gpArray.getStrategyAsLoadedFromDb() != gpArray.getFaultStrategy():
            self.__updateSystemConfigFaultStrategy(conn, gpArray)

        # commit changes
        logger.debug("Committing configuration table changes")
        dbconn.execSQL(conn, "COMMIT")
        conn.close()

        gpArray.setStrategyAsLoadedFromDb([gpArray.getFaultStrategy()])
        gpArray.setSegmentsAsLoadedFromDb([seg.copy() for seg in gpArray.getDbList()])
Example #2
0
    def updateSystemConfig(self, gpArray, textForConfigTable,
                           dbIdToForceMirrorRemoveAdd, useUtilityMode,
                           allowPrimary):
        """
        Update the configuration for the given segments in the underlying
        configuration store to match the current values

        Also resets any dirty bits on saved/updated objects

        @param textForConfigTable label to be used when adding to segment configuration history
        @param dbIdToForceMirrorRemoveAdd a map of dbid -> True for mirrors for which we should force updating the mirror
        @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)
        """

        # ensure initializeProvider() was called
        checkNotNone("masterDbUrl", self.__masterDbUrl)

        logger.debug("Validating configuration changes...")

        if not gpArray.is_array_valid():
            logger.critical("Configuration is invalid")
            raise InvalidSegmentConfiguration(gpArray)

        conn = dbconn.connect(self.__masterDbUrl,
                              useUtilityMode,
                              allowSystemTableMods=True)
        dbconn.execSQL(conn, "BEGIN")

        # compute what needs to be updated
        update = ComputeCatalogUpdate(gpArray, dbIdToForceMirrorRemoveAdd,
                                      useUtilityMode, allowPrimary)
        update.validate()

        # put the mirrors in a map by content id so we can update them later
        mirror_map = {}
        for seg in update.mirror_to_add:
            mirror_map[seg.getSegmentContentId()] = seg

        # remove mirror segments (e.g. for gpexpand rollback)
        for seg in update.mirror_to_remove:
            self.__updateSystemConfigRemoveMirror(conn, seg,
                                                  textForConfigTable)

        # remove primary segments (e.g for gpexpand rollback)
        for seg in update.primary_to_remove:
            self.__updateSystemConfigRemovePrimary(conn, seg,
                                                   textForConfigTable)

        # add new primary segments
        for seg in update.primary_to_add:
            self.__updateSystemConfigAddPrimary(conn, gpArray, seg,
                                                textForConfigTable, mirror_map)

        # add new mirror segments
        for seg in update.mirror_to_add:
            self.__updateSystemConfigAddMirror(conn, gpArray, seg,
                                               textForConfigTable)

        # remove and add mirror segments necessitated by catalog attribute update
        for seg in update.mirror_to_remove_and_add:
            self.__updateSystemConfigRemoveAddMirror(conn, gpArray, seg,
                                                     textForConfigTable)

        # apply updates to existing segments
        for seg in update.segment_to_update:
            originalSeg = update.dbsegmap.get(seg.getSegmentDbId())
            self.__updateSystemConfigUpdateSegment(conn, gpArray, seg,
                                                   originalSeg,
                                                   textForConfigTable)

        # commit changes
        logger.debug("Committing configuration table changes")
        dbconn.execSQL(conn, "COMMIT")
        conn.close()

        gpArray.setSegmentsAsLoadedFromDb(
            [seg.copy() for seg in gpArray.getDbList()])