您好,欢迎来到海洋目录网!网站收录,值得选择!长期招友情链接 QQ10212321

快审
当前位置:海洋目录网 » 站长资讯 » 站长资讯 » 文章详细 订阅RssFeed

PG vacuum可见性

来源:网站目录 浏览:25次 时间:2020-09-19

分两种情况,一是XMIN事务未提交,一个是xmin事务已提交。
针对xmin未提交的事务,即当前的tuple刚insert还未提交:
1)元组不合法,即坏元组时,返回HEAPTUPLE_DEAD
2)该tuple是当前事务产生的:此时这个记录在这个事务未删除或只是被锁住或进行了delete但是delete abort了,那返回HAPTUPLE_INSERT_IN_PROGRESS;若则记录又被删除了,那返回HEAPTUPLE_DELETE_IN_PROGRESS
3)该tuple是其他事务产生的,tuple头中标记未提交:HEAP_INSERT_IN_POGRESS
4)该tuple是其他事务产生,clog中显示xmin已提交:则标记tuple头为HEAP_XMIN_COMMITTED。
5)其他情况下,这个xmin事务确实未提交,abort或损坏了:返回HEAPTUPLE_DEAD
针对xmin已提交的事务,即当前的tuple insert已提交了:
1)xmax未提交,返回HEAPTUPLE_LIVE
2)tuple只是被锁着:xmax未提交:返回HEAPTUPLE_LIVE
3)tuple正在delete:返回HEAPTUPLE_DELETE_IN_PROGRESS
4)clog中查到xmax已提交:标记tuple头HEAP_XMAX_COMMITTED
5)其他情况delete确实未提交:HEAPTUPLE_LIVE
6)剩下的情况,tuple.t_xmax >= OldestXmin表示有事务还能看到insert的值:HEAPTUPLE_RECENTLY_DEAD
7)其他情况XMAX已提交了:返回HEAPTUPLE_DEAD
PG vacuum可见性

HeapTupleSatisfiesVacuum{    HeapTupleHeader tuple = htup->t_data;    if (!HeapTupleHeaderXminCommitted(tuple))//未提交    {        if (HeapTupleHeaderXminInvalid(tuple))//元组不合法,坏的元组            return HEAPTUPLE_DEAD;        else if (TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmin(tuple)))        {//当前事务产生的元组            if (tuple->t_infomask & HEAP_XMAX_INVALID)//未被删除,当前事务正在insert                return HEAPTUPLE_INSERT_IN_PROGRESS;            //元组被锁住,未被删除 或者             if (HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask) || HeapTupleHeaderIsOnlyLocked(tuple))                return HEAPTUPLE_INSERT_IN_PROGRESS;            //insert后当前事务又删除            if (TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetUpdateXid(tuple)))                return HEAPTUPLE_DELETE_IN_PROGRESS;            //delete的子事务被abort,即insert正在进行            return HEAPTUPLE_INSERT_IN_PROGRESS;        }        else if (TransactionIdIsInProgress(HeapTupleHeaderGetRawXmin(tuple)))        {//其他事务正在insert            return HEAPTUPLE_INSERT_IN_PROGRESS;        }//从clog中读取tuple的事务状态,为提交则标记提交        else if (TransactionIdDidCommit(HeapTupleHeaderGetRawXmin(tuple)))            SetHintBits(tuple, buffer, HEAP_XMIN_COMMITTED,HeapTupleHeaderGetRawXmin(tuple));        else        {            //真的tuple未提交、abort或者损坏            SetHintBits(tuple, buffer, HEAP_XMIN_INVALID,InvalidTransactionId);            return HEAPTUPLE_DEAD;        }        //此时,xmin已提交了。    }    /*     * Okay, the inserter committed, so it was good at some point.  Now what     * about the deleting transaction?     */    if (tuple->t_infomask & HEAP_XMAX_INVALID)        return HEAPTUPLE_LIVE;//未被删除则该记录是活的    if (HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask))    {//只是锁住,未进行delete        if (!(tuple->t_infomask & HEAP_XMAX_COMMITTED))        {//delete事务未提交            if (TransactionIdIsInProgress(HeapTupleHeaderGetRawXmax(tuple)))                return HEAPTUPLE_LIVE;            SetHintBits(tuple, buffer, HEAP_XMAX_INVALID,InvalidTransactionId);        }        return HEAPTUPLE_LIVE;    }    //delete未提交    if (!(tuple->t_infomask & HEAP_XMAX_COMMITTED))    {        if (TransactionIdIsInProgress(HeapTupleHeaderGetRawXmax(tuple)))            return HEAPTUPLE_DELETE_IN_PROGRESS;//delete正在进行        else if (TransactionIdDidCommit(HeapTupleHeaderGetRawXmax(tuple)))//从clog中检查delete提交了            SetHintBits(tuple, buffer, HEAP_XMAX_COMMITTED,HeapTupleHeaderGetRawXmax(tuple));        else        {            //真的未提交、abort或者损坏            SetHintBits(tuple, buffer, HEAP_XMAX_INVALID,InvalidTransactionId);            return HEAPTUPLE_LIVE;        }        //此时delete已提交    }    //有事务还可能看到他    //tuple->t_choice.t_heap.t_xmax >= OldestXmin    if (!TransactionIdPrecedes(HeapTupleHeaderGetRawXmax(tuple), OldestXmin))        return HEAPTUPLE_RECENTLY_DEAD;    /* Otherwise, it's dead and removable */    return HEAPTUPLE_DEAD;}

推荐站点

  • At-lib分类目录At-lib分类目录

    At-lib网站分类目录汇集全国所有高质量网站,是中国权威的中文网站分类目录,给站长提供免费网址目录提交收录和推荐最新最全的优秀网站大全是名站导航之家

    www.at-lib.cn
  • 中国链接目录中国链接目录

    中国链接目录简称链接目录,是收录优秀网站和淘宝网店的网站分类目录,为您提供优质的网址导航服务,也是网店进行收录推广,站长免费推广网站、加快百度收录、增加友情链接和网站外链的平台。

    www.cnlink.org
  • 35目录网35目录网

    35目录免费收录各类优秀网站,全力打造互动式网站目录,提供网站分类目录检索,关键字搜索功能。欢迎您向35目录推荐、提交优秀网站。

    www.35mulu.com
  • 伍佰目录伍佰目录

    伍佰网站目录免费收录各类优秀网站,全力打造互动式网站目录,提供网站分类目录检索,关键字搜索功能。欢迎您向伍佰目录推荐、提交优秀网站。

    www.wbwb.net