Esempio n. 1
0
    def __load(self, filename):
        try:
            with open(filename, 'rb') as file:
                pgctl_data = file.read(PG_CONTROL_SIZE)

                self.systemidentifier, = struct.unpack_from('Q', pgctl_data, memoffset['ControlFileData.system_identifier'])
                self.catalog_version_no, = struct.unpack_from('I', pgctl_data, memoffset['ControlFileData.catalog_version_no'])
                self.dbstate, = struct.unpack_from(pgstruct.get_type_format('DBState'), pgctl_data, memoffset['ControlFileData.state'])
                self.checkPoint, = struct.unpack_from('Q', pgctl_data, memoffset['ControlFileData.checkPoint'])
                self.minRecoveryPoint, = struct.unpack_from('Q', pgctl_data, memoffset['ControlFileData.minRecoveryPoint'])
                self.minRecoveryPointTLI, = struct.unpack_from('I', pgctl_data, memoffset['ControlFileData.minRecoveryPointTLI'])
                self.checkPointCopy = CheckPoint(pgctl_data, memoffset['ControlFileData.checkPointCopy'])
                self.xlog_blcksz, = struct.unpack_from('I', pgctl_data, memoffset['ControlFileData.xlog_blcksz'])
                self.xlog_seg_size, = struct.unpack_from('I', pgctl_data, memoffset['ControlFileData.xlog_seg_size'])
                self.blcksz, = struct.unpack_from('I', pgctl_data, memoffset['ControlFileData.blcksz'])
                self.relseg_size, = struct.unpack_from('I', pgctl_data, memoffset['ControlFileData.relseg_size'])
                
                self.nameDataLen, = struct.unpack_from('I', pgctl_data, memoffset['ControlFileData.nameDataLen'])
                
                self.float8ByVal, = struct.unpack_from(pgstruct.get_type_format('bool'), pgctl_data, memoffset['ControlFileData.float8ByVal'])
                self.float4ByVal, = struct.unpack_from(pgstruct.get_type_format('bool'), pgctl_data, memoffset['ControlFileData.float4ByVal'])
                
                self.crc, = struct.unpack_from('I', pgctl_data, memoffset['ControlFileData.crc'])
                
                crcdatas = []
                crcdatas.append((pgctl_data, memoffset['ControlFileData.crc']));
                 
                if not upgcrc.crceq(crcdatas, self.crc):
                    logger.error('pg_control has invalid CRC')
                    raise UPgException('pg_control has invalid CRC')
        except IOError:
            logger.error("Error in reading control file!")
            raise
Esempio n. 2
0
 def loadrelmap(self, spacenode=None, dbnode=None):
     assert not dbnode and not spacenode or dbnode and spacenode
     if not dbnode and not spacenode:
         mapfile = '%s/global/%s'%(self.datadir, Catalog.RELMAPPER_FILENAME)
     else:
         dbpath = Catalog.getdbpath(self.datadir, spacenode, dbnode, self.GLOBALTABLESPACE_OID, 
                                    self.DEFAULTTABLESPACE_OID, self.pg_majorversion, self.catalog_version_no)
         mapfile = '%s/%s'%(dbpath, Catalog.RELMAPPER_FILENAME)
     
     try:
         with open(mapfile, 'r') as file:
             data = file.read(pgstruct.typesize['RelMapFile'])
     except IOError as e:
         logger.error('could not read relation mapping file %s'%(mapfile))
         raise UPgException('could not read relation mapping file')
     
     if len(data) != pgstruct.typesize['RelMapFile']:
         logger.error('could not read relation mapping file %s'%(mapfile))
         raise UPgException('could not read relation mapping file')
     
     magic = pgstruct.getuint(data, memoffset['RelMapFile.magic'])
     mappingnum = pgstruct.getuint(data, memoffset['RelMapFile.num_mappings'])
     crc = pgstruct.getuint(data, memoffset['RelMapFile.crc'])
     
     
     if magic != self.RELMAPPER_FILEMAGIC or mappingnum > self.max_mappings:
         logger.error('mapping file %s contains invalid data'%(mapfile))
         raise UPgException('mapping file contains invalid data')
     
     crcdatas = []
     crcdatas.append((data, memoffset['RelMapFile.crc']));
     if not upgcrc.crceq(crcdatas, crc):
         logger.error('mapping file %s contains invalid crc'%(mapfile))
         raise UPgException('mapping file contains invalid crc')
     
     result = {}
     entrysize = pgstruct.typesize['RelMapping']
     for i in range(mappingnum):
         mapoid = pgstruct.getuint(data, memoffset['RelMapFile.mappings'] + i * entrysize+memoffset['RelMapping.mapoid'])
         mapfilenode = pgstruct.getuint(data, memoffset['RelMapFile.mappings'] + i * entrysize+memoffset['RelMapping.mapfilenode'])
         result[mapoid] = mapfilenode
     return result