| 2102 | |
| 2103 | |
| 2104 | bool BTR_next_index(thread_db* tdbb, jrd_rel* relation, jrd_tra* transaction, index_desc* idx, WIN* window) |
| 2105 | { |
| 2106 | /************************************** |
| 2107 | * |
| 2108 | * B T R _ n e x t _ i n d e x |
| 2109 | * |
| 2110 | ************************************** |
| 2111 | * |
| 2112 | * Functional description |
| 2113 | * Get next index for relation. Index ids |
| 2114 | * recently changed from UCHAR to SHORT |
| 2115 | * |
| 2116 | **************************************/ |
| 2117 | SET_TDBB(tdbb); |
| 2118 | |
| 2119 | USHORT id; |
| 2120 | if (idx->idx_id == idx_invalid) |
| 2121 | { |
| 2122 | id = 0; |
| 2123 | window->win_bdb = NULL; |
| 2124 | } |
| 2125 | else |
| 2126 | id = idx->idx_id + 1; |
| 2127 | |
| 2128 | index_root_page* root; |
| 2129 | if (window->win_bdb) |
| 2130 | root = (index_root_page*) window->win_buffer; |
| 2131 | else |
| 2132 | { |
| 2133 | RelationPages* const relPages = transaction ? |
| 2134 | relation->getPages(tdbb, transaction->tra_number) : relation->getPages(tdbb); |
| 2135 | |
| 2136 | if (!(root = fetch_root(tdbb, window, relation, relPages))) |
| 2137 | return false; |
| 2138 | } |
| 2139 | |
| 2140 | for (; id < root->irt_count; ++id) |
| 2141 | { |
| 2142 | const index_root_page::irt_repeat* irt_desc = root->irt_rpt + id; |
| 2143 | if (irt_desc->getTransaction() && transaction) |
| 2144 | { |
| 2145 | const TraNumber trans = irt_desc->getTransaction(); |
| 2146 | CCH_RELEASE(tdbb, window); |
| 2147 | const int trans_state = TRA_wait(tdbb, transaction, trans, jrd_tra::tra_wait); |
| 2148 | if ((trans_state == tra_dead) || (trans_state == tra_committed)) |
| 2149 | { |
| 2150 | // clean up this left-over index |
| 2151 | root = (index_root_page*) CCH_FETCH(tdbb, window, LCK_write, pag_root); |
| 2152 | irt_desc = root->irt_rpt + id; |
| 2153 | |
| 2154 | if (irt_desc->getTransaction() == trans) |
| 2155 | BTR_delete_index(tdbb, window, id); |
| 2156 | else |
| 2157 | CCH_RELEASE(tdbb, window); |
| 2158 | |
| 2159 | root = (index_root_page*) CCH_FETCH(tdbb, window, LCK_read, pag_root); |
| 2160 | continue; |
| 2161 | } |
no test coverage detected