/* search in a node's child */ int _search_child(struct cursor *cur, struct search *so, struct node *n, int childnum) { int ret; NID child_nid; int child_to_search; struct node *child; nassert(n->height > 0); ancestors_append(cur, n->parts[childnum].msgbuf); child_nid = n->parts[childnum].child_nid; if (!cache_get_and_pin(cur->tree->cf, child_nid, (void**)&child, L_READ)) { __ERROR("cache get node error, nid [%" PRIu64 "]", child_nid); return NESS_ERR; } child_to_search = _search_in_which_child(so, child); ret = _search_node(cur, so, child, child_to_search); /* unpin */ cache_unpin(cur->tree->cf, child->cpair); return ret; }
/* search in a node's child */ int _search_child(struct cursor *cur, struct search *so, struct node *n, int childnum) { int ret; int child_to_search; NID child_nid; struct node *child; struct cache_operations *c_op = cur->tree->cache->c_op; nassert(n->height > 0); /* add basement to ances */ ancestors_append(cur, n->u.n.parts[childnum].buffer); child_nid = n->u.n.parts[childnum].child_nid; if (c_op->cache_get_and_pin(cur->tree->cache, child_nid, &child, L_READ) < 0) { __ERROR("cache get node error, nid [%" PRIu64 "]", child_nid); return NESS_ERR; } child_to_search = _search_in_which_child(so, child); ret = _search_node(cur, so, child, child_to_search); /* unpin */ c_op->cache_unpin_readonly(cur->tree->cache, child); return ret; }
int _search_leaf(struct cursor *cur, struct search *so, struct node *n) { int i = 0; int bsms_size; struct ancestors *ances; ancestors_append(cur, n->u.l.le->bsm); ances = cur->ances; bsms_size = cur->ances_size; struct basement *bsms[bsms_size]; /* * bsms[0 - 1] is memtable basement * the last one is root's */ while (ances) { bsms[i++] = (struct basement*) ances->v; ances = ances->next; } switch (so->direction) { case SEARCH_FORWARD: return _findsmallest(bsms, bsms_size, cur, so); break; case SEARCH_BACKWARD: return _findlargest(bsms, bsms_size, cur, so); break; default: __PANIC("unsupport direction %u", so->direction); } }