"Two-way" fix of the bug in transaction testing visible with multiple clients:
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Mon, 3 Jul 2006 16:02:13 +0000 (16:02 +0000)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Mon, 3 Jul 2006 16:02:13 +0000 (16:02 +0000)
 - pid in name of the testing table so more slaves can call it
 - check for the transaction only in DBCheckVersion (called from master here)

org.glite.lb.server/interface/lbs_db.h
org.glite.lb.server/src/bkindex.c
org.glite.lb.server/src/bkserverd.c
org.glite.lb.server/src/lbs_db.c

index 8febdf0..fc875fd 100644 (file)
@@ -101,7 +101,7 @@ extern edg_wll_ErrorCode edg_wll_Open(edg_wll_Context ctx, char *cs);
 /**
  * Check database version.
  */
-int edg_wll_DBCheckVersion(edg_wll_Context);
+int edg_wll_DBCheckVersion(edg_wll_Context, const char *);
 
 int edg_wll_Transaction(edg_wll_Context ctx);
 int edg_wll_Commit(edg_wll_Context ctx);
index 2b45116..7f7dcba 100644 (file)
@@ -76,7 +76,7 @@ int main(int argc,char **argv)
 
        edg_wll_InitContext(&ctx);
        if (edg_wll_Open(ctx,dbstring)) do_exit(ctx,EX_UNAVAILABLE);
-       if (edg_wll_DBCheckVersion(ctx)) do_exit(ctx,EX_SOFTWARE);
+       if (edg_wll_DBCheckVersion(ctx,dbstring)) do_exit(ctx,EX_SOFTWARE);
        if (edg_wll_QueryJobIndices(ctx,&old_indices,&index_names)) do_exit(ctx,EX_SOFTWARE);
 
        if (dump) {
index 15ea8f1..c112ac1 100644 (file)
@@ -120,7 +120,7 @@ static int                          hardJobsLimit = 0;
 static int                             hardEventsLimit = 0;
 static int                             hardRespSizeLimit = 0;
 static char                       *dbstring = NULL,*fake_host = NULL;
-int                                    transactions = -1;
+int                                    transactions = -1, use_transactions = -1;
 static int                             fake_port = 0;
 static char                      **super_users = NULL;
 static int                             slaves = 10,
@@ -567,7 +567,7 @@ a.sin_addr.s_addr = INADDR_ANY;
        edg_wll_InitContext(&ctx);
        wait_for_open(ctx, dbstring);
 
-       if (edg_wll_DBCheckVersion(ctx))
+       if (edg_wll_DBCheckVersion(ctx, dbstring))
        {
                char    *et,*ed;
                edg_wll_Error(ctx,&et,&ed);
@@ -576,6 +576,14 @@ a.sin_addr.s_addr = INADDR_ANY;
                return 1;
        }
        if (count_statistics) edg_wll_InitStatistics(ctx);
+       if (!ctx->use_transactions && transactions != 0) {
+               fprintf(stderr, "[%d]: transactions aren't supported!\n", getpid());
+       }
+       if (transactions >= 0) {
+               fprintf(stderr, "[%d]: transactions forced from %d to %d\n", getpid(), ctx->use_transactions, transactions);
+               ctx->use_transactions = transactions;
+       }
+       use_transactions = ctx->use_transactions;
        edg_wll_Close(ctx);
        edg_wll_FreeContext(ctx);
 
@@ -1264,13 +1272,7 @@ static void wait_for_open(edg_wll_Context ctx, const char *dbstring)
                if (!debug) syslog(LOG_INFO,"DB connection established\n");
        }
 
