On Sun, Oct 13, 2024 at 08:45:59PM GMT, yuan fang wrote:
> Dear Kent, I am looking at the function int
> bch2_btree_path_traverse_one(struct btree_trans *trans, btree_path_idx_t
> path_idx, unsigned flags, unsigned long trace_ip), and I noticed that
> path->level
> = btree_path_up_until_good_node(trans, path, 0); sets check_pos to 0.
> According to the function:
>
> static inline bool btree_path_check_pos_in_node(struct btree_path *path,
> unsigned l, int check_pos){
> // Check if the position is before the node and return false if it is.
> if (check_pos < 0 && btree_path_pos_before_node(path, path->l[l].b))
> return false;
>
> // Check if the position is after the node and return false if it is.
> if (check_pos > 0 && btree_path_pos_after_node(path, path->l[l].b))
> return false;
>
> // If the position is within the valid range, return true.
> return true;}
>
> When check_pos is 0, it directly returns true. It doesn’t seem to check if
> the key position is on the bnode corresponding to path->level. This is
> somewhat confusing to me. If it always returns true, can it find the good
> node? By the way, my understanding of a good node in your code is that it
> either contains the key we’re looking for or can lead us progressively to
> search for the key.
Correct, when check_pos is 0 path->pos hasn't changed so we don't need
those checks - it's called with check_pos nonzero in set_pos, when we're
advancing or rewinding path->pos.
When check_pos is 0, we're being called from path_traverse(); we just
want a node that's locked or that we can relock - if we can relock it,
we were using it previously and we know that path->pos is in the range
for that node.