def createSegmentRowsFromSegmentList()

in automation/tinc/main/ext/qautils/gppylib/gparray.py [0:0]


def createSegmentRowsFromSegmentList( newHostlist
                                    , interface_list
                                    , primary_segment_list
                                    , primary_portbase
                                    , mirror_type
                                    , mirror_segment_list
                                    , mirror_portbase
                                    , dir_prefix
                                    , primary_replication_portbase
                                    , mirror_replication_portbase
                                    ):
    """
    This method will return a list of SegmentRow objects that represent an expansion of existing
    segments on new hosts. 
    """
    rows    = []
    dbid    = 0
    content = 0
    interfaceDict = {}

    for host in newHostlist:
        isprimary='t'
        port=primary_portbase
        prPort = primary_replication_portbase
        index = 0
        for pSeg in primary_segment_list:
            if len(interface_list) > 0:
                interfaceNumber = interface_list[index % len(interface_list)]
                address = host + '-' + str(interfaceNumber)
                interfaceDict[content] = index % len(interface_list)
            else:
                address = host
            newFulldir = "%s/%s%d" % (GpDB.getDataDirPrefix(pSeg.getSegmentDataDirectory()), dir_prefix, content)
            newFileSpaceDictionary = GpDB.getFileSpaceDirsWithNewSuffix(pSeg.getSegmentFilespaces(), dir_prefix + str(content), includeSystemFilespace = False)
            rows.append( SegmentRow( content = content
                                   , isprimary = isprimary
                                   , dbid = dbid
                                   , host = host
                                   , address = address
                                   , port = port
                                   , fulldir = newFulldir
                                   , prPort = prPort
                                   , fileSpaceDictionary = newFileSpaceDictionary
                                   ) )
            port += 1
            if prPort != None:
                prPort += 1
            content += 1
            dbid += 1
            index += 1
    
    #mirrors
    if mirror_type is None or mirror_type == 'none':
        return rows
    elif mirror_type.lower().strip() == 'spread':
        content=0
        isprimary='f'
        num_hosts = len(newHostlist)
        num_dirs=len(primary_segment_list)
        if num_hosts <= num_dirs:
            raise Exception("Not enough hosts for spread mirroring.  You must have more hosts than primary segments per host")
        
        mirror_port = {}
        mirror_replication_port = {}

        mirror_host_offset=1
        last_mirror_offset=0
        for host in newHostlist:
            mirror_host_offset = last_mirror_offset + 1
            last_mirror_offset += 1
            for mSeg in mirror_segment_list:
                newFulldir = "%s/%s%d" % (GpDB.getDataDirPrefix(mSeg.getSegmentDataDirectory()), dir_prefix, content)
                newFileSpaceDictionary = GpDB.getFileSpaceDirsWithNewSuffix(mSeg.getSegmentFilespaces(), dir_prefix + str(content), includeSystemFilespace = False)
                mirror_host = newHostlist[mirror_host_offset % num_hosts]
                if mirror_host == host:
                    mirror_host_offset += 1
                    mirror_host = newHostlist[mirror_host_offset % num_hosts]
                if len(interface_list) > 0:
                    interfaceNumber = interface_list[(interfaceDict[content] + 1) % len(interface_list)]
                    address = mirror_host + '-' + str(interfaceNumber)
                else:
                    address = mirror_host
    
                if not mirror_port.has_key(mirror_host):
                    mirror_port[mirror_host] = mirror_portbase
                if not mirror_replication_port.has_key(mirror_host):
                    mirror_replication_port[mirror_host] = mirror_replication_portbase
                    
                rows.append( SegmentRow( content = content
                                       , isprimary = isprimary
                                       , dbid = dbid
                                       , host = mirror_host
                                       , address = address
                                       , port = mirror_port[mirror_host]
                                       , fulldir = newFulldir
                                       , prPort = mirror_replication_port[mirror_host]
                                       , fileSpaceDictionary = newFileSpaceDictionary
                                       ) )

                mirror_port[mirror_host] += 1
                mirror_replication_port[mirror_host] += 1
                content += 1
                dbid += 1
                mirror_host_offset += 1
                
        
    elif mirror_type.lower().strip() == 'grouped':
        content = 0
        num_hosts = len(newHostlist)
        
        if num_hosts < 2:
            raise Exception("Not enough hosts for grouped mirroring.  You must have at least 2")
        
        #we'll pick our mirror host to be 1 host "ahead" of the primary.
        mirror_host_offset = 1
        
        isprimary='f'
        for host in newHostlist:            
            mirror_host = newHostlist[mirror_host_offset % num_hosts]
            mirror_host_offset += 1
            port = mirror_portbase
            mrPort = mirror_replication_portbase
            index = 0
            for mSeg in mirror_segment_list:
                if len(interface_list) > 0:
                    interfaceNumber = interface_list[(interfaceDict[content] + 1) % len(interface_list)]
                    address = mirror_host + '-' + str(interfaceNumber)
                else:
                    address = mirror_host
                newFulldir = "%s/%s%d" % (GpDB.getDataDirPrefix(mSeg.getSegmentDataDirectory()), dir_prefix, content)
                newFileSpaceDictionary = GpDB.getFileSpaceDirsWithNewSuffix(mSeg.getSegmentFilespaces(), dir_prefix + str(content), includeSystemFilespace = False)                
                rows.append( SegmentRow( content = content
                                       , isprimary = isprimary
                                       , dbid = dbid
                                       , host = mirror_host
                                       , address = address
                                       , port = port
                                       , fulldir = newFulldir
                                       , prPort = mrPort
                                       , fileSpaceDictionary = newFileSpaceDictionary
                                       ) )
                port += 1
                mrPort +=1
                content += 1
                dbid += 1
                index = index + 1
        
    else:
        raise Exception("Invalid mirror type specified: %s" % mirror_type)
    
    return rows