-       if (!ctx->use_transactions && transactions != 0) {
-               fprintf(stderr, "[%d]: transactions aren't supported!\n", getpid());
-       }
-       if (transactions >= 0) {
-               ctx->use_transactions = transactions;
-               fprintf(stderr, "[%d]: transactions forced from %d to %d\n", getpid(), ctx->use_transactions, transactions);
-       }
+       ctx->use_transactions = use_transactions;
 }
 
 static void free_hostent(struct hostent *h){
index 9f169ba..464fce4 100644 (file)
@@ -79,54 +79,55 @@ static void db_close(MYSQL *mysql) {
 
 static int transaction_test(edg_wll_Context ctx, MYSQL *m2) {
        MYSQL *m1;
-       char *desc;
+       char *desc, *cmd_create, *cmd_insert, *cmd_select, *cmd_drop;
        int retval;
        edg_wll_ErrorCode err;
+       pid_t pid;
 
        ctx->use_transactions = 1;
+       pid = getpid();
+
+       asprintf(&cmd_create, "create table test%d (item int)", pid);
+       asprintf(&cmd_insert, "insert into test%d (item) values (1)", pid);
+       asprintf(&cmd_select, "select item from test%d", pid);
+       asprintf(&cmd_drop, "drop table test%d", pid);
 
        m1 = (MYSQL *)ctx->mysql;
-       edg_wll_ExecStmt(ctx, "drop table test", NULL);
-       if (edg_wll_ExecStmt(ctx, "create table test (item int)", NULL) != 0) goto err1;
+       edg_wll_ExecStmt(ctx, cmd_drop, NULL);
+       if (edg_wll_ExecStmt(ctx, cmd_create, NULL) != 0) goto err1;
        if (edg_wll_Transaction(ctx) != 0) goto err2;
-       if (edg_wll_ExecStmt(ctx, "insert into test (item) values (1)", NULL) != 1) goto err2;
+       if (edg_wll_ExecStmt(ctx, cmd_insert, NULL) != 1) goto err2;
 
        ctx->mysql = (void *)m2;
-       if ((retval = edg_wll_ExecStmt(ctx, "select item from test", NULL)) == -1) goto err2;
+       if ((retval = edg_wll_ExecStmt(ctx, cmd_select, NULL)) == -1) goto err2;
        ctx->use_transactions = (retval == 0);
 
        ctx->mysql = (void *)m1;
        if (edg_wll_Commit(ctx) != 0) goto err2;
-       if (edg_wll_ExecStmt(ctx, "drop table test", NULL) != 0) goto err1;
+       if (edg_wll_ExecStmt(ctx, cmd_drop, NULL) != 0) goto err1;
 
 #ifdef LBS_DB_PROFILE
        fprintf(stderr, "[%d] use_transactions = %d\n", getpid(), ctx->use_transactions);
 #endif
 
-       return 0;
+       goto ok;
 err2:
-       edg_wll_Error(ctx, &err, &desc);
-       edg_wll_ExecStmt(ctx, "drop table test", NULL);
+       err = edg_wll_Error(ctx, NULL, &desc);
+       edg_wll_ExecStmt(ctx, cmd_drop, NULL);
        edg_wll_SetError(ctx, err, desc);
 err1:
+ok:
+       free(cmd_create);
+       free(cmd_insert);
+       free(cmd_select);
+       free(cmd_drop);
        return edg_wll_Error(ctx, NULL, NULL);
 }
 
 
 edg_wll_ErrorCode edg_wll_DBConnect(edg_wll_Context ctx, const char *cs)
 {
-       MYSQL *m2;
-       int errcode;
-
-       if ((errcode = db_connect(ctx, cs, (MYSQL **)&ctx->mysql)) == 0) {
-               if ((errcode = db_connect(ctx, cs, (MYSQL **)&m2)) == 0) {
-                       errcode = transaction_test(ctx, m2);
-                       db_close(m2);
-               }
-               if (errcode) edg_wll_DBClose(ctx);
-       }
-
-       return errcode;
+       return db_connect(ctx, cs, (MYSQL **)&ctx->mysql);
 }
 
 
@@ -268,9 +269,10 @@ void edg_wll_FreeStmt(edg_wll_Stmt *stmt)
        }
 }
 
-int edg_wll_DBCheckVersion(edg_wll_Context ctx)
+int edg_wll_DBCheckVersion(edg_wll_Context ctx, const char *cs)
 {
        MYSQL   *m = (MYSQL *) ctx->mysql;
+       MYSQL   *m2;
        const   char *ver_s = mysql_get_server_info(m);
        int     major,minor,sub,version;
 
@@ -286,7 +288,14 @@ int edg_wll_DBCheckVersion(edg_wll_Context ctx)
                return edg_wll_SetError(ctx,EINVAL,msg);
        }
 
-       return edg_wll_ResetError(ctx);
+       edg_wll_ResetError(ctx);
+
+       if (db_connect(ctx, cs, &m2) == 0) {
+               transaction_test(ctx, m2);
+               db_close(m2);
+       }
+
+       return edg_wll_Error(ctx, NULL, NULL);
 }