Changeset: d5fd38ffa420 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/d5fd38ffa420
Modified Files:
        monetdb5/mal/mal_profiler.c
        monetdb5/mal/mal_profiler.h
        sql/backends/monet5/sql_scenario.c
        sql/server/sql_mvc.c
        sql/storage/sql_storage.h
        sql/storage/store.c
Branch: Jul2021_prof_ext
Log Message:

Collapse all transaction messages into a single message for commits, conflicts 
and errors.


diffs (246 lines):

diff --git a/monetdb5/mal/mal_profiler.c b/monetdb5/mal/mal_profiler.c
--- a/monetdb5/mal/mal_profiler.c
+++ b/monetdb5/mal/mal_profiler.c
@@ -177,14 +177,14 @@ static str phase_descriptions[] = {
        [REL_TO_MAL]            = "rel_to_mal",
        [MAL_OPT]                       = "rel_to_mal",
        [MAL_ENGINE]            = "mal_engine",
-       [TRANSACTION_START]     = "trans_start",
-       [COMMIT]                        = "trans_commit",
-       [ROLLBACK]                      = "trans_rollback",
-       [TRANSACTION_END]       = "trans_end"
+       // [TRANSACTION_START]  = "trans_start",
+       // [COMMIT]                     = "trans_commit",
+       // [ROLLBACK]                   = "trans_rollback",
+       [TRANSACTION_END]       = "transaction"
 };
 
 static str
