int dnet_trans_insert_nolock(struct dnet_net_state *st, struct dnet_trans *a) { struct rb_root *root = &st->trans_root; struct rb_node **n = &root->rb_node, *parent = NULL; struct dnet_trans *t; int cmp; while (*n) { parent = *n; t = rb_entry(parent, struct dnet_trans, trans_entry); cmp = dnet_trans_cmp(t->trans, a->trans); if (cmp < 0) n = &parent->rb_left; else if (cmp > 0) n = &parent->rb_right; else return -EEXIST; } if (a->st && a->st->n) dnet_log(a->st->n, DNET_LOG_NOTICE, "%s: %s: added trans: %llu -> %s/%d", dnet_dump_id(&a->cmd.id), dnet_cmd_string(a->cmd.cmd), (unsigned long long)a->trans, dnet_addr_string(&a->st->addr), a->cmd.backend_id); rb_link_node(&a->trans_entry, parent, n); rb_insert_color(&a->trans_entry, root); return 0; }
int dnet_trans_alloc_send(struct dnet_session *s, struct dnet_trans_control *ctl) { struct dnet_node *n = s->node; struct dnet_net_state *st; struct dnet_addr *addr = NULL; int err; if (dnet_session_get_cflags(s) & DNET_FLAGS_DIRECT) { st = dnet_state_search_by_addr(n, &s->direct_addr); addr = &s->direct_addr; } else if(dnet_session_get_cflags(s) & DNET_FLAGS_FORWARD) { st = dnet_state_search_by_addr(n, &s->forward_addr); addr = &s->forward_addr; }else { st = dnet_state_get_first(n, &ctl->id); } if (!st) { dnet_log(n, DNET_LOG_ERROR, "%s: direct: %d, direct-addr: %s, forward: %d: trans_send: could not find network state for address", dnet_dump_id(&ctl->id), !!(dnet_session_get_cflags(s) & DNET_FLAGS_DIRECT), dnet_addr_string(&s->direct_addr), !!(dnet_session_get_cflags(s) & DNET_FLAGS_FORWARD)); err = dnet_trans_send_fail(s, addr, ctl, -ENXIO, 1); } else { err = dnet_trans_alloc_send_state(s, st, ctl); dnet_state_put(st); } return err; }
void iterate_node(Ctx &ctx, const dnet_addr &node) { std::cout << "Iterating node: " << dnet_addr_string(&node) << ":" << node.family << std::endl; std::vector<dnet_iterator_range> ranges; if (ctx.iflags & DNET_IFLAGS_KEY_RANGE) ranges.push_back(ctx.key_range); dnet_id id; memset(&id, 0, sizeof(id)); bool found = false; for (auto it = ctx.routes.begin(), end = ctx.routes.end(); it != end; ++it) { if (dnet_addr_equal(&it->addr, &node)) { dnet_setup_id(&id, it->group_id, it->id.id); found = true; break; } } if (!found) { std::cerr << "Node was not found in the route list" << std::endl; return; } ctx.session->set_groups(std::vector<int>(1, id.group_id)); auto res = ctx.session->start_iterator(ioremap::elliptics::key(id), ranges, DNET_ITYPE_NETWORK, ctx.iflags, ctx.time_begin, ctx.time_end); char buffer[2*DNET_ID_SIZE + 1] = {0}; for (auto it = res.begin(), end = res.end(); it != end; ++it) { std::cout << "node: " << dnet_addr_string(&node) << node.family << ", key: " << dnet_dump_id_len_raw(it->reply()->key.id, DNET_ID_SIZE, buffer) << ", flags: " << it->reply()->user_flags << ", ts: " << it->reply()->timestamp.tsec << "/" << it->reply()->timestamp.tnsec << ", keys: " << it->reply()->iterated_keys << "/" << it->reply()->total_keys << ", status: " << it->reply()->status << ", size: " << it->reply_data().size() << ", data: " << it->reply_data().to_string() << std::endl; } }
static std::set<std::tuple<std::string, int, uint32_t>> get_unique_hosts(session &sess) { std::vector<dnet_route_entry> routes = sess.get_routes(); std::set<std::tuple<std::string, int, uint32_t>> unique_hosts; for (auto it = routes.begin(); it != routes.end(); ++it) { dnet_route_entry &entry = *it; std::string addr = dnet_addr_string(&entry.addr); unique_hosts.insert(std::make_tuple(addr, entry.group_id, entry.backend_id)); } return unique_hosts; }
std::string route_entry_get_address(const dnet_route_entry &entry) { return std::string(dnet_addr_string(&entry.addr)); }
std::string callback_entry_address(const callback_result_entry &result) { return dnet_addr_string(result.address()); }
std::string exec_context_get_address(exec_context &context) { return dnet_addr_string(context.address()); }
std::string lookup_result_get_storage_address(const lookup_result_entry &result) { return std::string(dnet_addr_string(result.storage_address())); }