GError *
peer_restore(const gchar *target, struct sqlx_name_s *name,
		GByteArray *dump)
{
	GError *err = NULL;

	if (!target) {
		g_byte_array_unref(dump);
		return NULL;
	}

	GByteArray *encoded = _pack_RESTORE(name, dump);
	struct gridd_client_s *client = gridd_client_create(target, encoded, NULL, NULL);
	g_byte_array_unref(encoded);

	if (!client)
		return NEWERROR(CODE_INTERNAL_ERROR, "Failed to create client to [%s], bad address?", target);

	gridd_client_set_timeout(client, SQLX_RESYNC_TIMEOUT);
	gridd_client_start(client);
	if (!(err = gridd_client_loop(client)))
		err = gridd_client_error(client);
	gridd_client_free(client);
	return err;
}
Beispiel #2
0
static gint
do_queryv(struct meta1_service_url_s *surl)
{
	gint rc;
	gchar **pq;
	struct gridd_client_s *client;

	GRID_DEBUG("Contacting SHARD[%"G_GINT64_FORMAT"] at [%s][%s]",
			surl->seq, surl->host, surl->args);

	client = gridd_client_create_idle(surl->host);
	gridd_client_set_keepalive(client, TRUE);
	gridd_client_start(client);

	rc = 1;
	for (pq=query; *pq ;pq++) {
		if (!do_query(client, surl, *pq)) {
			rc = 0;
			break;
		}
	}

	gridd_client_free(client);
	return rc;
}
GError *
gridd_client_exec_and_concat (const gchar *to, gdouble seconds, GByteArray *req,
		GByteArray **out)
{
	if (!to) {
		g_byte_array_unref (req);
		return NEWERROR(CODE_INTERNAL_ERROR, "No target");
	}

	GByteArray *tmp = NULL;
	if (out)
		tmp = g_byte_array_new();

	struct gridd_client_s *client = gridd_client_create(to, req,
			out ? tmp : NULL, out ? (client_on_reply)_cb_exec_and_concat : NULL);
	g_byte_array_unref (req);
	if (!client) {
		if (tmp) g_byte_array_free (tmp, TRUE);
		return NEWERROR(CODE_INTERNAL_ERROR, "client creation");
	}
	if (seconds > 0.0)
		gridd_client_set_timeout (client, seconds);
	GError *err = gridd_client_run (client);
	gridd_client_free (client);

	if (!err && out) {
		*out = tmp;
		tmp = NULL;
	}
	if (tmp)
		metautils_gba_unref (tmp);
	return err;
}
Beispiel #4
0
GError*
sqlx_remote_execute_ADMGET(const gchar *target, GByteArray *sid,
		struct sqlx_name_s *name, const gchar *k, gchar **v)
{
	(void) sid;
	GError *err = NULL;
	GByteArray *encoded = sqlx_pack_ADMGET(name, k);
	GByteArray *gba_buf = g_byte_array_new();
	struct client_s *client = gridd_client_create(target, encoded,
			gba_buf, on_reply_gba);
	g_byte_array_unref(encoded);

	gridd_client_start(client);
	if (!(err = gridd_client_loop(client))) {
		if (!(err = gridd_client_error(client))) {
			gchar *buf = g_malloc0(gba_buf->len + 1);
			metautils_gba_data_to_string(gba_buf, buf, gba_buf->len + 1);
			*v = buf;
		}
	}

