| 144 | } |
| 145 | |
| 146 | void TRA_setup_request_snapshot(Jrd::thread_db* tdbb, Jrd::Request* request) |
| 147 | { |
| 148 | // This function is called whenever request is started in a transaction. |
| 149 | // Setup context to preserve read consistency in READ COMMITTED transactions. |
| 150 | |
| 151 | Jrd::jrd_tra* transaction = request->req_transaction; |
| 152 | |
| 153 | // We assume that request is already attached to a transaction |
| 154 | fb_assert(transaction); |
| 155 | |
| 156 | // If we are not READ COMMITTED or read consistency is not needed then nothing to do here |
| 157 | if (!(transaction->tra_flags & TRA_read_committed) || !(transaction->tra_flags & TRA_read_consistency)) |
| 158 | return; |
| 159 | |
| 160 | // See if there is any request right above us in the call stack |
| 161 | Request* org_request = TRA_get_prior_request(tdbb); |
| 162 | |
| 163 | if (org_request && org_request->req_transaction == transaction) |
| 164 | { |
| 165 | fb_assert(org_request->req_snapshot.m_owner); |
| 166 | request->req_snapshot.m_owner = org_request->req_snapshot.m_owner; |
| 167 | return; |
| 168 | } |
| 169 | |
| 170 | // If we are a top-level request or caller is executed in a different transaction, |
| 171 | // we need to set up statement snapshot for read consistency and own it |
| 172 | |
| 173 | request->req_snapshot.m_owner = request; |
| 174 | request->req_snapshot.m_number = 0; |
| 175 | |
| 176 | request->req_snapshot.m_handle = |
| 177 | tdbb->getDatabase()->dbb_tip_cache->beginSnapshot(tdbb, |
| 178 | tdbb->getAttachment()->att_attachment_id, request->req_snapshot.m_number); |
| 179 | } |
| 180 | |
| 181 | |
| 182 | void TRA_release_request_snapshot(Jrd::thread_db* tdbb, Jrd::Request* request) |
no test coverage detected