Пример #1
0
 def check_database_stopped(self):
     try:
         mode = get_local_db_mode(MASTER_DATA_DIR)
         logger.info('Database was started in %s mode' % mode)
     except Exception, e:
         logger.info('Database might already be stopped.')
         return True
Пример #2
0
 def check_database_stopped(self):
     try:
         mode = get_local_db_mode(MASTER_DATA_DIR)
         logger.info('Database was started in %s mode' % mode)
     except Exception, e:
         logger.info('Database might already be stopped.')
         return True 
    def loadSystemConfig(self, useUtilityMode):
        """
        Load all segment information from the configuration source.

        Returns a new GpArray object
        """

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

        logger.info("Obtaining Segment details from master...")

        array = GpArray.initFromCatalog(self.__masterDbUrl, useUtilityMode)

        if get_local_db_mode(array.master.getSegmentDataDirectory()) != "UTILITY":
            logger.debug("Validating configuration...")
            if not array.is_array_valid():
                raise InvalidSegmentConfiguration(array)

        return array
Пример #4
0
    def loadSystemConfig( self, useUtilityMode ) :
        """
        Load all segment information from the configuration source.

        Returns a new GpArray object
        """

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

        logger.info("Obtaining Segment details from master...")

        array = GpArray.initFromCatalog(self.__masterDbUrl, useUtilityMode)
        
        if get_local_db_mode(array.master.getSegmentDataDirectory()) != 'UTILITY':
            logger.debug("Validating configuration...")
            if not array.is_array_valid():
                raise InvalidSegmentConfiguration(array)
            
        return array
Пример #5
0
    def execute(self):

        try:
            # Disable Ctrl+C
            signal.signal(signal.SIGINT, signal.SIG_IGN)

            # StopGPDB - Check for GPDB connections first and fail if connections exist
            if not self.check_database_stopped():
                self.stop_database()

            # StartGPDB in Master only mode
            self.start_master_only()

            try:

                if not CheckSuperUser(
                        dbconn.DbURL(username=self.user,
                                     password=self.pswd)).run():
                    raise MoveFilespaceError(
                        'gpfilespace requires database superuser privileges.')

                gparray = GpArray.initFromCatalog(dbconn.DbURL(), utility=True)

                # CheckFilespace - Check if new filespace exists
                if not CheckFilespace(self.new_filespace_name).run():
                    raise MoveFilespaceError('Filespace %s does not exist' %
                                             self.new_filespace_name)

                    # CheckFilespaceIsSame - Check if filespace is different from the old one
                if CheckFilespaceIsSame(gparray, self.new_filespace_name,
                                        self.file_type).run():
                    raise MoveFilespaceError(
                        'Filespace %s is same as the current filespace' %
                        self.new_filespace_name)
            except Exception, e:
                # Bring GPDB Offline
                self.stop_master_only()
                # Restart the database
                self.start_database()
                raise

            # Bring GPDB Offline
            if 'UTILITY' == get_local_db_mode(MASTER_DATA_DIR):
                self.stop_master_only()
            else:
                raise MoveFilespaceError('Database state is invalid.')

            if not CheckConnectivity(gparray).run():
                raise MoveFilespaceError('Failed connectivity test')

            logger.info('Obtaining current filespace information')
            # Find the filespace directory used for each segment
            # query using pg_filespace, pg_filespace_entry, gp_segment_configuration
            # If gp_transaction/temporary flat files exist and is not empty, then we know
            # the filespace being used. Otherwise, we assume that it is the pg_system
            # filespace by default

            cur_filespace_entries = GetFilespaceEntriesDict(
                GetCurrentFilespaceEntries(gparray,
                                           self.file_type).run()).run()
            new_filespace_entries = GetFilespaceEntriesDict(
                GetFilespaceEntries(gparray,
                                    self.new_filespace_name).run()).run()
            pg_system_filespace_entries = GetFilespaceEntriesDict(
                GetFilespaceEntries(gparray, PG_SYSTEM_FILESPACE).run()).run()

            cur_filespace_name = gparray.getFileSpaceName(
                int(cur_filespace_entries[1][0]))

            logger.info('Obtaining segment information ...')
            segments = gparray.getDbList()

            # MoveTemp/Trans files

            try:
                operations = GetMoveOperationList(
                    segments, self.file_type, self.new_filespace_name,
                    new_filespace_entries, cur_filespace_entries,
                    pg_system_filespace_entries).run()
            except Exception, e:
                raise MoveFilespaceError(
                    'Failed to create operations list. %s' % str(e))
Пример #6
0
    def execute(self):

        try:
            #Disable Ctrl+C
            signal.signal(signal.SIGINT,signal.SIG_IGN)
    
            #StopGPDB - Check for GPDB connections first and fail if connections exist
            if not self.check_database_stopped():
                self.stop_database()

            #StartGPDB in Master only mode
            self.start_master_only()

            try:
                
                if not CheckSuperUser(dbconn.DbURL(username=self.user, password=self.pswd)).run():
                    raise MoveFilespaceError('gpfilespace requires database superuser privileges.')  
                
                gparray = GpArray.initFromCatalog(dbconn.DbURL(), utility=True)

                #CheckFilespace - Check if new filespace exists
                if not CheckFilespace(self.new_filespace_name).run():
                    raise MoveFilespaceError('Filespace %s does not exist' % self.new_filespace_name) 

                #CheckFilespaceIsSame - Check if filespace is different from the old one
                if CheckFilespaceIsSame(gparray, self.new_filespace_name, self.file_type).run():
                    raise MoveFilespaceError('Filespace %s is same as the current filespace' % self.new_filespace_name)
            except Exception, e:
                #Bring GPDB Offline
                self.stop_master_only()
                #Restart the database
                self.start_database()                 
                raise

            #Bring GPDB Offline
            if 'UTILITY' == get_local_db_mode(MASTER_DATA_DIR):
                self.stop_master_only()
            else:
                raise MoveFilespaceError('Database state is invalid.')

            if not CheckConnectivity(gparray).run():
                raise MoveFilespaceError('Failed connectivity test') 
 
            logger.info('Obtaining current filespace information')
            #Find the filespace directory used for each segment
            #query using pg_filespace, pg_filespace_entry, gp_segment_configuration
            #If gp_transaction/temporary flat files exist and is not empty, then we know 
            #the filespace being used. Otherwise, we assume that it is the pg_system 
            #filespace by default 

            cur_filespace_entries = GetFilespaceEntriesDict(GetCurrentFilespaceEntries(gparray,
                                                                               self.file_type).run()).run()
            new_filespace_entries = GetFilespaceEntriesDict(GetFilespaceEntries(gparray,
                                                                        self.new_filespace_name).run()).run()
            pg_system_filespace_entries = GetFilespaceEntriesDict(GetFilespaceEntries(gparray,
                                                                              PG_SYSTEM_FILESPACE).run()).run()
 
            cur_filespace_name = gparray.getFileSpaceName(int(cur_filespace_entries[1][0]))

            logger.info('Obtaining segment information ...')
            segments = gparray.getDbList() 

            #MoveTemp/Trans files

            try:
                operations = GetMoveOperationList(segments,
                                                  self.file_type,
                                                  self.new_filespace_name,
                                                  new_filespace_entries,
                                                  cur_filespace_entries,
                                                  pg_system_filespace_entries
                                                 ).run()
            except Exception, e:
                raise MoveFilespaceError('Failed to create operations list. %s' % str(e))