Exemple #1
0
    def execute(self):

        # if the filespace directory is not present on the segment,
        # We simply return.
        if not CheckDir(self.current_filespace_entry[2]).run():
            return

        tmp_file = os.path.join(self.new_filespace_entry[2], 'tmp_file')
        if not CheckFilespacePermissions(tmp_file).run():
            raise MoveFilespaceError('Invalid permissions for %s' % tmp_file)

        stats = os.statvfs(os.path.dirname(self.new_filespace_entry[2]))
        free_bytes = stats.f_bfree * stats.f_frsize
        logger.info('free_bytes for %s = %s' %
                    (self.new_filespace_entry[2], free_bytes))
        if not free_bytes:
            raise MoveFilespaceError('Insufficient diskspace for %s' %
                                     self.new_filespace_entry[2])

        # 1. Copy the contents of the filespace dirs from old filespace to new filespace
        for directory in self.TRANSACTION_FILES_DIRS:
            src_dir = os.path.join(self.current_filespace_entry[2], directory)
            dst_dir = os.path.join(self.new_filespace_entry[2], directory)

            logger.info('Copying directories from %s to %s' %
                        (src_dir, dst_dir))
            try:
                # In case of a rollback, we need to retain the directories that
                # already exist on the source segment. If it doesn't then we do a
                # copy.
                if self.rollback:
                    if CheckDir(src_dir).run() and not CheckDir(dst_dir).run():
                        logger.info('copying %s' % src_dir)
                        shutil.copytree(src_dir, dst_dir)
                        try:
                            self.sha256_check(src_dir, dst_dir)
                        except (IOError, OSError), e:
                            raise MoveFilespaceError(
                                'Failed to calculate sha256 checksums !')
                elif CheckDir(src_dir).run():
                    # We use the src segment as the source of truth and copy everything
                    if CheckDir(dst_dir).run():
                        shutil.rmtree(dst_dir)

                    logger.info('copying %s' % src_dir)
                    shutil.copytree(src_dir, dst_dir)

                    try:
                        self.sha256_check(src_dir, dst_dir)
                    except (IOError, OSError), e:
                        raise MoveFilespaceError(
                            'Failed to calculate sha256 checksums !')
Exemple #2
0
    def execute(self):

        if not CheckDir(self.current_filespace_entry[2]).run():
            return

        tmp_file = os.path.join(self.new_filespace_entry[2], 'tmp_file')
        if not CheckFilespacePermissions(tmp_file).run():
            raise MoveFilespaceError('Invalid permissions for %s' % tmp_file)

        stats = os.statvfs(os.path.dirname(self.new_filespace_entry[2]))
        free_bytes = stats.f_bfree * stats.f_frsize
        logger.info('free_bytes for %s = %s' %
                    (self.new_filespace_entry[2], free_bytes))
        if not free_bytes:
            raise MoveFilespaceError('Insufficient diskspace for %s' %
                                     self.new_filespace_entry[2])

        # 1. Drop the directories from old filespace location
        # If the filespace is being moved from pg_system filespace
        # for temp files will be slightly different as they will be stored under
        # <filespace_dir>/base/<database_oid>/
        gp_temporary_files_filespace_path = os.path.join(
            self.pg_system_filespace_entry[2], GP_TEMPORARY_FILES_FILESPACE)

        if not CheckFile(gp_temporary_files_filespace_path).run():
            base_dir = os.path.join(self.current_filespace_entry[2], 'base')

            directories = []
            try:
                directories = ListFiles(base_dir).run()
            except Exception, e:
                if self.rollback:
                    pass
                else:
                    raise

            for directory in directories:
                try:
                    dst_dir = os.path.join(base_dir, directory,
                                           self.TEMPORARY_FILES_DIR)
                    if CheckDir(dst_dir).run():
                        logger.info('Dropping dir %s' % dst_dir)
                        shutil.rmtree(dst_dir)
                except (IOError, OSError), e:
                    logger.error('Failed to delete temporary files')
                    raise
Exemple #3
0
 def execute(self):
     path = os.path.join(self.dir, DUMP_DIR, DUMP_DATE)
     exists = CheckDir(path).run()
     if exists:
         logger.info("Directory %s exists" % path)
     else:
         logger.info("Directory %s not found, will try to create" % path)
         try:
             MakeDir(path).run()
         except OSError, e:
             logger.exception("Could not create directory %s" % path)
             raise DumpDirCreateFailed()
         else:
Exemple #4
0
    def execute(self):
        logger.info('Gathering results of verification %s...' % self.token)
        to_gather = ValidateVerification(content=self.content,
                                         primaries_only=False).run()

        dest_base = os.path.join(self.master_datadir, 'pg_verify', self.token)
        if CheckDir(dest_base).run():
            # TODO: if end user has mucked around with artifacts on master, a regathering may
            # be needed; perhaps, a --force option to accompany --results?
            return
        MakeDir(dest_base).run()

        pool = WorkerPool(min(len(to_gather), self.batch_default))
        for seg in to_gather:
            host = seg.getSegmentHostName()
            content = seg.getSegmentContentId()
            role = seg.getSegmentRole()
            src = os.path.join(seg.getSegmentDataDirectory(), "pg_verify",
                               "*%s*" % self.token)

            dest = os.path.join(dest_base, str(content), str(role))
            MakeDir(dest).run()
            cmd = Scp('consolidate', srcFile=src, srcHost=host, dstFile=dest)
            pool.addCommand(cmd)

        logger.info('Waiting for scp commands to complete...')
        pool.wait_and_printdots(len(to_gather))
        pool.check_results()

        dest = os.path.join(dest_base, 'verification_%s.fix' % self.token)
        with open(dest, 'w') as output:
            for seg in to_gather:
                content = seg.getSegmentContentId()
                role = seg.getSegmentRole()
                src = os.path.join(dest_base, str(content), str(role),
                                   'verification_%s.fix' % self.token)
                with open(src, 'r') as input:
                    output.writelines(input.readlines())
Exemple #5
0
                        self.sha256_check(src_dir, dst_dir)
                    except (IOError, OSError), e:
                        raise MoveFilespaceError(
                            'Failed to calculate sha256 checksums !')

            except (IOError, OSError), e:
                logger.error(
                    'Failed to copy transaction files to new Filespace location.'
                )
                raise

        # 2. Drop the directories in current filespace
        for directory in self.TRANSACTION_FILES_DIRS:
            src_dir = os.path.join(self.current_filespace_entry[2], directory)
            try:
                if CheckDir(src_dir).run():
                    logger.info('Dropping dir %s' % src_dir)
                    shutil.rmtree(src_dir)
            except (IOError, OSError), e:
                logger.error(
                    'Failed to drop transaction files directories from current filespace.'
                )
                raise

        gp_transaction_files_filespace_path = os.path.join(
            self.pg_system_filespace_entry[2], GP_TRANSACTION_FILES_FILESPACE)
        # If we are moving to default Filespace, then we need to delete the flat file
        if self.new_filespace_name == PG_SYSTEM_FILESPACE:
            if CheckFile(gp_transaction_files_filespace_path).run():
                os.remove(gp_transaction_files_filespace_path)
            return