From: František Dvořák Date: Thu, 6 Oct 2005 15:43:15 +0000 (+0000) Subject: Fixed error handling (different place, negate condition in SQL). X-Git-Tag: gridsite-core_R_1_1_12~7 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=b1741f2a045bd96c6eea4cff61396b6d9725d23a;p=jra1mw.git Fixed error handling (different place, negate condition in SQL). --- diff --git a/org.glite.jp.index/src/bones_server.c b/org.glite.jp.index/src/bones_server.c index 25a4f18..d4376b6 100644 --- a/org.glite.jp.index/src/bones_server.c +++ b/org.glite.jp.index/src/bones_server.c @@ -6,14 +6,14 @@ #include #include -#include "glite/jp/types.h" -#include "glite/jp/context.h" +#include +#include -#include "glite/lb/srvbones.h" -#include "glite/security/glite_gss.h" +#include +#include #include -#include "glite/security/glite_gsplugin.h" +#include #include "conf.h" #include "db_ops.h" @@ -40,8 +40,6 @@ extern SOAP_NMAC struct Namespace jpis__namespaces[],jpps__namespaces[]; extern SOAP_NMAC struct Namespace namespaces[] = { {NULL,NULL} }; // namespaces[] not used here, but need to prevent linker to complain... -extern void MyFeedIndex(glite_jpis_context_t ctx, glite_jp_is_conf *conf, long int uniqueid, char *dest); - static int newconn(int,struct timeval *,void *); static int request(int,struct timeval *,void *); static int reject(int); @@ -192,8 +190,8 @@ int main(int argc, char *argv[]) static int data_init(void **data) { slave_data_t *private; - char *PS_URL = NULL; long int uniqueid; + char *PS_URL = NULL; private = calloc(sizeof(*private), 1); glite_jpis_init_context(&private->ctx, ctx, conf); @@ -207,28 +205,28 @@ static int data_init(void **data) /* ask PS server for data */ do { switch (glite_jpis_lockUninitializedFeed(private->ctx,&uniqueid,&PS_URL)) { + case 0: + // contact PS server, ask for data, save feedId and expiration + // to DB and unlock feed + if (MyFeedIndex(private->ctx, conf, uniqueid, PS_URL) != 0) { + printf("[%d] slave_init(): %s (%s), reconnecting later\n", getpid(), ctx->error->desc, ctx->error->source); + // error when connecting to PS + glite_jpis_tryReconnectFeed(private->ctx, uniqueid, + time(NULL) + RECONNECT_TIME); + } + free(PS_URL); + PS_URL = NULL; + break; case ENOENT: // no more feeds to initialize return 0; - case ENOLCK: + default: // error during locking printf("[%d] slave_init(): Locking error.\n",getpid()); free(PS_URL); glite_jpis_free_db(private->ctx); glite_jpis_free_context(private->ctx); return -1; - case ENOTCONN: - // error when connecting to PS - glite_jpis_tryReconnectFeed(private->ctx, uniqueid, - time(NULL) + RECONNECT_TIME); - break; - default: - // contact PS server, ask for data, save feedId and expiration - // to DB and unlock feed - MyFeedIndex(private->ctx, conf, uniqueid, PS_URL); - free(PS_URL); - PS_URL = NULL; - break; } } while (1); } diff --git a/org.glite.jp.index/src/db_ops.c b/org.glite.jp.index/src/db_ops.c index 3dbc8d9..87ccd16 100644 --- a/org.glite.jp.index/src/db_ops.c +++ b/org.glite.jp.index/src/db_ops.c @@ -411,7 +411,7 @@ int glite_jpis_init_db(glite_jpis_context_t isctx) { glite_jp_db_create_results(&myres, 2, GLITE_JP_DB_TYPE_INT, NULL, &(isctx->param_uniqueid), GLITE_JP_DB_TYPE_VARCHAR, NULL, isctx->param_ps, sizeof(isctx->param_ps), &isctx->param_ps_len); - if ((ret = glite_jp_db_prepare(jpctx, "SELECT uniqueid, source FROM feeds WHERE (locked=0) AND (feedid IS NULL) AND ((state <> " GLITE_JP_IS_STATE_ERROR_STR ") OR (expires >= ?))", &isctx->select_unlocked_feed_stmt, myparam, myres)) != 0) goto fail; + if ((ret = glite_jp_db_prepare(jpctx, "SELECT uniqueid, source FROM feeds WHERE (locked=0) AND (feedid IS NULL) AND ((state <> " GLITE_JP_IS_STATE_ERROR_STR ") OR (expires <= ?))", &isctx->select_unlocked_feed_stmt, myparam, myres)) != 0) goto fail; // sql command: lock the feed (via uniqueid) glite_jp_db_create_params(&myparam, 1, GLITE_JP_DB_TYPE_INT, &isctx->param_uniqueid); @@ -484,8 +484,10 @@ void glite_jpis_free_db(glite_jpis_context_t ctx) { int glite_jpis_lockUninitializedFeed(glite_jpis_context_t ctx, long int *uniqueid, char **PS_URL) { int ret; + time_t now; - glite_jp_db_set_time(ctx->param_expires, time(NULL)); + now = time(NULL); + glite_jp_db_set_time(ctx->param_expires, now); do { switch (glite_jp_db_execute(ctx->select_unlocked_feed_stmt)) { case -1: lprintf("error selecting unlocked feed\n"); return ENOLCK; @@ -493,10 +495,10 @@ int glite_jpis_lockUninitializedFeed(glite_jpis_context_t ctx, long int *uniquei default: break; } if (glite_jp_db_fetch(ctx->select_unlocked_feed_stmt) != 0) return ENOLCK; - lprintf("selected uninit. feed %lu\n", ctx->param_uniqueid); + lprintf("selected uninit. feed %ld\n", ctx->param_uniqueid); ret = glite_jp_db_execute(ctx->lock_feed_stmt); - lprintf("locked %d feeds (uniqueid=%lu)\n", ret, ctx->param_uniqueid); + lprintf("locked %d feeds (uniqueid=%ld, time=%ld)\n", ret, ctx->param_uniqueid, now); } while (ret != 1); *uniqueid = ctx->param_uniqueid; @@ -541,6 +543,7 @@ int glite_jpis_unlockFeed(glite_jpis_context_t ctx, long int uniqueid) { /* Saves TTL (when to reconnect if error occured) for given feed */ int glite_jpis_tryReconnectFeed(glite_jpis_context_t ctx, long int uniqueid, time_t reconn_time) { + lprintf("reconnect, un=%ld, %ld\n", uniqueid, reconn_time); ctx->param_uniqueid = uniqueid; ctx->param_state = GLITE_JP_IS_STATE_ERROR; glite_jp_db_set_time(ctx->param_expires, reconn_time); diff --git a/org.glite.jp.index/src/soap_ps_calls.c b/org.glite.jp.index/src/soap_ps_calls.c index 3d6bb30..536d59f 100644 --- a/org.glite.jp.index/src/soap_ps_calls.c +++ b/org.glite.jp.index/src/soap_ps_calls.c @@ -76,7 +76,7 @@ static int find_dest_index(glite_jp_is_conf *conf, char *dest) // call PS FeedIndex for a given destination -void MyFeedIndex(glite_jpis_context_t ctx, glite_jp_is_conf *conf, long int uniqueid, char *dest) +int MyFeedIndex(glite_jpis_context_t ctx, glite_jp_is_conf *conf, long int uniqueid, char *dest) { struct _jpelem__FeedIndex in; struct _jpelem__FeedIndexResponse out; @@ -85,7 +85,8 @@ void MyFeedIndex(glite_jpis_context_t ctx, glite_jp_is_conf *conf, long int uniq // struct xsd__base64Binary blob; int i, dest_index; struct soap *soap = soap_new(); - + glite_jp_error_t err; + char *src; printf("MyFeedIndex for %s called\n", dest); @@ -93,6 +94,7 @@ printf("MyFeedIndex for %s called\n", dest); soap_set_namespaces(soap,jpps__namespaces); memset(&in, 0, sizeof(in)); + memset(&err, 0, sizeof(err)); for (i=0; conf->attrs[i]; i++) ; in.__sizeattributes = i; @@ -102,12 +104,15 @@ printf("MyFeedIndex for %s called\n", dest); for (i=0; conf->feeds[dest_index]->query[i]; i++); in.__sizeconditions = i; - in.conditions = malloc(in.__sizeconditions * sizeof(*in.conditions)); + in.conditions = soap_malloc(soap, in.__sizeconditions * sizeof(*in.conditions)); for (i=0; conf->feeds[dest_index]->query[i]; i++) { if (glite_jpis_QueryCondToSoap(soap, conf->feeds[dest_index]->query[i], &(in.conditions[i])) != SOAP_OK) { - printf("MyFeedIndex() - error during conds conversion\n"); + err.code = EINVAL; + err.desc = "error during conds conversion"; + asprintf(&src, "%s/%s():%d", __FILE__, __FUNCTION__, __LINE__); + printf("%s\n", src); goto err; } } @@ -117,8 +122,12 @@ printf("MyFeedIndex for %s called\n", dest); //if (!check_fault(soap,soap_call_jpsrv___FeedIndex(soap,dest,"", if (soap_call___jpsrv__FeedIndex(soap,dest,"", &in, &out)) { - printf("soap_call___jpsrv__FeedIndex() returned error\n"); + printf("\n"); glite_jpis_unlockFeed(ctx, uniqueid); + err.code = EIO; + err.desc = "soap_call___jpsrv__FeedIndex() returned error"; + asprintf(&src, "%s/%s():%d", __FILE__, __FUNCTION__, __LINE__); + printf("%s\n", err.desc); goto err; } else { @@ -126,8 +135,13 @@ printf("MyFeedIndex for %s called\n", dest); glite_jpis_initFeed(ctx, uniqueid, out.feedId, out.feedExpires); glite_jpis_unlockFeed(ctx, uniqueid); } - + + return 0; err: + err.source = src; + glite_jp_stack_error(ctx->jpctx, &err); + free(src); soap_end(soap); + return err.code; } diff --git a/org.glite.jp.index/src/soap_ps_calls.h b/org.glite.jp.index/src/soap_ps_calls.h index f8ffb61..cf167ef 100644 --- a/org.glite.jp.index/src/soap_ps_calls.h +++ b/org.glite.jp.index/src/soap_ps_calls.h @@ -6,6 +6,6 @@ #include "context.h" #include "conf.h" -void MyFeedIndex(glite_jpis_context_t ctx, glite_jp_is_conf *conf, long int uniqueid, char *dest); +int MyFeedIndex(glite_jpis_context_t ctx, glite_jp_is_conf *conf, long int uniqueid, char *dest); #endif