src/backend/concurrency/pessimistic_txn_manager.cpp
// Visibility check
// check whether a tuple is visible to current transaction.
// in this protocol, we require that a transaction cannot see other
// transaction's local copy.
Visibility check
check whether a tuple is visible to current transaction.
in this protocol, we require that a transaction cannot see other
transaction's local copy.
Visibility check check whether a tuple is visible to current transaction . in this protocol we require that a transaction cannot see other transaction ' s local copy .
bool PessimisticTxnManager::IsVisible(
    const storage::TileGroupHeader *const tile_group_header,
    const oid_t &tuple_id) {
  txn_id_t tuple_txn_id = tile_group_header->GetTransactionId(tuple_id);
  cid_t tuple_begin_cid = tile_group_header->GetBeginCommitId(tuple_id);
  cid_t tuple_end_cid = tile_group_header->GetEndCommitId(tuple_id);
  if (EXTRACT_TXNID(tuple_txn_id) == INVALID_TXN_ID) {
    return false;
  }
  bool own = (current_txn->GetTransactionId() == EXTRACT_TXNID(tuple_txn_id));
  if (own == true) {
    if (tuple_begin_cid == MAX_CID && tuple_end_cid != INVALID_CID) {
      assert(tuple_end_cid == MAX_CID);
      return true;
    } else {
      return false;
    }
  } else {
    bool activated = (current_txn->GetBeginCommitId() >= tuple_begin_cid);
    bool invalidated = (current_txn->GetBeginCommitId() >= tuple_end_cid);
    if (EXTRACT_TXNID(tuple_txn_id) != INITIAL_TXN_ID) {
      if (tuple_begin_cid == MAX_CID) {
        return false;
      } else {
        if (activated && !invalidated) {
          return true;
        } else {
          return false;
        }
      }
    } else {
      if (activated && !invalidated) {
        return true;
      } else {
        return false;
      }
    }
  }
}
bool PessimisticTxnManager :: IsVisible ( const storage :: TileGroupHeader * const tile_group_header , const oid_t & tuple_id ) { txn_id_t tuple_txn_id = tile_group_header -> GetTransactionId ( tuple_id ) ; cid_t tuple_begin_cid = tile_group_header -> GetBeginCommitId ( tuple_id ) ; cid_t tuple_end_cid = tile_group_header -> GetEndCommitId ( tuple_id ) ; if ( EXTRACT_TXNID ( tuple_txn_id ) == INVALID_TXN_ID ) { return false ; } bool own = ( current_txn -> GetTransactionId ( ) == EXTRACT_TXNID ( tuple_txn_id ) ) ; if ( own == true ) { if ( tuple_begin_cid == MAX_CID && tuple_end_cid != INVALID_CID ) { assert ( tuple_end_cid == MAX_CID ) ; return true ; } else { return false ; } } else { bool activated = ( current_txn -> GetBeginCommitId ( ) >= tuple_begin_cid ) ; bool invalidated = ( current_txn -> GetBeginCommitId ( ) >= tuple_end_cid ) ; if ( EXTRACT_TXNID ( tuple_txn_id ) != INITIAL_TXN_ID ) { if ( tuple_begin_cid == MAX_CID ) { return false ; } else { if ( activated && ! invalidated ) { return true ; } else { return false ; } } } else { if ( activated && ! invalidated ) { return true ; } else { return false ; } } } }
Visibility check
check whether a tuple is visible to current transaction.
Visibility check check whether a tuple is visible to current transaction .
// the tuple is not available. // there are exactly two versions that can be owned by a transaction. // unless it is an insertion. // the only version that is visible is the newly inserted one. // the older version is not visible. // if the tuple is owned by other transactions. // currently, we do not handle cascading abort. so never read an // uncommitted version. // the older version may be visible. // if the tuple is not owned by any transaction.