void peers_restore(gchar **targets, struct sqlx_name_s *name, GByteArray *dump) { GError *err = NULL; if (!targets || !targets[0]) { g_byte_array_unref(dump); return ; } GByteArray *encoded = _pack_RESTORE(name, dump); struct gridd_client_s **clients = gridd_client_create_many(targets, encoded, NULL, NULL); g_byte_array_unref(encoded); gridd_clients_set_timeout(clients, SQLX_RESYNC_TIMEOUT); gridd_clients_start(clients); if (!(err = gridd_clients_loop(clients))) err = gridd_clients_error(clients); gridd_clients_free(clients); if (err) { GRID_WARN("RESTORE failed [%s][%s] : (%d) %s", name->base, name->type, err->code, err->message); g_clear_error(&err); } }
GError* sqlx_remote_execute_DESTROY_many(gchar **targets, GByteArray *sid, struct sqlx_name_s *name) { (void) sid; GError *err = NULL; GByteArray *req = sqlx_pack_DESTROY(name, TRUE); struct gridd_client_s **clients = gridd_client_create_many(targets, req, NULL, NULL); metautils_gba_unref(req); req = NULL; if (clients == NULL) { err = NEWERROR(0, "Failed to create gridd clients"); return err; } gridd_clients_start(clients); err = gridd_clients_loop(clients); for (struct gridd_client_s **p = clients; !err && p && *p ;p++) { if (!(err = gridd_client_error(*p))) continue; GRID_DEBUG("Database destruction attempts failed: (%d) %s", err->code, err->message); if (err->code == CODE_CONTAINER_NOTFOUND || err->code == 404) { g_clear_error(&err); continue; } } gridd_clients_free(clients); return err; }
GError* sqlx_remote_execute_RESTORE_many(gchar **targets, GByteArray *sid, struct sqlx_name_s *name, GByteArray *dump) { (void) sid; GError *err = NULL; GByteArray *req = sqlx_pack_RESTORE(name, dump->data, dump->len); struct client_s **clients = gridd_client_create_many(targets, req, NULL, NULL); metautils_gba_unref(req); req = NULL; if (clients == NULL) { err = NEWERROR(0, "Failed to create gridd clients"); return err; } gridd_clients_start(clients); err = gridd_clients_loop(clients); for (struct client_s **p = clients; !err && p && *p; p++) { err = gridd_client_error(*p); } gridd_clients_free(clients); return err; }
GError* m2v2_remote_execute_DESTROY_many(gchar **targets, struct oio_url_s *url, guint32 flags) { if (!targets) return NEWERROR(CODE_INTERNAL_ERROR, "invalid target array (NULL)"); // TODO: factorize with sqlx_remote_execute_DESTROY_many GByteArray *req = m2v2_remote_pack_DESTROY(url, flags | M2V2_DESTROY_LOCAL); struct gridd_client_s **clients = gridd_client_create_many(targets, req, NULL, NULL); metautils_gba_unref(req); req = NULL; if (clients == NULL) return NEWERROR(0, "Failed to create gridd clients"); gridd_clients_start(clients); GError *err = gridd_clients_loop(clients); for (struct gridd_client_s **p = clients; !err && p && *p ;p++) { if (!(err = gridd_client_error(*p))) continue; GRID_DEBUG("Database destruction attempts failed: (%d) %s", err->code, err->message); if (err->code == CODE_CONTAINER_NOTFOUND || err->code == CODE_NOT_FOUND) { g_clear_error(&err); continue; } } gridd_clients_free(clients); return err; }
GError* sqlx_remote_execute_packed_DESTROY_many(gchar **targets, GByteArray *sid, GByteArray *req) { (void) sid; GError *err = NULL, *local_err = NULL; GPtrArray *targets_ok = g_ptr_array_new(); struct client_s **clients = gridd_client_create_many(targets, req, NULL, NULL); metautils_gba_unref(req); req = NULL; if (clients == NULL) { err = NEWERROR(0, "Failed to create gridd clients"); return err; } gridd_clients_start(clients); err = gridd_clients_loop(clients); for (gchar **cursor = targets; cursor && *cursor; cursor++) { metautils_str_clean(cursor); } if (err) goto end; for (struct client_s **p = clients; p && *p; p++) { if (!(local_err = gridd_client_error(*p))) { g_ptr_array_add(targets_ok, g_strdup(gridd_client_url(*p))); continue; } if (local_err->code == CODE_CONTAINER_NOTFOUND || local_err->code == CODE_NOT_FOUND) { g_clear_error(&local_err); g_ptr_array_add(targets_ok, g_strdup(gridd_client_url(*p))); continue; } GRID_DEBUG("Database destruction attempts failed: (%d) %s", local_err->code, local_err->message); if (!err) g_propagate_prefixed_error(&err, local_err, "Failed to destroy base on %s: ", gridd_client_url(*p)); else g_clear_error(&local_err); } for (guint i = 0; i < targets_ok->len; i++) { targets[i] = g_ptr_array_index(targets_ok, i); } end: g_ptr_array_free(targets_ok, TRUE); gridd_clients_free(clients); return err; }