Changeset: 6a4d437f74ee for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6a4d437f74ee Modified Files: tools/merovingian/daemon/controlrunner.c tools/merovingian/utils/control.c Branch: default Log Message:
Adjustments to make remote streaming snapshot work diffs (114 lines): diff --git a/tools/merovingian/daemon/controlrunner.c b/tools/merovingian/daemon/controlrunner.c --- a/tools/merovingian/daemon/controlrunner.c +++ b/tools/merovingian/daemon/controlrunner.c @@ -756,24 +756,39 @@ static void ctl_handle_client( } else if (strcmp(p, "snapshot stream") == 0) { Mfprintf(_mero_ctlout, "Start streaming snapshot of database '%s'\n", q); - if (fout != NULL) - e = newErr("internal error: did not expect fout to be non-NULL"); - else { - stream *wrapper = NULL; - stream *bs = NULL; - do { - e = NULL; + + stream *wrapper = NULL; + stream *bs = NULL; + stream *s = NULL; // aliases either bs or fout + do { + if (fout) { + if (!isa_block_stream(fout)) { + e = newErr("internal error: expected fout to be a block stream"); + break; + } + s = fout; + } else { wrapper = socket_wstream(msgsock, "sockwrapper"); - if (!wrapper) + if (!wrapper) { + e = newErr("internal error: could not create sock wrapper"); break; + } bs = block_stream(wrapper); - if (!bs) + if (!bs) { + e = newErr("internal error: could not wrap block_stream"); break; - e = snapshot_database_stream(q, bs); - mnstr_flush(bs); - } while (0); - mnstr_destroy(bs); // implies mnstr_destroy(wrapper); - } + } + wrapper = NULL; // will be cleanup through bs + s = bs; + // + } + e = snapshot_database_stream(q, s); + mnstr_flush(s); + } while (0); + if (bs) + mnstr_destroy(bs); + if (wrapper) + mnstr_destroy(wrapper); if (e != NULL) { Mfprintf(_mero_ctlerr, "%s: streaming snapshot database '%s' failed: %s", origin, q, getErrMsg(e)); diff --git a/tools/merovingian/utils/control.c b/tools/merovingian/utils/control.c --- a/tools/merovingian/utils/control.c +++ b/tools/merovingian/utils/control.c @@ -563,27 +563,38 @@ char* control_send_callback( if (msg != NULL) return msg; - assert(!control->fdin); // not sure under which circumstances it would exist. - // in any case, we have to mirror the code path in controlrunner.c, which - // likewise only works if fdin/fdout are not set. - stream *wrapper = NULL; stream *bs = NULL; + stream *s = NULL; // aliases either bs or control->fdin + do { - wrapper = socket_rstream(control->sock, "sockwrapper"); - if (!wrapper) - break; - bs = block_stream(wrapper); - if (!bs) - break; - while ((nread = mnstr_read(bs, buf, 1, sizeof(buf))) > 0) { + if (control->fdin) { + assert(isa_block_stream(control->fdin)); + s = control->fdin; + } else { + wrapper = socket_rstream(control->sock, "sockwrapper"); + if (!wrapper) { + msg = strdup("could not wrap socket"); + break; + } + bs = block_stream(wrapper); + if (!bs) { + msg = strdup("could not wrap block stream"); + break; + } + wrapper = NULL; // it will be cleaned up when bs is cleaned up + s = bs; + } + while ((nread = mnstr_read(s, buf, 1, sizeof(buf))) > 0) { callback(buf, (size_t)nread, cb_private); } - if (mnstr_errnr(bs)) - msg = mnstr_error(bs); + if (mnstr_errnr(s)) + msg = mnstr_error(s); } while (0); - mnstr_destroy(bs); // implies mnstr_destroy(wrapper) - + if (bs) + mnstr_destroy(bs); + if (wrapper) + mnstr_destroy(wrapper); if (msg) return msg; _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list