Пример #1
0
static GError*
location_from_chunk_id(const gchar *chunk_id, const gchar *ns_name,
		struct oio_lb_pool_s *pool, oio_location_t *location)
{
	g_assert_nonnull(location);
	GError *err = NULL;
	if (chunk_id == NULL || strlen(chunk_id) <= 0)
		return NEWERROR(CODE_INTERNAL_ERROR, "emtpy chunk id");

	gchar *netloc = NULL;
	oio_parse_chunk_url(chunk_id, NULL, &netloc, NULL);

	if (pool) {
		gchar *key = oio_make_service_key(ns_name, NAME_SRVTYPE_RAWX, netloc);
		struct oio_lb_item_s *item = oio_lb_pool__get_item(pool, key);
		g_free(key);
		if (item) {
			*location = item->location;
			g_free(item);
			goto out;
		}
	}

	addr_info_t ai = {{0}};
	if (!err && !grid_string_to_addrinfo(netloc, &ai))
		err = NEWERROR(CODE_INTERNAL_ERROR,
				"could not parse [%s] to addrinfo", netloc);
	if (!err)
		*location = location_from_addr_info(&ai);

out:
	g_free(netloc);
	return err;
}
Пример #2
0
// TODO(srvid): do not suppose url is an IP address
static oio_location_t *
__locations_from_m1srvurl(struct meta1_service_url_s **urls)
{
    GArray *out = g_array_new(TRUE, TRUE, sizeof(oio_location_t));
    struct meta1_service_url_s **cursor = NULL;
    for (cursor = urls; cursor && *cursor; cursor++) {
        struct meta1_service_url_s **extracted;
        extracted = expand_url(*cursor);
        addr_info_t ai = {{0}};
        if (!grid_string_to_addrinfo((*extracted)->host, &ai))
            GRID_WARN("Could not parse [%s] to addrinfo", (*cursor)->host);
        else {
            oio_location_t loc = location_from_addr_info(&ai);
            g_array_append_val(out, loc);
        }
        meta1_service_url_cleanv(extracted);
        extracted = NULL;
    }
    return (oio_location_t*)g_array_free(out, FALSE);
}
void
service_info_to_lb_item(const struct service_info_s *si,
		struct oio_lb_item_s *item)
{
	g_assert_nonnull(si);
	g_assert_nonnull(item);
	/* Take location from:
	 * - tag.loc as a hexadecimal number or
	 * - tag.log as a hash dot-separated string or
	 * - IP address and port */
	const gchar *loc_str = service_info_get_tag_value(si, "tag.loc", NULL);
	if (!loc_str) {
		item->location = location_from_addr_info(&(si->addr));
	} else if (!g_str_has_prefix(loc_str, "0x") ||
			!(item->location = g_ascii_strtoull(loc_str, NULL, 16))) {
		item->location = location_from_dotted_string(loc_str);
	}
	item->weight = CLAMP(si->score.value, 0, 100);
	gchar *key = service_info_key(si);
	g_strlcpy(item->id, key, LIMIT_LENGTH_SRVID);
	g_free(key);
}