Пример #1
0
    def load(self, pagedata, tupleoff, heaptuplemode=True):
        if heaptuplemode:
            self.xmin = pgstruct.getuint(
                pagedata, tupleoff + memoffset['HeapTupleHeaderData.t_heap'] +
                memoffset['HeapTupleFields.t_xmin'])
            self.xmax = pgstruct.getuint(
                pagedata, tupleoff + memoffset['HeapTupleHeaderData.t_heap'] +
                memoffset['HeapTupleFields.t_xmax'])
            self.field3 = pgstruct.getuint(
                pagedata, tupleoff + memoffset['HeapTupleHeaderData.t_heap'] +
                memoffset['HeapTupleFields.t_field3'])
        else:
            self.datum_len_ = pgstruct.getuint(
                pagedata, tupleoff + memoffset['HeapTupleHeaderData.t_heap'] +
                memoffset['DatumTupleFields.datum_len_'])
            self.datum_typmod = pgstruct.getuint(
                pagedata, tupleoff + memoffset['HeapTupleHeaderData.t_heap'] +
                memoffset['DatumTupleFields.datum_typmod'])
            self.datum_typeid = pgstruct.getuint(
                pagedata, tupleoff + memoffset['HeapTupleHeaderData.t_heap'] +
                memoffset['DatumTupleFields.datum_typeid'])

        self.ctid_blkid_hi = pgstruct.getushort(
            pagedata, tupleoff + memoffset['HeapTupleHeaderData.t_ctid'] +
            memoffset['ItemPointerData.ip_blkid'] +
            memoffset['BlockIdData.bi_hi'])
        self.ctid_blkid_lo = pgstruct.getushort(
            pagedata, tupleoff + memoffset['HeapTupleHeaderData.t_ctid'] +
            memoffset['ItemPointerData.ip_blkid'] +
            memoffset['BlockIdData.bi_lo'])
        self.ctid_posid = pgstruct.getushort(
            pagedata, tupleoff + memoffset['HeapTupleHeaderData.t_ctid'] +
            memoffset['ItemPointerData.ip_posid'])

        self.infomask2 = pgstruct.getushort(
            pagedata, tupleoff + memoffset['HeapTupleHeaderData.t_infomask2'])
        self.infomask = pgstruct.getushort(
            pagedata, tupleoff + memoffset['HeapTupleHeaderData.t_infomask'])

        self.hoff = pgstruct.getubyte(
            pagedata, tupleoff + memoffset['HeapTupleHeaderData.t_hoff'])

        hasoid = (self.infomask & HeapTuple.HEAP_HASOID) != 0
        hasnull = (self.infomask & HeapTuple.HEAP_HASNULL) != 0
        if hasnull:
            nullbitlen = self.hoff - memoffset[
                'HeapTupleHeaderData.t_bits'] - (4 if hasoid else 0)
            self.bits = ctypes.string_at(
                ctypes.byref(
                    pagedata,
                    tupleoff + memoffset['HeapTupleHeaderData.t_bits']),
                nullbitlen)
        else:
            nullbitlen = 0
            self.bits = None
        if hasoid:
            self.oid = pgstruct.getuint(pagedata, tupleoff + self.hoff - 4)
        else:
            self.oid = None
Пример #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
Пример #3
0
 def getmembers(self, multixid, readtoinvalid = False, multixactstate = None):
     result = []
     thisoffset = self.offsetcache.getoffset(multixid, multixactstate)
     if not thisoffset:
         return None
     nextxid = uint32advancedIgnor0(multixid, 1)
     targetoffset = None
     if multixactstate and multixactstate.nextmultixactid == nextxid:
         targetoffset = multixactstate.nextoffset
     else:
         nextoffset = self.offsetcache.getoffset(nextxid, multixactstate)
         if not nextoffset and not readtoinvalid:
             logger.error("could not find next multi transaction's offset:%u"%(nextxid))
             return None
         if nextoffset:
             targetoffset = nextoffset
     
     offset = thisoffset    
     while True:
         if targetoffset and offset == targetoffset:
             break
         pageno = self.__getmemberpagebyoffset(offset)
         memberoff = self.__getmemberinnerpageoffsetbyoffset(offset)
         
         try:
             blockdata = self.getlrupage(pageno).data
         except UPgException:
             if targetoffset:
                 logger.error("could not read member block:%u"%(pageno))
                 return None
             else:
                 return result
         memberxid = pgstruct.gettransactionid(blockdata, memberoff)
         if memberxid == 0:
             if targetoffset:
                 logger.error("found invalid member transaction id in offset:%u"%(offset))
                 return None
             else:
                 return result
         flagoff = self.__getgroupflagoffset(offset)
         bshift = self.__getmemberflagbitsshit(offset)
         flag = pgstruct.getuint(blockdata, flagoff)
         status = (flag >> bshift) & self.MXACT_MEMBER_XACT_BITMASK;
         result.append((memberxid, status))
         offset = uint32advancedIgnor0(offset, 1)
     return result
