Exemplo n.º 1
0
static void
sqlx_service_action(void)
{
	GError *err = NULL;

	if (!SRV.flag_nolock) {
		err = volume_service_lock (SRV.volume, SRV.service_config->srvtype,
				SRV.announce->str, SRV.ns_name);
		if (err)
			return _action_report_error(err, "Volume lock failed");
	}

	oio_server_volume = SRV.volume;

	gridd_client_pool_set_max(SRV.clients_pool, SRV.max_active);
	network_server_set_maxcnx(SRV.server, SRV.max_passive);
	sqlx_repository_configure_maxbases(SRV.repository, SRV.max_bases);

	election_manager_set_peering(SRV.election_manager, SRV.peering);
	if (SRV.sync)
		election_manager_set_sync(SRV.election_manager, SRV.sync);
	sqlx_repository_set_elections(SRV.repository, SRV.election_manager);

	grid_task_queue_fire(SRV.gtq_reload);
	grid_task_queue_fire(SRV.gtq_admin);
	GRID_DEBUG("All tasks now fired once");

	/* Start the administrative threads */
	SRV.thread_admin = grid_task_queue_run(SRV.gtq_admin, &err);
	if (!SRV.thread_admin)
		return _action_report_error(err, "Failed to start the ADMIN thread");

	SRV.thread_reload = grid_task_queue_run(SRV.gtq_reload, &err);
	if (!SRV.thread_reload)
		return _action_report_error(err, "Failed to start the RELOAD thread");

	SRV.thread_client = g_thread_try_new("clients", _worker_clients, &SRV, &err);
	if (!SRV.thread_client)
		return _action_report_error(err, "Failed to start the CLIENT thread");

	if (SRV.events_queue) {
		SRV.thread_queue = g_thread_try_new("queue", _worker_queue, &SRV, &err);
		if (!SRV.thread_queue)
			return _action_report_error(err, "Failed to start the QUEUE thread");
	}

	/* SERVER/GRIDD main run loop */
	if (!grid_main_is_running())
		return;
	grid_daemon_bind_host(SRV.server, SRV.url->str, SRV.dispatcher);
	err = network_server_open_servers(SRV.server);
	if (NULL != err)
		return _action_report_error(err, "GRIDD bind failure");
	if (!grid_main_is_running())
		return;

	if (NULL != (err = network_server_run(SRV.server)))
		return _action_report_error(err, "GRIDD run failure");
}
Exemplo n.º 2
0
static void
_task_reconfigure_events (gpointer p)
{
	if (!grid_main_is_running ())
		return;
	if (!p || !PSRV(p)->events_queue)
		return;

	struct namespace_info_s *ni = PSRV(p)->nsinfo;
	if (!ni || !ni->options)
		return;

	gint64 i64 = OIO_EVTQ_MAXPENDING;
	gchar *k;

	/* without the prefix */
	i64 = gridcluster_get_nsinfo_int64 (ni, OIO_CFG_EVTQ_MAXPENDING, i64);
	GRID_TRACE("Looking for [%s]: %"G_GINT64_FORMAT, OIO_CFG_EVTQ_MAXPENDING, i64);

	/* with the prefix */
	k = g_strconcat (PSRV(p)->service_config->srvtype, ".",
			OIO_CFG_EVTQ_MAXPENDING, NULL);
	i64 = gridcluster_get_nsinfo_int64 (ni, k, i64);
	GRID_TRACE("Looking for [%s]: %"G_GINT64_FORMAT, k, i64);
	g_free(k);

	if (i64 >= 0 && i64 < G_MAXUINT) {
		guint u = (guint) i64;
		oio_events_queue__set_max_pending (PSRV(p)->events_queue, u);
	}
}
Exemplo n.º 3
0
static void
_task_reconfigure_events (gpointer p)
{
	if (!grid_main_is_running ())
		return;
	if (!p || !PSRV(p)->events_queue)
		return;

	struct namespace_info_s *ni = PSRV(p)->nsinfo;
	if (!ni || !ni->options)
		return;

	gint64 i64 = namespace_info_get_srv_param_i64(ni, NULL,
			PSRV(p)->service_config->srvtype,
			OIO_CFG_EVTQ_MAXPENDING,
			OIO_EVTQ_MAXPENDING);
	GRID_TRACE("Looking for [%s]: %"G_GINT64_FORMAT,
			OIO_CFG_EVTQ_MAXPENDING, i64);

	if (i64 >= 0 && i64 < G_MAXUINT) {
		guint u = (guint) i64;
		oio_events_queue__set_max_pending (PSRV(p)->events_queue, u);
	}

	i64 = namespace_info_get_srv_param_i64(ni, NULL,
			PSRV(p)->service_config->srvtype,
			OIO_CFG_EVTQ_BUFFER_DELAY,
			OIO_EVTQ_BUFFER_DELAY);
	if (i64 >= 0 && i64 < 3600) {
		oio_events_queue__set_buffering(PSRV(p)->events_queue,
				i64 * G_TIME_SPAN_SECOND);
	}
}
Exemplo n.º 4
0
static void
_task_expire_resolver(gpointer p)
{
	if (!grid_main_is_running ())
		return;

	guint count = hc_resolver_expire(PSRV(p)->resolver);
	if (count)
		GRID_DEBUG("Expired %u entries from the resolver cache", count);
}
Exemplo n.º 5
0
static void
_task_expire_resolver(gpointer p)
{
	if (!grid_main_is_running ())
		return;

	hc_resolver_set_now(PSRV(p)->resolver, oio_ext_monotonic_time () / G_TIME_SPAN_SECOND);
	guint count = hc_resolver_expire(PSRV(p)->resolver);
	if (count)
		GRID_DEBUG("Expired %u entries from the resolver cache", count);
}
Exemplo n.º 6
0
static void
_task_reload_workers(gpointer p)
{
	if (!grid_main_is_running ())
		return;
	if (!PSRV(p)->nsinfo)
		return;

	gint64 max_workers = namespace_info_get_srv_param_i64 (PSRV(p)->nsinfo,
			NULL, PSRV(p)->service_config->srvtype, "max_workers",
			SRV.cfg_max_workers);
	network_server_set_max_workers(PSRV(p)->server, (guint) max_workers);
}
Exemplo n.º 7
0
static void
_task_expire_bases(gpointer p)
{
	if (!grid_main_is_running ())
		return;

	struct sqlx_cache_s *cache = sqlx_repository_get_cache(PSRV(p)->repository);
	if (cache != NULL) {
		guint count = sqlx_cache_expire(cache, 100, 500 * G_TIME_SPAN_MILLISECOND);
		if (count)
			GRID_DEBUG("Expired %u bases", count);
	}
}
Exemplo n.º 8
0
static gpointer
_worker_clients(gpointer p)
{
	metautils_ignore_signals();
	while (grid_main_is_running()) {
		GError *err = gridd_client_pool_round(PSRV(p)->clients_pool, 1);
		if (err != NULL) {
			GRID_ERROR("Clients error : (%d) %s", err->code, err->message);
			g_clear_error(&err);
			grid_main_stop();
		}
	}
	return p;
}
Exemplo n.º 9
0
static void
_task_react_elections(gpointer p)
{
	if (!grid_main_is_running ())
		return;
	if (!PSRV(p)->flag_replicable)
		return;

	gint64 t = oio_ext_monotonic_time();
	guint count = election_manager_play_timers (PSRV(p)->election_manager,
			PSRV(p)->max_elections_timers_per_round);
	t = t - oio_ext_monotonic_time();

	if (count || t > (500*G_TIME_SPAN_MILLISECOND)) {
		GRID_DEBUG("Reacted %u elections in %"G_GINT64_FORMAT"ms",
				count, t / G_TIME_SPAN_MILLISECOND);
	}
}
Exemplo n.º 10
0
static void
_task_reload_nsinfo(gpointer p)
{
	if (!grid_main_is_running ())
		return;

	struct namespace_info_s *ni = NULL, *old = NULL;
	GError *err = conscience_get_namespace(PSRV(p)->ns_name, &ni);
	EXTRA_ASSERT ((err != NULL) ^ (ni != NULL));

	if (err) {
		GRID_WARN("NSINFO reload error [%s]: (%d) %s",
				PSRV(p)->ns_name, err->code, err->message);
		g_clear_error(&err);
	} else {
		old = PSRV(p)->nsinfo;
		PSRV(p)->nsinfo = ni;
		namespace_info_free(old);
	}
}
Exemplo n.º 11
0
void
sqlx_task_reload_lb (struct sqlx_service_s *ss)
{
	EXTRA_ASSERT(ss != NULL);
	ADAPTIVE_PERIOD_DECLARE();

	if (!grid_main_is_running ())
		return;
	if (!ss->lb || !ss->nsinfo)
		return;
	if (ADAPTIVE_PERIOD_SKIP())
		return;

	GError *err = _reload_lbpool(ss->lb, FALSE);
	if (!err) {
		ADAPTIVE_PERIOD_ONSUCCESS(10);
	} else {
		GRID_WARN("Failed to reload the LB pool services: (%d) %s",
				err->code, err->message);
		g_clear_error(&err);
	}

	grid_lbpool_reconfigure(ss->lb, ss->nsinfo);
}
Exemplo n.º 12
0
static gboolean
_event_running (gboolean pending)
{
	(void) pending;
	return grid_main_is_running ();
}