static void _root_split(struct tree *t, struct node *new_root, struct node *old_root) { struct node *a; struct node *b; struct msg *split_key = NULL; __DEBUG("root split begin, old NID %"PRIu64" , height %d" , old_root->nid , old_root->height); if (old_root->height > 0 || old_root->n_children > 2) _node_split(t, old_root, &a, &b, &split_key); else _leaf_and_lmb_split(t, old_root, &a, &b, &split_key); /* swap two roots */ _root_swap(new_root, old_root); msgcpy(&new_root->pivots[0], split_key); new_root->parts[0].child_nid = a->nid; new_root->parts[1].child_nid = b->nid; msgfree(split_key); cache_unpin(t->cf, b->cpair, make_cpair_attr(b)); node_set_dirty(old_root); node_set_dirty(new_root); t->hdr->height++; status_increment(&t->e->status->tree_root_new_nums); __DEBUG("root split end, old NID %"PRIu64, old_root->nid); }
/* * EFFECT: * - split the child * - add a new pivot(split-key) to parent * ENTER: * - parent is already locked(L_WRITE) * - child is already locked(L_WRITE) * EXITS: * - parent is locked * - child is locked */ void node_split_child(struct tree *t, struct node *parent, struct node *child) { int child_num; struct node *a; struct node *b; struct msg *split_key; if (child->height > 0 || child->n_children > 2) _node_split(t, child, &a, &b, &split_key); else _leaf_and_lmb_split(t, child, &a, &b, &split_key); child_num = node_partition_idx(parent, split_key); /* add pivot to parent */ _add_pivot_to_parent(t, parent, child_num, a, b, split_key); cache_unpin(t->cf, b->cpair, make_cpair_attr(b)); msgfree(split_key); if (child->height > 0) status_increment(&t->e->status->tree_nonleaf_split_nums); else status_increment(&t->e->status->tree_leaf_split_nums); }
void rollentry_free(struct roll_entry *re) { switch (re->type) { case RT_CMDINSERT: msgfree(re->u.cmdinsert.key); xfree(re); break; case RT_CMDDELETE: msgfree(re->u.cmddelete.key); xfree(re); break; case RT_CMDUPDATE: msgfree(re->u.cmdupdate.key); xfree(re); break; } }
/* * save the newly pivot bound to search->pivot_bound */ void _save_pivot_bound(struct search *so, struct node *n, int child_searched) { nassert(n->height > 0); int p = (so->direction == SEARCH_FORWARD) ? child_searched : child_searched - 1; if (p >= 0 && p < (int)(n->u.n.n_children - 1)) { if (so->pivot_bound) msgfree(so->pivot_bound); so->pivot_bound = msgdup(&n->u.n.pivots[p]); } }
void boxfree(Box *b) { int i; if(b == nil) return; for(i=0; i<b->nmsg; i++) msgfree(b->msg[i]); free(b->msg); free(b); }
/* Executes apropriate function as parameters specify. */ void execute (message_t * msg, command_t * cmd) { unsigned int i; if (checkrights (msg)) { logstr ("accepted command %s from %s (%s@%s)\n", cmd->action, msg->sender, msg->ident, msg->host); for (i = 0; i < plugin_count; i++) { /* bad performance impact. meh. */ if (!strcmp(plugins[i]->name, cmd->action)) { logstr ("plugin %s matched\n", plugins[i]->name); plugins[i]->execute (msg, cmd, 1); } else plugins[i]->execute (msg, cmd, 0); } } free (cmd->raw); free (cmd); msgfree (msg); }
void _tree_search_finish(struct search *so) { msgfree(so->pivot_bound); }
/* * apply parent's [leaf, right] messages to child node */ void _apply_msg_to_child(struct node *parent, int child_num, struct node *child, struct msg *left, struct msg *right) { int height; struct basement *bsm; struct basement_iter iter; nassert(child != NULL); nassert(parent->height > 0); height = child->height; if (height == 0) bsm = child->u.l.le->bsm; else bsm = child->u.n.parts[child_num].buffer; basement_iter_init(&iter, bsm); basement_iter_seek(&iter, left); while (basement_iter_valid_lessorequal(&iter, right)) { struct bt_cmd cmd = { .msn = iter.msn, .type = iter.type, .key = &iter.key, .val = &iter.val, .xidpair = iter.xidpair }; if (nessunlikely(height == 0)) leaf_put_cmd(child, &cmd); else nonleaf_put_cmd(child, &cmd); } } /* * apply msgs from ances to leaf basement which are between(include) left and right * REQUIRES: * 1) leaf write-lock * 2) ances all write-lock */ int leaf_apply_ancestors(struct node *leaf, struct ancestors *ances) { struct ancestors *ance; struct msg *left = NULL; struct msg *right = NULL; struct basement_iter iter; struct basement *bsm = leaf->u.l.le->bsm; basement_iter_init(&iter, bsm); basement_iter_seektofirst(&iter); if (basement_iter_valid(&iter)) left = msgdup(&iter.key); basement_iter_seektolast(&iter); if (basement_iter_valid(&iter)) right = msgdup(&iter.key); ance = ances; while (ance && ance->next) { /* apply [leaf, right] to leaf */ _apply_msg_to_child(ance->v, ance->childnum, ance->next->v, left, right); ance = ances->next; } msgfree(left); msgfree(right); return NESS_OK; }