Exemplo n.º 1
0
/*
 * returns (CS_TRUE == OK, CS_FALSE == failed)
 */
static int32_t wd_resource_state_is_ok (struct resource *ref)
{
	char* state;
	uint64_t last_updated;
	uint64_t my_time;
	uint64_t allowed_period;
	char key_name[ICMAP_KEYNAME_MAXLEN];

	snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "%s%s", ref->res_path, "last_updated");
	if (icmap_get_uint64(key_name, &last_updated) != CS_OK) {
		/* key does not exist.
		*/
		return CS_FALSE;
	}

	snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "%s%s", ref->res_path, "state");
	if (icmap_get_string(key_name, &state) != CS_OK || strcmp(state, "disabled") == 0) {
		/* key does not exist.
		*/
		return CS_FALSE;
	}
	free (state);

	if (last_updated == 0) {
		/* initial value */
		free(state);
		return CS_TRUE;
	}

	my_time = cs_timestamp_get();

	/*
	 * Here we check that the monitor has written a timestamp within the poll_period
	 * plus a grace factor of (0.5 * poll_period).
	 */
	allowed_period = (ref->check_timeout * MILLI_2_NANO_SECONDS * 3) / 2;
	if ((last_updated + allowed_period) < my_time) {
		log_printf (LOGSYS_LEVEL_ERROR,
			"last_updated %"PRIu64" ms too late, period:%"PRIu64".",
			(uint64_t)(my_time/MILLI_2_NANO_SECONDS - ((last_updated + allowed_period) / MILLI_2_NANO_SECONDS)),
			ref->check_timeout);
		free(state);
		return CS_FALSE;
	}

	if (strcmp (state, wd_failed_str) == 0) {
		free(state);
		return CS_FALSE;
	}

	free(state);
	return CS_TRUE;
}
Exemplo n.º 2
0
/*
 * returns (CS_TRUE == OK, CS_FALSE == failed)
 */
static int32_t wd_resource_state_is_ok (struct resource *ref)
{
	hdb_handle_t resource = ref->handle;
	int res;
	char* state;
	size_t state_len;
	objdb_value_types_t type;
	uint64_t *last_updated;
	uint64_t my_time;
	uint64_t allowed_period;
	size_t last_updated_len;

	res = api->object_key_get_typed (resource,
		"last_updated", (void*)&last_updated, &last_updated_len, &type);
	if (res != 0) {
		/* key does not exist.
		*/
		return CS_FALSE;
	}
	res = api->object_key_get_typed (resource,
		"state", (void**)&state, &state_len, &type);
	if (res != 0 ||	strncmp (state, "disabled", strlen ("disabled")) == 0) {
		/* key does not exist.
		*/
		return CS_FALSE;
	}
	if (*last_updated == 0) {
		/* initial value */
		return CS_TRUE;
	}

	my_time = cs_timestamp_get();

	/*
	 * Here we check that the monitor has written a timestamp within the poll_period
	 * plus a grace factor of (0.5 * poll_period).
	 */
	allowed_period = (ref->check_timeout * MILLI_2_NANO_SECONDS * 3) / 2;
	if ((*last_updated + allowed_period) < my_time) {
		log_printf (LOGSYS_LEVEL_ERROR,
			"last_updated %"PRIu64" ms too late, period:%"PRIu64".",
			(uint64_t)(my_time/MILLI_2_NANO_SECONDS - ((*last_updated + allowed_period) / MILLI_2_NANO_SECONDS)),
			ref->check_timeout);
		return CS_FALSE;
	}

	if (strcmp (state, wd_failed_str) == 0) {
		return CS_FALSE;
	}
	return CS_TRUE;
}
Exemplo n.º 3
0
static cs_error_t sam_confdb_update_key (enum sam_confdb_key_t key, const char *value)
{
	cs_error_t err;
	const char *svalue;
	uint64_t hc_period, last_hc;
	const char *ssvalue[] = { [SAM_RECOVERY_POLICY_QUIT] = "quit", [SAM_RECOVERY_POLICY_RESTART] = "restart" };

	switch (key) {
	case SAM_CONFDB_KEY_RECOVERY:
		svalue = ssvalue[SAM_RP_MASK (sam_internal_data.recovery_policy)];

		if ((err = confdb_key_create_typed (sam_internal_data.confdb_handle, sam_internal_data.confdb_pid_handle,
			"recovery", svalue, strlen ((const char *)svalue), CONFDB_VALUETYPE_STRING)) != CS_OK) {
			goto exit_error;
		}
		break;
	case SAM_CONFDB_KEY_HC_PERIOD:
		hc_period = sam_internal_data.time_interval;

		if ((err = confdb_key_create_typed (sam_internal_data.confdb_handle, sam_internal_data.confdb_pid_handle,
			"poll_period", &hc_period, sizeof (hc_period), CONFDB_VALUETYPE_UINT64)) != CS_OK) {
			goto exit_error;
		}
		break;
	case SAM_CONFDB_KEY_LAST_HC:
		last_hc = cs_timestamp_get();

		if ((err = confdb_key_create_typed (sam_internal_data.confdb_handle, sam_internal_data.confdb_pid_handle,
			"last_updated", &last_hc, sizeof (last_hc), CONFDB_VALUETYPE_UINT64)) != CS_OK) {
			goto exit_error;
		}
		break;
	case SAM_CONFDB_KEY_STATE:
		svalue = value;
		if ((err = confdb_key_create_typed (sam_internal_data.confdb_handle, sam_internal_data.confdb_pid_handle,
			"state", svalue, strlen ((const char *)svalue), CONFDB_VALUETYPE_STRING)) != CS_OK) {
			goto exit_error;
		}
		break;
	}

	return (CS_OK);

exit_error:
	return (err);
}