Пример #4
0
 def load(self, pagedata, tupleoff, heaptuplemode = True):
     if heaptuplemode:
         self.xmin = pgstruct.getuint(pagedata, 
             tupleoff+memoffset['HeapTupleHeaderData.t_heap']+memoffset['HeapTupleFields.t_xmin'])
         self.xmax = pgstruct.getuint(pagedata, 
             tupleoff+memoffset['HeapTupleHeaderData.t_heap']+memoffset['HeapTupleFields.t_xmax'])
         self.field3 = pgstruct.getuint(pagedata, 
             tupleoff+memoffset['HeapTupleHeaderData.t_heap']+memoffset['HeapTupleFields.t_field3'])
     else:
         self.datum_len_ = pgstruct.getuint(pagedata, 
             tupleoff+memoffset['HeapTupleHeaderData.t_heap']+memoffset['DatumTupleFields.datum_len_'])
         self.datum_typmod = pgstruct.getuint(pagedata, 
             tupleoff+memoffset['HeapTupleHeaderData.t_heap']+memoffset['DatumTupleFields.datum_typmod'])
         self.datum_typeid = pgstruct.getuint(pagedata, 
             tupleoff+memoffset['HeapTupleHeaderData.t_heap']+memoffset['DatumTupleFields.datum_typeid'])
     
     self.ctid_blkid_hi =  pgstruct.getushort(pagedata, 
             tupleoff+memoffset['HeapTupleHeaderData.t_ctid']
             +memoffset['ItemPointerData.ip_blkid'] + memoffset['BlockIdData.bi_hi'])
     self.ctid_blkid_lo =  pgstruct.getushort(pagedata, 
             tupleoff+memoffset['HeapTupleHeaderData.t_ctid']
             +memoffset['ItemPointerData.ip_blkid'] + memoffset['BlockIdData.bi_lo'])
     self.ctid_posid =  pgstruct.getushort(pagedata, 
             tupleoff+memoffset['HeapTupleHeaderData.t_ctid']
             +memoffset['ItemPointerData.ip_posid'])
     
     self.infomask2 = pgstruct.getushort(pagedata, 
             tupleoff+memoffset['HeapTupleHeaderData.t_infomask2'])
     self.infomask = pgstruct.getushort(pagedata, 
             tupleoff+memoffset['HeapTupleHeaderData.t_infomask'])
     
     self.hoff = pgstruct.getubyte(pagedata, 
             tupleoff+memoffset['HeapTupleHeaderData.t_hoff'])
     
     hasoid = (self.infomask & HeapTuple.HEAP_HASOID) != 0
     hasnull = (self.infomask & HeapTuple.HEAP_HASNULL) != 0
     if hasnull:
         nullbitlen = self.hoff - memoffset['HeapTupleHeaderData.t_bits']- (4 if hasoid else 0)
         self.bits = ctypes.string_at(ctypes.byref(pagedata, tupleoff+memoffset['HeapTupleHeaderData.t_bits']), nullbitlen)
     else:
         nullbitlen = 0
         self.bits = None
     if hasoid:
         self.oid = pgstruct.getuint(pagedata, tupleoff+ self.hoff - 4)
     else:
         self.oid = None
Пример #5
0
def xidout(data, off, len):
    return pgstruct.getuint(data, off)
Пример #6
0
def xidout(data, off, len):
    return pgstruct.getuint(data, off)