Changeset: 7a8306f47513 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7a8306f47513 Modified Files: clients/mapiclient/mclient.c clients/mapilib/mapi.c monetdb5/mal/mal_client.c monetdb5/mal/mal_client.h monetdb5/mal/mal_session.c sql/backends/monet5/sql_scenario.c Branch: mapihandshake Log Message:
Send auto_commit and reply_size during the handshake not as a separate Xcommand round trip diffs (229 lines): diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c --- a/clients/mapiclient/mclient.c +++ b/clients/mapiclient/mclient.c @@ -3538,6 +3538,10 @@ main(int argc, char **argv) if (dbname) free(dbname); dbname = NULL; + + mapi_cache_limit(mid, -1); + mapi_setAutocommit(mid, autocommit); + if (mid && mapi_error(mid) == MOK) mapi_reconnect(mid); /* actually, initial connect */ @@ -3553,7 +3557,6 @@ main(int argc, char **argv) mnstr_printf(stderr_stream, "%s\n", mapi_error_str(mid)); exit(2); } - mapi_cache_limit(mid, -1); if (dump) { if (mode == SQL) { exit(dump_database(mid, toConsole, 0, useinserts, false)); @@ -3567,9 +3570,6 @@ main(int argc, char **argv) priv = (struct privdata) {0}; mapi_setfilecallback(mid, getfile, putfile, &priv); - if (!autocommit) - mapi_setAutocommit(mid, autocommit); - if (logfile) mapi_log(mid, logfile); diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c --- a/clients/mapilib/mapi.c +++ b/clients/mapilib/mapi.c @@ -996,6 +996,7 @@ static int mapi_extend_bindings(MapiHdl static int mapi_extend_params(MapiHdl hdl, int minparams); static void close_connection(Mapi mid); static MapiMsg read_into_cache(MapiHdl hdl, int lookahead); +static MapiMsg mapi_Xcommand(Mapi mid, const char *cmdname, const char *cmdvalue); static int unquote(const char *msg, char **start, const char **next, int endchar, size_t *lenp); static int mapi_slice_row(struct MapiResultSet *result, int cr); static void mapi_store_bind(struct MapiResultSet *result, int cr); @@ -1864,6 +1865,17 @@ mapi_close_handle(MapiHdl hdl) return MOK; } +static const struct MapiStruct MapiStructDefaults = { + .auto_commit = true, + .error = MOK, + .languageId = LANG_SQL, + .mapiversion = "mapi 1.0", + .cachelimit = 100, + .redirmax = 10, + .blk.eos = false, + .blk.lim = BLOCK, +}; + /* Allocate a new connection handle. */ static Mapi mapi_new(void) @@ -1876,17 +1888,8 @@ mapi_new(void) return NULL; /* then fill in some details */ - *mid = (struct MapiStruct) { - .index = (uint32_t) ATOMIC_ADD(&index, 1), /* for distinctions in log records */ - .auto_commit = true, - .error = MOK, - .languageId = LANG_SQL, - .mapiversion = "mapi 1.0", - .cachelimit = 100, - .redirmax = 10, - .blk.eos = false, - .blk.lim = BLOCK, - }; + *mid = MapiStructDefaults; + mid->index = (uint32_t) ATOMIC_ADD(&index, 1); /* for distinctions in log records */ if ((mid->blk.buf = malloc(mid->blk.lim + 1)) == NULL) { mapi_destroy(mid); return NULL; @@ -2975,8 +2978,26 @@ mapi_reconnect(Mapi mid) if (mid->languageId != LANG_SQL) return mid->error; - /* tell server about cachelimit */ - mapi_cache_limit(mid, mid->cachelimit); + if (mid->error != MOK) + return mid->error; + + /* use X commands to send options that couldn't be sent in the handshake */ + /* tell server about auto_complete and cache limit if handshake options weren't used */ + if (mid->handshake_options <= MAPI_HANDSHAKE_AUTOCOMMIT && mid->auto_commit != MapiStructDefaults.auto_commit) { + char buf[2]; + sprintf(buf, "%d", !!mid->auto_commit); + MapiMsg result = mapi_Xcommand(mid, "auto_commit", buf); + if (result != MOK) + return mid->error; + } + if (mid->handshake_options <= MAPI_HANDSHAKE_REPLY_SIZE && mid->cachelimit != MapiStructDefaults.cachelimit) { + char buf[50]; + sprintf(buf, "%d", mid->cachelimit); + MapiMsg result = mapi_Xcommand(mid, "reply_size", buf); + if (result != MOK) + return mid->error; + } + return mid->error; } @@ -3663,6 +3684,8 @@ mapi_setAutocommit(Mapi mid, bool autoco return MERROR; } mid->auto_commit = autocommit; + if (!mid->connected) + return MOK; if (autocommit) return mapi_Xcommand(mid, "auto_commit", "1"); else @@ -4566,8 +4589,10 @@ MapiMsg mapi_cache_limit(Mapi mid, int limit) { /* clean out superflous space TODO */ + mid->cachelimit = limit; + if (!mid->connected) + return MOK; mapi_check(mid); - mid->cachelimit = limit; /* if (hdl->cache.rowlimit < hdl->cache.limit) { */ /* TODO: decide what to do here */ /* hdl->cache.limit = hdl->cache.rowlimit; *//* arbitrarily throw away cache lines */ diff --git a/monetdb5/mal/mal_client.c b/monetdb5/mal/mal_client.c --- a/monetdb5/mal/mal_client.c +++ b/monetdb5/mal/mal_client.c @@ -274,6 +274,7 @@ MCinitClientRecord(Client c, oid user, b c->protocol = PROTOCOL_9; c->filetrans = false; + c->handshake_options = NULL; c->query = NULL; char name[MT_NAME_LEN]; @@ -457,6 +458,8 @@ MCfreeClient(Client c) c->sqlprofiler = 0; c->wlc_kind = 0; c->wlc = NULL; + free(c->handshake_options); + c->handshake_options = NULL; MT_sema_destroy(&c->s); c->mode = MCshutdowninprogress()? BLOCKCLIENT: FREECLIENT; } diff --git a/monetdb5/mal/mal_client.h b/monetdb5/mal/mal_client.h --- a/monetdb5/mal/mal_client.h +++ b/monetdb5/mal/mal_client.h @@ -179,6 +179,7 @@ typedef struct CLIENT { size_t blocksize; protocol_version protocol; bool filetrans; /* whether the client can read files for us */ + char *handshake_options; char *query; /* string, identify whatever we're working on */ } *Client, ClientRec; diff --git a/monetdb5/mal/mal_session.c b/monetdb5/mal/mal_session.c --- a/monetdb5/mal/mal_session.c +++ b/monetdb5/mal/mal_session.c @@ -172,7 +172,7 @@ is_exiting(void *data) void MSscheduleClient(str command, str challenge, bstream *fin, stream *fout, protocol_version protocol, size_t blocksize) { - char *user = command, *algo = NULL, *passwd = NULL, *lang = NULL; + char *user = command, *algo = NULL, *passwd = NULL, *lang = NULL, *handshake_opts = NULL; char *database = NULL, *s; const char *dbname; str msg = MAL_SUCCEED; @@ -251,6 +251,11 @@ MSscheduleClient(str command, str challe filetrans = true; } + if (s && strchr(s, ':') != NULL) { + handshake_opts = s; + s = strchr(s, ':'); + *s++ = '\0'; + } dbname = GDKgetenv("gdk_dbname"); if (database != NULL && database[0] != '\0' && strcmp(database, dbname) != 0) @@ -320,6 +325,7 @@ MSscheduleClient(str command, str challe return; } c->filetrans = filetrans; + c->handshake_options = handshake_opts ? strdup(handshake_opts) : NULL; /* move this back !! */ if (c->usermodule == 0) { c->curmodule = c->usermodule = userModule(); 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 @@ -279,6 +279,31 @@ SQLprepareClient(Client c, int login) _DELETE(schema); } + if (c->handshake_options) { + char *strtok_state = NULL; + char *tok = strtok_r(c->handshake_options, ",", &strtok_state); + while (tok != NULL) { + int value; + if (sscanf(tok, "auto_commit=%d", &value) == 1) { + bool auto_commit= value != 0; + m->session->auto_commit = auto_commit; + m->session->ac_on_commit = auto_commit; + } else if (sscanf(tok, "reply_size=%d", &value) == 1) { + if (value < -1) { + msg = createException(SQL, "SQLprepareClient", SQLSTATE(42000) "Reply_size cannot be negative"); + goto bailout; + } + m->reply_size = value; + } else { + msg = createException(SQL, "SQLprepareClent", SQLSTATE(42000) "unexpected handshake option: %s", tok); + goto bailout; + } + + tok = strtok_r(NULL, ",", &strtok_state); + } + } + + bailout: MT_lock_set(&sql_contextLock); /* expect SQL text first */ _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list