标签:tuple update val choice ini 针对 return 可见 current
分两种情况,一是XMIN事务未提交,一个是xmin事务已提交。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;
}
标签:tuple update val choice ini 针对 return 可见 current
原文地址:https://blog.51cto.com/yanzongshuai/2482580