From fdec4101ceb0b763b11e3b94575a57e6d2f51d5c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ji=C5=99=C3=AD=20Filipovi=C4=8D?= Date: Thu, 12 Jun 2008 12:31:18 +0000 Subject: [PATCH] Force-feed option. --- org.glite.jp.index/src/bones_server.c | 8 ++++ org.glite.jp.index/src/conf.c | 5 ++- org.glite.jp.index/src/conf.h | 1 + org.glite.jp.index/src/db_ops.c | 74 +++++++++++++++++++++------------- org.glite.jp.index/src/db_ops.h | 1 + org.glite.jp.index/src/soap_ps_calls.c | 2 + 6 files changed, 63 insertions(+), 28 deletions(-) diff --git a/org.glite.jp.index/src/bones_server.c b/org.glite.jp.index/src/bones_server.c index 368388d..435abfd 100644 --- a/org.glite.jp.index/src/bones_server.c +++ b/org.glite.jp.index/src/bones_server.c @@ -116,6 +116,14 @@ int main(int argc, char *argv[]) goto quit; } + if (conf->delete_db || conf->force_feed) { + if (glite_jpis_initDatabaseFeeds(isctx) != 0) { + fprintf(stderr, "Init feeds failed: "); + retval = 1; + goto quit; + } + } + server_cert = conf->server_cert; server_key = conf->server_key; diff --git a/org.glite.jp.index/src/conf.c b/org.glite.jp.index/src/conf.c index 56fb2bc..1506faf 100644 --- a/org.glite.jp.index/src/conf.c +++ b/org.glite.jp.index/src/conf.c @@ -24,7 +24,7 @@ extern SOAP_NMAC struct Namespace jp__namespaces[]; -static const char *get_opt_string = "dq:c:k:C:V:nm:p:i:o:x:s:Df:"; +static const char *get_opt_string = "dq:c:k:C:V:nm:p:i:o:x:s:Df:F"; static struct option opts[] = { {"debug", 0, NULL, 'd'}, @@ -42,6 +42,7 @@ static struct option opts[] = { {"slaves", 1, NULL, 's'}, {"delete-db", 0, NULL, 'D'}, {"feeding", 1, NULL, 'f'}, + {"force-feed", 0, NULL, 'F'}, {NULL, 0, NULL, 0} }; @@ -68,6 +69,7 @@ static void usage(char *me) "\t-s, --slaves\t number of slaves for responses\n" "\t-D, --delete-db\t delete and restore data in the database\n" "\t-f, --feeding\t feed index server from local file\n" + "\t-F, --force-feed\t force reloading feeds from the config file\n" "\n" ,me); } @@ -98,6 +100,7 @@ int glite_jp_get_conf(int argc, char **argv, glite_jp_is_conf **configuration) case 's': conf->slaves = atoi(optarg); if (conf->slaves > 0) break; case 'D': conf->delete_db = 1; break; case 'f': conf->feeding = optarg; break; + case 'F': conf->force_feed = 1; break; default : usage(argv[0]); exit(0); break; } diff --git a/org.glite.jp.index/src/conf.h b/org.glite.jp.index/src/conf.h index d5ec255..9a09ea4 100644 --- a/org.glite.jp.index/src/conf.h +++ b/org.glite.jp.index/src/conf.h @@ -54,6 +54,7 @@ typedef struct _glite_jp_is_conf { int delete_db; char *feeding; // feed DB from local file + int force_feed; } glite_jp_is_conf; diff --git a/org.glite.jp.index/src/db_ops.c b/org.glite.jp.index/src/db_ops.c index e5db901..90f9573 100644 --- a/org.glite.jp.index/src/db_ops.c +++ b/org.glite.jp.index/src/db_ops.c @@ -299,11 +299,8 @@ int glite_jpis_initDatabase(glite_jpis_context_t ctx) { char **attrs, *attrid, *num; const char *type_index, *type_full; size_t i; - int indexed, state, locked, nattrs; - size_t conds_len; + int indexed, nattrs; char sql[2048]; - glite_jp_is_feed **feeds; - void *conds; glite_jp_context_t jpctx = ctx->jpctx; glite_lbu_Statement stmt = NULL; @@ -371,6 +368,51 @@ int glite_jpis_initDatabase(glite_jpis_context_t ctx) { } glite_jp_db_FreeStmt(&stmt); + // create jobs table + snprintf(sql, sizeof(sql) - 1, SQLCMD_CREATE_JOBS_TABLE_BEGIN); + if (ctx->conf->attrs) for (i = 0; ctx->conf->attrs[i]; i++) + if (is_singleval(ctx->conf, ctx->conf->attrs[i]) + && is_queriable(ctx->conf, ctx->conf->attrs[i])){ + snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), + " `attr_%s` %s NOT NULL,\n", + glite_jp_indexdb_attr2id(ctx->conf->attrs[i]), + glite_jp_attrval_db_type_index(jpctx, ctx->conf->attrs[i], INDEX_LENGTH)); + + if (is_indexed(ctx->conf, ctx->conf->attrs[i])) + snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), + " index (attr_%s), \n", + glite_jp_indexdb_attr2id(ctx->conf->attrs[i])); + } + snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), SQLCMD_CREATE_JOBS_TABLE_END); + llprintf(LOG_SQL, "sql=%s\n", sql); + if ((glite_jp_db_ExecSQL(jpctx, sql, NULL)) == -1) { + glite_jpis_stack_error(ctx->jpctx, EAGAIN, "Cannot create table 'jobs'!"); + goto fail; + } + + return 0; + +fail: + glite_jp_db_FreeStmt(&stmt); + if (!jpctx->error) glite_jpis_stack_error(ctx->jpctx, EIO, "error during initial filling of the database"); + return jpctx->error->code; +} + + +int glite_jpis_initDatabaseFeeds(glite_jpis_context_t ctx) { + glite_jp_context_t jpctx = ctx->jpctx; + glite_lbu_Statement stmt = NULL; + glite_jp_is_feed **feeds; + size_t i; + size_t conds_len; + void *conds; + int state, locked; + + if (glite_jp_db_ExecSQL(jpctx, "DELETE FROM feeds", NULL) == -1) { + glite_jpis_stack_error(ctx->jpctx, EIO, "can't delete feeds"); + goto fail; + } + // feeds table if (glite_jp_db_PrepareStmt(jpctx, "INSERT INTO feeds (`state`, `locked`, `source`, `condition`) VALUES (?, ?, ?, ?)", &stmt) != 0) { glite_jpis_stack_error(ctx->jpctx, EIO, "can't create insert feeds statement"); @@ -390,34 +432,12 @@ int glite_jpis_initDatabase(glite_jpis_context_t ctx) { GLITE_LBU_DB_TYPE_MEDIUMBLOB, conds, conds_len) == -1) goto fail_conds; free(conds); + conds = NULL; feeds[i]->uniqueid = glite_lbu_Lastid(stmt); i++; } glite_jp_db_FreeStmt(&stmt); - - // create jobs table - snprintf(sql, sizeof(sql) - 1, SQLCMD_CREATE_JOBS_TABLE_BEGIN); - if (ctx->conf->attrs) for (i = 0; ctx->conf->attrs[i]; i++) - if (is_singleval(ctx->conf, ctx->conf->attrs[i]) - && is_queriable(ctx->conf, ctx->conf->attrs[i])){ - snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), - " `attr_%s` %s NOT NULL,\n", - glite_jp_indexdb_attr2id(ctx->conf->attrs[i]), - glite_jp_attrval_db_type_index(jpctx, ctx->conf->attrs[i], INDEX_LENGTH)); - - if (is_indexed(ctx->conf, ctx->conf->attrs[i])) - snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), - " index (attr_%s), \n", - glite_jp_indexdb_attr2id(ctx->conf->attrs[i])); - } - snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), SQLCMD_CREATE_JOBS_TABLE_END); - llprintf(LOG_SQL, "sql=%s\n", sql); - if ((glite_jp_db_ExecSQL(jpctx, sql, NULL)) == -1) { - glite_jpis_stack_error(ctx->jpctx, EAGAIN, "Cannot create table 'jobs'!"); - goto fail; - } - return 0; fail_conds: diff --git a/org.glite.jp.index/src/db_ops.h b/org.glite.jp.index/src/db_ops.h index a9de808..8078a5b 100644 --- a/org.glite.jp.index/src/db_ops.h +++ b/org.glite.jp.index/src/db_ops.h @@ -27,6 +27,7 @@ char *glite_jpis_attr_name2id(const char *name); int glite_jpis_initDatabase(glite_jpis_context_t ctx); +int glite_jpis_initDatabaseFeeds(glite_jpis_context_t ctx); int glite_jpis_dropDatabase(glite_jpis_context_t ctx); int glite_jpis_init_db(glite_jpis_context_t isctx); diff --git a/org.glite.jp.index/src/soap_ps_calls.c b/org.glite.jp.index/src/soap_ps_calls.c index 5b3edc0..a9c4e80 100644 --- a/org.glite.jp.index/src/soap_ps_calls.c +++ b/org.glite.jp.index/src/soap_ps_calls.c @@ -176,3 +176,5 @@ int __jpsrv__FeedIndex(struct soap* soap UNUSED, struct _jpelem__FeedIndex *jpel int __jpsrv__FeedIndexRefresh(struct soap* soap UNUSED, struct _jpelem__FeedIndexRefresh *jpelem__FeedIndexRefresh UNUSED, struct _jpelem__FeedIndexRefreshResponse *jpelem__FeedIndexRefreshResponse UNUSED) { return 0; } int __jpsrv__GetJobFiles(struct soap* soap UNUSED, struct _jpelem__GetJobFiles *jpelem__GetJobFiles UNUSED, struct _jpelem__GetJobFilesResponse *jpelem__GetJobFilesResponse UNUSED) { return 0; } int __jpsrv__GetJobAttributes(struct soap* soap UNUSED, struct _jpelem__GetJobAttributes *jpelem__GetJobAttributes UNUSED, struct _jpelem__GetJobAttributesResponse *jpelem__GetJobAttributesResponse UNUSED) { return 0; } + +int __jpsrv__RecordMultiTags(struct soap* soap UNUSED, struct _jpelem__RecordMultiTags *jpelem__RecordMultiTags UNUSED, struct _jpelem__RecordMultiTagsResponse *jpelem__RecordMultiTagsResponse UNUSED) { return 0; } -- 1.8.2.3