-prepareNonMalEvent(Client cntxt, enum event_phase phase, ulng clk, ulng *tid, 
ulng *ts, int state, ulng duration)
+prepareNonMalEvent(Client cntxt, enum event_phase phase, ulng clk, ulng 
*tstart, ulng *tend, int state, ulng duration)
 {
        oid* tag = NULL;
        str query = NULL;
@@ -207,9 +207,9 @@ prepareNonMalEvent(Client cntxt, enum ev
        if (!logadd(&logbuf, ", \"thread\":%d, \"phase\":\"%s\"",
                                THRgettid(), phase_descriptions[phase]))
                goto cleanup_and_exit;
-       if (tid && !logadd(&logbuf, ", \"tid\":"ULLFMT, *tid))
+       if (tstart && !logadd(&logbuf, ", \"tstart\":"ULLFMT, *tstart))
                goto cleanup_and_exit;
-       if (ts && !logadd(&logbuf, ", \"ts\":"ULLFMT, *ts))
+       if (tend && !logadd(&logbuf, ", \"tend\":"ULLFMT, *tend))
                goto cleanup_and_exit;
        if (tag && !logadd(&logbuf, ", \"tag\":"OIDFMT, *tag))
                goto cleanup_and_exit;
diff --git a/monetdb5/mal/mal_profiler.h b/monetdb5/mal/mal_profiler.h
--- a/monetdb5/mal/mal_profiler.h
+++ b/monetdb5/mal/mal_profiler.h
@@ -29,9 +29,9 @@ enum event_phase {
        REL_OPT,
        REL_TO_MAL,
        MAL_OPT,
-       TRANSACTION_START = 7,
-       COMMIT,
-       ROLLBACK,
+       // TRANSACTION_START,
+       // COMMIT,
+       // ROLLBACK,
        TRANSACTION_END
 };
 
diff --git a/sql/backends/monet5/sql_scenario.c 
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -1149,7 +1149,7 @@ SQLparser(Client c)
        if(malProfileMode > 0) {
                profilerEvent((struct MalEvent) {0},
                                          (struct NonMalEvent)
-                                         {TEXT_TO_SQL, c, Tend, NULL, NULL, 
c->query?0:1, Tend-Tbegin});
+                                         {TEXT_TO_SQL, c, Tend, 
&m->session->tr->ts, NULL, c->query?0:1, Tend-Tbegin});
        }
 
        if (c->query == NULL) {
diff --git a/sql/server/sql_mvc.c b/sql/server/sql_mvc.c
--- a/sql/server/sql_mvc.c
+++ b/sql/server/sql_mvc.c
@@ -123,17 +123,6 @@ mvc_fix_depend(mvc *m, sql_column *depid
        }
 }
 
-static void
-profiler_event_wrapper(int phase, lng clk, ulng *tid, ulng *ts, int state, lng 
usec)
-{
-       Client  c = getClientContext();
-
-       if(malProfileMode > 0)
-               profilerEvent((struct MalEvent) {0},
-                                         (struct NonMalEvent)
-                                         {(enum event_phase) phase, c, clk, 
tid, ts, state, usec});
-}
-
 sql_store
 mvc_init(int debug, store_type store_tpe, int ro, int su)
 {
@@ -150,7 +139,7 @@ mvc_init(int debug, store_type store_tpe
                return NULL;
        }
 
-       if ((store = store_init(debug, store_tpe, ro, su, 
&profiler_event_wrapper)) == NULL) {
+       if ((store = store_init(debug, store_tpe, ro, su)) == NULL) {
                keyword_exit();
                TRC_CRITICAL(SQL_TRANS, "Unable to create system tables\n");
                return NULL;
@@ -540,9 +529,32 @@ mvc_commit(mvc *m, int chain, const char
        }
 
        if (!tr->parent && !name) {
-               if (sql_trans_end(m->session, ok) != SQL_OK) {
-                       /* transaction conflict */
-                       return createException(SQL, "sql.commit", 
SQLSTATE(40000) "%s transaction is aborted because of concurrency conflicts, 
will ROLLBACK instead", operation);
+               lng Tbegin;
+               ulng ts_start;
+               if(malProfileMode > 0) {
+                       Tbegin = GDKusec();
+                       ts_start = m->session->tr->ts;
+               }
+
+               const int state = sql_trans_end(m->session, ok);
+
+               if(malProfileMode > 0) {
+                       lng Tend = GDKusec();
+                       Client  c = getClientContext();
+                       profilerEvent((struct MalEvent) {0},
+                                               (struct NonMalEvent)
+                                               {TRANSACTION_END, c, Tend, 
&ts_start, &m->session->tr->ts, state == SQL_OK ? 0 : 1, Tend - Tbegin});
+               }
+               switch (state) {
+                       case SQL_ERR:
+                               GDKfatal("%s transaction commit failed; exiting 
(kernel error: %s)", operation, GDKerrbuf);
+                               break;
+                       case SQL_CONFLICT:
+
+                               /* transaction conflict */
+                               return createException(SQL, "sql.commit", 
SQLSTATE(40001) "%s transaction is aborted because of concurrency conflicts, 
will ROLLBACK instead", operation);
+                       default:
+                               break;
                }
                msg = WLCcommit(m->clientid);
                if (msg != MAL_SUCCEED) {
diff --git a/sql/storage/sql_storage.h b/sql/storage/sql_storage.h
--- a/sql/storage/sql_storage.h
+++ b/sql/storage/sql_storage.h
@@ -309,8 +309,7 @@ extern res_table *res_tables_remove(res_
 sql_export void res_tables_destroy(res_table *results);
 extern res_table *res_tables_find(res_table *results, int res_id);
 
-typedef void (*profiler_event_wrapper_fptr) (int phase, lng clk, ulng *tid, 
ulng *ts, int state, lng usec);
-extern struct sqlstore *store_init(int debug, store_type store, int readonly, 
int singleuser, profiler_event_wrapper_fptr event_wrapper);
+extern struct sqlstore *store_init(int debug, store_type store, int readonly, 
int singleuser);
 extern void store_exit(struct sqlstore *store);
 
 extern void store_suspend_log(struct sqlstore *store);
@@ -478,7 +477,6 @@ typedef struct sqlstore {
        table_functions table_api;
        logger_functions logger_api;
        void *logger;                   /* space to keep logging structure of 
storage backend */
-       generic_event_wrapper_fptr generic_event_wrapper;
 } sqlstore;
 
 typedef enum sql_dependency_change_type {
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -2039,7 +2039,7 @@ store_load(sqlstore *store, sql_allocato
 }
 
 sqlstore *
-store_init(int debug, store_type store_tpe, int readonly, int singleuser, 
generic_event_wrapper_fptr event_wrapper)
+store_init(int debug, store_type store_tpe, int readonly, int singleuser)
 {
        sql_allocator *pa;
        sqlstore *store = MNEW(sqlstore);
@@ -2078,8 +2078,6 @@ store_init(int debug, store_type store_t
        MT_lock_set(&store->lock);
        MT_lock_set(&store->flush);
 
-       store->generic_event_wrapper = event_wrapper;
-
        /* initialize empty bats */
        switch (store_tpe) {
        case store_bat:
@@ -3482,19 +3480,10 @@ clean_predicates_and_propagate_to_parent
        return res;
 }
 
-enum event_phase {
-       TRANSACTION_START = 7,
-       COMMIT,
-       ROLLBACK,
-       TRANSACTION_END
-};
-
 static void
 sql_trans_rollback(sql_trans *tr, bool commit_lock)
 {
        sqlstore *store = tr->store;
-       lng Tbegin = GDKusec();
-       lng Tend;
 
        /* move back deleted */
        if (tr->localtmps.dset) {
@@ -3591,9 +3580,6 @@ sql_trans_rollback(sql_trans *tr, bool c
                list_destroy(tr->depchanges);
                tr->depchanges = NULL;
        }
-
-       Tend = GDKusec();
-       store->profiler_event_wrapper(ROLLBACK, Tend, &tr->tid, NULL, 0, 
Tend-Tbegin);
 }
 
 sql_trans *
@@ -3799,8 +3785,6 @@ sql_trans_commit(sql_trans *tr)
 {
        int ok = LOG_OK;
        sqlstore *store = tr->store;
-       lng Tbegin = 0;
-       lng Tend = 0;
 
        if (!list_empty(tr->changes)) {
                int flush = 0;
@@ -3826,8 +3810,6 @@ sql_trans_commit(sql_trans *tr)
                        }
                }
 
-               Tbegin = GDKusec();
-
                /* log changes should only be done if there is something to log 
*/
                if (!tr->parent && tr->logchanges > 0) {
                        int min_changes = GDKdebug & FORCEMITOMASK ? 5 : 
1000000;
@@ -3944,9 +3926,6 @@ sql_trans_commit(sql_trans *tr)
        if (ok == LOG_OK)
                ok = clean_predicates_and_propagate_to_parent(tr);
 
-       Tend = GDKusec();
-       store->profiler_event_wrapper(COMMIT, Tend, &tr->tid, &tr->ts, ok, 
Tend-Tbegin);
-
        return (ok==LOG_OK)?SQL_OK:SQL_ERR;
 }
 
@@ -6881,7 +6860,6 @@ sql_trans_begin(sql_session *s)
        TRC_DEBUG(SQL_STORE, "Exit sql_trans_begin for transaction: " ULLFMT 
"\n", tr->tid);
        store_unlock(store);
        s->status = tr->status = 0;
-       store->profiler_event_wrapper(TRANSACTION_START, GDKusec(), 
&s->tr->tid, &s->tr->ts, 0, 0);
        return 0;
 }
 
@@ -6913,8 +6891,6 @@ sql_trans_end(sql_session *s, int ok)
        store->oldest = oldest;
        assert(list_length(store->active) == (int) 
ATOMIC_GET(&store->nr_active));
        store_unlock(store);
-       lng Tend = GDKusec();
-       store->profiler_event_wrapper(TRANSACTION_END, Tend, &s->tr->tid, 
&s->tr->ts, ok==SQL_OK?0:1, 0);
 
        return ok;
 }
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to