	gridd_client_free(client);
	metautils_gba_unref(gba_buf);
	return err;
}
Beispiel #5
0
void
gridd_clients_free(struct client_s **clients)
{
	if (clients) {
		struct client_s **c;
		for (c=clients; *c ;c++)
			gridd_client_free(*c);
		g_free(clients);
	}
}
Beispiel #6
0
static void
event_client_free(struct event_client_s *ec)
{
	if (!ec)
		return;
	if (ec->on_end)
		ec->on_end(ec);
	if (ec->client)
		gridd_client_free(ec->client);
	memset(ec, 0, sizeof(*ec));
	g_free(ec);
}
Beispiel #7
0
GError*
sqlx_remote_execute_ADMSET(const gchar *target, GByteArray *sid,
		struct sqlx_name_s *name, const gchar *k, const gchar *v)
{
	(void) sid;
	GError *err = NULL;
	GByteArray *encoded = sqlx_pack_ADMSET(name, k, v);
	struct client_s *client = gridd_client_create(target, encoded, NULL, NULL);
	g_byte_array_unref(encoded);
	gridd_client_start(client);
	if (!(err = gridd_client_loop(client)))
		err = gridd_client_error(client);
	gridd_client_free(client);
	return err;
}
Beispiel #8
0
struct client_s *
gridd_client_create_idle(const gchar *target)
{
	struct client_s *client = gridd_client_create_empty();
	if (unlikely(NULL == client))
		return NULL;

	GError *err = gridd_client_connect_url(client, target);
	if (likely(NULL == err))
		return client;

	GRID_WARN("Client creation failed: (%d) %s", err->code, err->message);
	g_clear_error(&err);
	gridd_client_free(client);
	return NULL;
}
struct gridd_client_s *
gridd_client_create(const gchar *target, GByteArray *req, gpointer ctx,
                client_on_reply cb)
{
	EXTRA_ASSERT(req != NULL);

	struct gridd_client_s *client = gridd_client_create_idle(target);
	if (!client)
		return NULL;
	GError *err = gridd_client_request(client, req, ctx, cb);
	if (NULL == err)
		return client;

	GRID_WARN("gridd client creation error : (%d) %s", err->code, err->message);
	g_clear_error(&err);
	gridd_client_free(client);
	return NULL;
}
GError*
sqlx_remote_execute_DESTROY(const gchar *target, GByteArray *sid,
		struct sqlx_name_s *name, gboolean local)
{
	(void) sid;
	GError *err = NULL;
	GByteArray *req = sqlx_pack_DESTROY(name, local);

	struct gridd_client_s *client = gridd_client_create(target, req, NULL, NULL);
	g_byte_array_unref(req);

	gridd_client_start(client);
	if (!(err = gridd_client_loop(client))) {
		err = gridd_client_error(client);
	}

	gridd_client_free(client);
	return err;
}
static void
test_bad_addresses(void)
{
	void test(const gchar *url) {
		GByteArray *req;
		struct gridd_client_s *client;
		GError *err;

		req = _generate_request();
		client = gridd_client_create_empty();
		g_assert(client != NULL);

		err = gridd_client_request(client, req, NULL, NULL);
		g_assert(err == NULL);

		err = gridd_client_connect_url(client, url);
		g_assert(err != NULL);
		g_clear_error (&err);

		g_byte_array_unref(req);
		gridd_client_free(client);
	}
GError *
gridd_client_exec4 (const gchar *to, gdouble seconds, GByteArray *req,
		GByteArray ***out)
{
	if (!to) {
		g_byte_array_unref (req);
		return NEWERROR(CODE_INTERNAL_ERROR, "No target");
	}

	GPtrArray *tmp = NULL;
	if (out)
		tmp = g_ptr_array_new();

	struct gridd_client_s *client = gridd_client_create(to, req,
			(out ? tmp : NULL), out ? (client_on_reply)_cb_exec4 : NULL);
	g_byte_array_unref (req);
	if (!client) {
		if (tmp) g_ptr_array_free (tmp, TRUE);
		return NEWERROR(CODE_INTERNAL_ERROR, "client creation");
	}
	if (seconds > 0.0)
		gridd_client_set_timeout (client, seconds);
	GError *err = gridd_client_run (client);
	gridd_client_free (client);

	if (!err && out) {
		*out = (GByteArray**) metautils_gpa_to_array (tmp, TRUE);
		tmp = NULL;
	}
	if (tmp) {
		g_ptr_array_set_free_func (tmp, (GDestroyNotify)g_byte_array_unref);
		g_ptr_array_free (tmp, TRUE);
		tmp = NULL;
	}
	return err;
}