static void
fill_service_info_score(struct conscience_s *conscience, struct service_info_s *si)
{
	struct conscience_srv_s *srv;
	struct conscience_srvtype_s *srvtype;

	si->score.value = SCORE_UNSET;
	srvtype = conscience_get_srvtype(conscience, NULL, si->type, MODE_STRICT);
	if (srvtype) {
		srv = conscience_srvtype_get_srv(srvtype, (struct conscience_srvid_s*)&(si->addr));
		if (srv)
			si->score.value = srv->score.value;
	}
}
예제 #2
0
/**
 * Find the service in the conscience and set its score to 0, and call
 * zero_service_stats() on the conscience service.
 */
static void
invalidate_conscience_service(struct namespace_data_s *ns_data, struct service_info_s *si)
{
	GError *error;
	struct conscience_srvtype_s *srvtype;
	struct conscience_srv_s *srv;
	struct conscience_srvid_s srvid;

	error = NULL;

	srvtype = conscience_get_srvtype(ns_data->conscience, &error, si->type, MODE_STRICT);
	if (srvtype) {
		memcpy(&(srvid.addr), &(si->addr), sizeof(addr_info_t));
		srv = conscience_srvtype_get_srv(srvtype, &srvid);
		if (srv) {
			srv->score.value = 0;
			zero_service_stats(srv->tags);
		}
	}
	if (error)
		g_error_free(error);
}
예제 #3
0
struct conscience_srv_s *
conscience_srvtype_refresh(struct conscience_srvtype_s *srvtype, struct service_info_s *si)
{
	g_assert_nonnull (srvtype);
	g_assert_nonnull (si);

	struct conscience_srvid_s srvid;
	memcpy(&(srvid.addr), &(si->addr), sizeof(addr_info_t));

	struct service_tag_s *tag_first =
		service_info_get_tag(si->tags, NAME_TAGNAME_RAWX_FIRST);
	gboolean really_first = FALSE;

	/*register the service if necessary */
	struct conscience_srv_s *p_srv = conscience_srvtype_get_srv(srvtype, &srvid);
	if (!p_srv) {
		p_srv = conscience_srvtype_register_srv(srvtype, NULL, &srvid);
		g_assert_nonnull (p_srv);
		really_first = tag_first && tag_first->type == STVT_BOOL && tag_first->value.b;
	}

	/* refresh the tags: create missing, replace existing
	 * (but the tags are not flushed before) */
	if (si->tags) {
		TRACE("Refreshing tags for srv [%.*s]",
				(int)(LIMIT_LENGTH_SRVDESCR), p_srv->description);
		const guint max = si->tags->len;
		for (guint i = 0; i < max; i++) {
			struct service_tag_s *tag = g_ptr_array_index(si->tags, i);
			if (tag == tag_first) continue;
			struct service_tag_s *orig = conscience_srv_ensure_tag(p_srv, tag->name);
			service_tag_copy(orig, tag);
		}
	}

	p_srv->score.timestamp = oio_ext_monotonic_seconds ();
	if (si->score.value == SCORE_UNSET || si->score.value == SCORE_UNLOCK) {
		if (really_first) {
			GRID_TRACE2("SRV first [%s]", p_srv->description);
			p_srv->score.value = 0;
			p_srv->locked = TRUE;
		} else {
			if (si->score.value == SCORE_UNLOCK) {
				if (p_srv->locked) {
					GRID_TRACE2("SRV unlocked [%s]", p_srv->description);
					p_srv->locked = FALSE;
					p_srv->score.value = CLAMP (p_srv->score.value, SCORE_DOWN, SCORE_MAX);
				} else {
					GRID_TRACE2("SRV already unlocked [%s]", p_srv->description);
				}
			} else { /* UNSET, a.k.a. regular computation */
				if (p_srv->locked) {
					GRID_TRACE2("SRV untouched [%s]", p_srv->description);
				} else {
					GError *err = NULL;
					if (!conscience_srv_compute_score(p_srv, &err)) {
						GRID_TRACE2("SRV error [%s]: (%d) %s", p_srv->description, err->code, err->message);
						g_clear_error (&err);
					} else {
						GRID_TRACE2("SRV refreshed [%s]", p_srv->description);
					}
				}
			}
		}
	} else { /* LOCK */
		p_srv->score.value = CLAMP(si->score.value, SCORE_DOWN, SCORE_MAX);
		if (p_srv->locked) {
			GRID_TRACE2("SRV already locked [%s]", p_srv->description);
		} else {
			p_srv->locked = TRUE;
			GRID_TRACE2("SRV locked [%s]", p_srv->description);
		}
	}

	return p_srv;
}