@@ -2079,7 +2079,6 @@ btree_lookup_node(cache *cc, // IN
20792079 *
20802080 * LOCAL Variables:
20812081 * - state->h: the height of the current node
2082- * - state->found: whether the target was found
20832082 * - state->child_node: the child node
20842083 */
20852084static inline async_status
@@ -2114,11 +2113,12 @@ btree_lookup_node_async(btree_lookup_async_state *state, uint64 depth)
21142113 state -> h > state -> stop_at_height ;
21152114 state -> h -- )
21162115 {
2117- int64 child_idx =
2116+ bool32 found ;
2117+ int64 child_idx =
21182118 key_is_positive_infinity (state -> target )
2119- ? btree_num_entries (state -> node .hdr ) - 1
2120- : btree_find_pivot (
2121- state -> cfg , state -> node .hdr , state -> target , & state -> found );
2119+ ? btree_num_entries (state -> node .hdr ) - 1
2120+ : btree_find_pivot (
2121+ state -> cfg , state -> node .hdr , state -> target , & found );
21222122 if (child_idx < 0 ) {
21232123 child_idx = 0 ;
21242124 }
@@ -2165,7 +2165,7 @@ btree_lookup_node_async(btree_lookup_async_state *state, uint64 depth)
21652165 *
21662166 * OUT Parameters:
21672167 * - state->node: the node found
2168- * - state->found: whether the target was found in the leaf
2168+ * - state->found_key: the key found in the leaf, or NULL_KEY otherwise.
21692169 * - state->msg: the message of the target
21702170 *
21712171 * LOCAL Variables:
@@ -2183,9 +2183,11 @@ btree_lookup_with_ref_async(btree_lookup_async_state *state, uint64 depth)
21832183 state -> stats = NULL ;
21842184 async_await_subroutine (state , btree_lookup_node_async );
21852185
2186- int64 idx = btree_find_tuple (
2187- state -> cfg , state -> node .hdr , state -> target , & state -> found );
2188- if (state -> found ) {
2186+ state -> found_key = NULL_KEY ;
2187+ bool32 found ;
2188+ int64 idx =
2189+ btree_find_tuple (state -> cfg , state -> node .hdr , state -> target , & found );
2190+ if (found ) {
21892191 leaf_entry * entry =
21902192 btree_get_leaf_entry (state -> cfg , state -> node .hdr , idx );
21912193 state -> found_key = leaf_entry_key (entry );
@@ -2205,13 +2207,15 @@ btree_lookup_with_ref(cache *cc, // IN
22052207 key target , // IN
22062208 btree_node * node , // OUT
22072209 key * found_key , // OUT
2208- message * msg , // OUT
2209- bool32 * found ) // OUT
2210+ message * msg ) // OUT
22102211{
2211- platform_status rc = STATUS_OK ;
2212+ platform_status rc = STATUS_OK ;
2213+ bool32 found = FALSE;
2214+
2215+ * found_key = NULL_KEY ;
22122216 btree_lookup_node (cc , cfg , root_addr , target , 0 , type , node , NULL );
2213- int64 idx = btree_find_tuple (cfg , node -> hdr , target , found );
2214- if (* found ) {
2217+ int64 idx = btree_find_tuple (cfg , node -> hdr , target , & found );
2218+ if (found ) {
22152219 leaf_entry * entry = btree_get_leaf_entry (cfg , node -> hdr , idx );
22162220 * found_key = leaf_entry_key (entry );
22172221 * msg = leaf_entry_message (entry );
@@ -2221,57 +2225,17 @@ btree_lookup_with_ref(cache *cc, // IN
22212225 return rc ;
22222226}
22232227
2224- async_status
2225- btree_lookup_async (btree_lookup_async_state * state )
2226- {
2227- async_begin (state , 0 );
2228-
2229- async_await_subroutine (state , btree_lookup_with_ref_async );
2230-
2231- platform_status rc = STATUS_OK ;
2232- if (state -> found ) {
2233- if (state -> keybuf != NULL ) {
2234- rc = key_buffer_copy_key (state -> keybuf , state -> found_key );
2235- }
2236- bool32 success =
2237- merge_accumulator_copy_message (state -> result , state -> msg );
2238- if (!success ) {
2239- rc = STATUS_NO_MEMORY ;
2240- }
2241- btree_node_unget (state -> cc , state -> cfg , & state -> node );
2242- }
2243- async_return (state , rc );
2244- }
2245-
2246-
22472228platform_status
2248- btree_lookup (cache * cc , // IN
2249- btree_config * cfg , // IN
2250- uint64 root_addr , // IN
2251- page_type type , // IN
2252- key target , // IN
2253- key_buffer * keybuf , // OUT
2254- merge_accumulator * result ) // OUT
2229+ btree_lookup (cache * cc , // IN
2230+ btree_config * cfg , // IN
2231+ uint64 root_addr , // IN
2232+ page_type type , // IN
2233+ key target , // IN
2234+ lookup_result * result ) // OUT
22552235{
2256- btree_node node ;
2257- key found_key ;
2258- message data ;
2259- platform_status rc = STATUS_OK ;
2260- bool32 local_found ;
2261-
2262- btree_lookup_with_ref (
2263- cc , cfg , root_addr , type , target , & node , & found_key , & data , & local_found );
2264- if (local_found ) {
2265- if (keybuf != NULL ) {
2266- rc = key_buffer_copy_key (keybuf , found_key );
2267- }
2268- bool32 success = merge_accumulator_copy_message (result , data );
2269- if (!success ) {
2270- rc = STATUS_NO_MEMORY ;
2271- }
2272- btree_node_unget (cc , cfg , & node );
2273- }
2274- return rc ;
2236+ lookup_result_reset (result );
2237+ return btree_lookup_and_merge (
2238+ cc , cfg , root_addr , type , target , result , NULL );
22752239}
22762240
22772241platform_status
@@ -2280,8 +2244,7 @@ btree_lookup_and_merge(cache *cc, // IN
22802244 uint64 root_addr , // IN
22812245 page_type type , // IN
22822246 key target , // IN
2283- key_buffer * keybuf , // OUT
2284- merge_accumulator * data , // OUT
2247+ lookup_result * result , // IN/OUT
22852248 bool32 * local_found ) // OUT
22862249{
22872250 btree_node node ;
@@ -2291,27 +2254,17 @@ btree_lookup_and_merge(cache *cc, // IN
22912254
22922255 log_trace_key (target , "btree_lookup" );
22932256
2294- btree_lookup_with_ref (cc ,
2295- cfg ,
2296- root_addr ,
2297- type ,
2298- target ,
2299- & node ,
2300- & found_key ,
2301- & local_data ,
2302- local_found );
2303- if (* local_found ) {
2304- if (keybuf != NULL ) {
2305- rc = key_buffer_copy_key (keybuf , found_key );
2306- }
2307- if (merge_accumulator_is_null (data )) {
2308- bool32 success = merge_accumulator_copy_message (data , local_data );
2309- if (!success ) {
2310- rc = STATUS_NO_MEMORY ;
2311- }
2312- } else if (btree_merge_tuples (cfg , target , local_data , data )) {
2313- rc = STATUS_NO_MEMORY ;
2257+ if (local_found != NULL ) {
2258+ * local_found = FALSE;
2259+ }
2260+
2261+ btree_lookup_with_ref (
2262+ cc , cfg , root_addr , type , target , & node , & found_key , & local_data );
2263+ if (!key_is_null (found_key )) {
2264+ if (local_found != NULL ) {
2265+ * local_found = TRUE;
23142266 }
2267+ rc = lookup_result_update (result , found_key , local_data );
23152268 btree_node_unget (cc , cfg , & node );
23162269 }
23172270 return rc ;
@@ -2325,11 +2278,8 @@ btree_lookup_and_merge(cache *cc, // IN
23252278 * - state->type: the type of the root node
23262279 * - state->target: the key to look up
23272280 *
2328- * IN/OUT Parameters:
2329- * - state->result: the result of the lookup
2330- *
23312281 * OUT Parameters:
2332- * - state->found: whether the target was found in the leaf
2282+ * - state->found_key: the key found in the leaf, or NULL_KEY otherwise.
23332283 *
23342284 * LOCAL Variables:
23352285 * - state->node: the node found
@@ -2347,26 +2297,20 @@ btree_lookup_and_merge_async(btree_lookup_async_state *state)
23472297 async_await_subroutine (state , btree_lookup_with_ref_async );
23482298
23492299 platform_status rc = STATUS_OK ;
2350- if (state -> found ) {
2351- if (state -> keybuf != NULL ) {
2352- rc = key_buffer_copy_key (state -> keybuf , state -> found_key );
2353- }
2354- if (merge_accumulator_is_null (state -> result )) {
2355- bool32 success =
2356- merge_accumulator_copy_message (state -> result , state -> msg );
2357- if (!success ) {
2358- rc = STATUS_NO_MEMORY ;
2359- }
2360- } else if (btree_merge_tuples (
2361- state -> cfg , state -> target , state -> msg , state -> result ))
2362- {
2363- rc = STATUS_NO_MEMORY ;
2364- }
2300+ if (!key_is_null (state -> found_key )) {
2301+ rc = lookup_result_update (state -> result , state -> found_key , state -> msg );
23652302 btree_node_unget (state -> cc , state -> cfg , & state -> node );
23662303 }
23672304 async_return (state , rc );
23682305}
23692306
2307+ async_status
2308+ btree_lookup_async (btree_lookup_async_state * state )
2309+ {
2310+ lookup_result_reset (state -> result );
2311+ return btree_lookup_and_merge_async (state );
2312+ }
2313+
23702314/*
23712315 *-----------------------------------------------------------------------------
23722316 * btree_iterator_init --
0 commit comments