| 4506 | |
| 4507 | |
| 4508 | WriteLockResult VIO_writelock(thread_db* tdbb, record_param* org_rpb, jrd_tra* transaction) |
| 4509 | { |
| 4510 | /************************************** |
| 4511 | * |
| 4512 | * V I O _ w r i t e l o c k |
| 4513 | * |
| 4514 | ************************************** |
| 4515 | * |
| 4516 | * Functional description |
| 4517 | * Modify record to make record owned by this transaction |
| 4518 | * |
| 4519 | **************************************/ |
| 4520 | SET_TDBB(tdbb); |
| 4521 | |
| 4522 | jrd_rel* const relation = org_rpb->rpb_relation; |
| 4523 | #ifdef VIO_DEBUG |
| 4524 | VIO_trace(DEBUG_WRITES, |
| 4525 | "VIO_writelock (rel_id %u, org_rpb %" QUADFORMAT"d, transaction %" SQUADFORMAT")\n", |
| 4526 | relation->rel_id, org_rpb->rpb_number.getValue(), transaction ? transaction->tra_number : 0); |
| 4527 | |
| 4528 | VIO_trace(DEBUG_WRITES_INFO, |
| 4529 | " old record %" SLONGFORMAT":%d, rpb_trans %" SQUADFORMAT |
| 4530 | ", flags %d, back %" SLONGFORMAT":%d, fragment %" SLONGFORMAT":%d\n", |
| 4531 | org_rpb->rpb_page, org_rpb->rpb_line, org_rpb->rpb_transaction_nr, |
| 4532 | org_rpb->rpb_flags, org_rpb->rpb_b_page, org_rpb->rpb_b_line, |
| 4533 | org_rpb->rpb_f_page, org_rpb->rpb_f_line); |
| 4534 | #endif |
| 4535 | |
| 4536 | const bool skipLocked = org_rpb->rpb_stream_flags & RPB_s_skipLocked; |
| 4537 | |
| 4538 | if (transaction->tra_flags & TRA_system) |
| 4539 | { |
| 4540 | // Explicit locks are not needed in system transactions |
| 4541 | return WriteLockResult::LOCKED; |
| 4542 | } |
| 4543 | |
| 4544 | if (org_rpb->rpb_runtime_flags & (RPB_refetch | RPB_undo_read)) |
| 4545 | { |
| 4546 | if (!VIO_refetch_record(tdbb, org_rpb, transaction, true, true)) |
| 4547 | return WriteLockResult::CONFLICTED; |
| 4548 | |
| 4549 | org_rpb->rpb_runtime_flags &= ~RPB_refetch; |
| 4550 | fb_assert(!(org_rpb->rpb_runtime_flags & RPB_undo_read)); |
| 4551 | } |
| 4552 | |
| 4553 | if (org_rpb->rpb_transaction_nr == transaction->tra_number) |
| 4554 | { |
| 4555 | // We already own this record, thus no writelock is required |
| 4556 | return WriteLockResult::LOCKED; |
| 4557 | } |
| 4558 | |
| 4559 | transaction->tra_flags |= TRA_write; |
| 4560 | |
| 4561 | Record* org_record = org_rpb->rpb_record; |
| 4562 | if (!org_record) |
| 4563 | { |
| 4564 | org_record = VIO_record(tdbb, org_rpb, NULL, tdbb->getDefaultPool()); |
| 4565 | org_rpb->rpb_address = org_record->getData(); |
no test coverage detected