| 677 | |
| 678 | |
| 679 | pag* CCH_fake(thread_db* tdbb, WIN* window, int wait) |
| 680 | { |
| 681 | /************************************** |
| 682 | * |
| 683 | * C C H _ f a k e |
| 684 | * |
| 685 | ************************************** |
| 686 | * |
| 687 | * Functional description |
| 688 | * Fake a fetch to a page. Rather than reading it, however, |
| 689 | * zero it in memory. This is used when allocating a new page. |
| 690 | * |
| 691 | * input |
| 692 | * wait: 1 => Wait as long as necessary to get the latch. |
| 693 | * This can cause deadlocks of course. |
| 694 | * 0 => If the latch can't be acquired immediately, |
| 695 | * or an IO would be necessary, then give |
| 696 | * up and return 0. |
| 697 | * <negative number> => Latch timeout interval in seconds. |
| 698 | * |
| 699 | * return |
| 700 | * pag pointer if successful. |
| 701 | * NULL pointer if timeout occurred (only possible if wait <> 1). |
| 702 | * NULL pointer if wait=0 and the faked page would have to be |
| 703 | * before reuse. |
| 704 | * |
| 705 | **************************************/ |
| 706 | SET_TDBB(tdbb); |
| 707 | Database* const dbb = tdbb->getDatabase(); |
| 708 | BufferControl *bcb = dbb->dbb_bcb; |
| 709 | |
| 710 | CCH_TRACE(("FAKE %d:%06d", window->win_page.getPageSpaceID(), window->win_page.getPageNum())); |
| 711 | |
| 712 | // if there has been a shadow added recently, go out and |
| 713 | // find it before we grant any more write locks |
| 714 | |
| 715 | if (dbb->dbb_ast_flags & DBB_get_shadows) |
| 716 | SDW_get_shadows(tdbb); |
| 717 | |
| 718 | BufferDesc* bdb = get_buffer(tdbb, window->win_page, SYNC_EXCLUSIVE, wait); |
| 719 | if (!bdb) |
| 720 | return NULL; // latch timeout occurred |
| 721 | |
| 722 | fb_assert(bdb->bdb_page == window->win_page); |
| 723 | |
| 724 | // If a dirty orphaned page is being reused - better write it first |
| 725 | // to clear current precedences and checkpoint state. This would also |
| 726 | // update the bcb_free_pages field appropriately. |
| 727 | |
| 728 | if (bdb->bdb_flags & (BDB_dirty | BDB_db_dirty)) |
| 729 | { |
| 730 | // If the caller didn't want to wait at all, then |
| 731 | // return 'try to fake an other page' to the caller. |
| 732 | |
| 733 | if (!wait) |
| 734 | { |
| 735 | bdb->release(tdbb, true); |
| 736 | return NULL; |
no test coverage detected