Changeset: 27a77f490870 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/27a77f490870
Modified Files:
        gdk/gdk_logger.c
        gdk/gdk_logger_internals.h
        gdk/gdk_logger_old.c
Branch: Jul2021
Log Message:

use a buffer for reading and one for writting within the logger.


diffs (272 lines):

diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -359,12 +359,12 @@ string_reader(logger *lg, BAT *b, lng nr
                if (mnstr_readLng(lg->input_log, &SZ) != 1)
                        return LOG_EOF;
                sz = (size_t)SZ;
-               char *buf = lg->buf;
-               if (lg->bufsize < sz) {
-                       if (!(buf = GDKrealloc(lg->buf, sz)))
+               char *buf = lg->rbuf;
+               if (lg->rbufsize < sz) {
+                       if (!(buf = GDKrealloc(lg->rbuf, sz)))
                                return LOG_ERR;
-                       lg->buf = buf;
-                       lg->bufsize = sz;
+                       lg->rbuf = buf;
+                       lg->rbufsize = sz;
                }
 
                if (mnstr_read(lg->input_log, buf, sz, 1) != 1)
@@ -438,13 +438,13 @@ log_read_updates(logger *lg, trans *tr, 
                                        BBPreclaim(r);
                                return LOG_ERR;
                        }
-                       size_t tlen = lg->bufsize;
-                       void *t = rt(lg->buf, &tlen, lg->input_log, 1);
+                       size_t tlen = lg->rbufsize;
+                       void *t = rt(lg->rbuf, &tlen, lg->input_log, 1);
                        if (t == NULL) {
                                res = LOG_ERR;
                        } else {
-                               lg->buf = t;
-                               lg->bufsize = tlen;
+                               lg->rbuf = t;
+                               lg->rbufsize = tlen;
                                for(BUN p = 0; p<(BUN) nr; p++) {
                                        if (r && BUNappend(r, t, true) != 
GDK_SUCCEED)
                                                res = LOG_ERR;
@@ -463,32 +463,32 @@ log_read_updates(logger *lg, trans *tr, 
                                        else
                                                res = LOG_ERR;
                                } else {
-                                       size_t tlen = lg->bufsize/sizeof(int);
+                                       size_t tlen = lg->rbufsize/sizeof(int);
                                        size_t cnt = 0, snr = (size_t)nr;
                                        snr = (snr+31)/32;
                                        assert(tlen);
                                        for (; res == LOG_OK && snr > 0; 
snr-=cnt) {
                                                cnt = snr>tlen?tlen:snr;
-                                               if 
(!mnstr_readIntArray(lg->input_log, lg->buf, cnt))
+                                               if 
(!mnstr_readIntArray(lg->input_log, lg->rbuf, cnt))
                                                        res = LOG_ERR;
                                        }
                                }
                        } else {
                                if (!ATOMvarsized(tpe)) {
                                        size_t cnt = 0, snr = (size_t)nr;
-                                       size_t tlen = 
lg->bufsize/ATOMsize(tpe), ntlen = lg->bufsize;
+                                       size_t tlen = 
lg->rbufsize/ATOMsize(tpe), ntlen = lg->rbufsize;
                                        assert(tlen);
                                        /* read in chunks of max
                                         * BUFSIZE/width rows */
                                        for (; res == LOG_OK && snr > 0; 
snr-=cnt) {
                                                cnt = snr>tlen?tlen:snr;
-                                               void *t = rt(lg->buf, &ntlen, 
lg->input_log, cnt);
+                                               void *t = rt(lg->rbuf, &ntlen, 
lg->input_log, cnt);
 
                                                if (t == NULL) {
                                                        res = LOG_EOF;
                                                        break;
                                                }
-                                               assert(t == lg->buf);
+                                               assert(t == lg->rbuf);
                                                if (r && BUNappendmulti(r, t, 
cnt, true) != GDK_SUCCEED)
                                                        res = LOG_ERR;
                                        }
@@ -497,8 +497,8 @@ log_read_updates(logger *lg, trans *tr, 
                                        res = string_reader(lg, r, nr);
                                } else {
                                        for (; res == LOG_OK && nr > 0; nr--) {
-                                               size_t tlen = lg->bufsize;
-                                               void *t = rt(lg->buf, &tlen, 
lg->input_log, 1);
+                                               size_t tlen = lg->rbufsize;
+                                               void *t = rt(lg->rbuf, &tlen, 
lg->input_log, 1);
 
                                                if (t == NULL) {
                                                        /* see if failure was 
due to
@@ -510,8 +510,8 @@ log_read_updates(logger *lg, trans *tr, 
                                                        else
                                                                res = LOG_ERR;
                                                } else {
-                                                       lg->buf = t;
-                                                       lg->bufsize = tlen;
+                                                       lg->rbuf = t;
+                                                       lg->rbufsize = tlen;
                                                        if (r && BUNappend(r, 
t, true) != GDK_SUCCEED)
                                                                res = LOG_ERR;
                                                }
@@ -560,8 +560,8 @@ log_read_updates(logger *lg, trans *tr, 
                                res = string_reader(lg, r, nr);
                        } else {
                                for (; res == LOG_OK && nr > 0; nr--) {
-                                       size_t tlen = lg->bufsize;
-                                       void *t = rt(lg->buf, &tlen, 
lg->input_log, 1);
+                                       size_t tlen = lg->rbufsize;
+                                       void *t = rt(lg->rbuf, &tlen, 
lg->input_log, 1);
 
                                        if (t == NULL) {
                                                if (strstr(GDKerrbuf, "malloc") 
== NULL)
@@ -569,8 +569,8 @@ log_read_updates(logger *lg, trans *tr, 
                                                else
                                                        res = LOG_ERR;
                                        } else {
-                                               lg->buf = t;
-                                               lg->bufsize = tlen;
+                                               lg->rbuf = t;
+                                               lg->rbufsize = tlen;
                                                if ((r && BUNappend(r, t, true) 
!= GDK_SUCCEED))
                                                        res = LOG_ERR;
                                        }
@@ -2081,7 +2081,8 @@ logger_load(int debug, const char *fn, c
        GDKfree(lg->fn);
        GDKfree(lg->dir);
        GDKfree(lg->local_dir);
-       GDKfree(lg->buf);
+       GDKfree(lg->rbuf);
+       GDKfree(lg->wbuf);
        GDKfree(lg);
        GDKdebug = dbg;
        return GDK_FAIL;
@@ -2130,13 +2131,17 @@ logger_new(int debug, const char *fn, co
        }
        lg->fn = GDKstrdup(fn);
        lg->dir = GDKstrdup(filename);
-       lg->bufsize = 64*1024;
-       lg->buf = GDKmalloc(lg->bufsize);
-       if (lg->fn == NULL || lg->dir == NULL || lg->buf == NULL) {
+       lg->rbufsize = 64*1024;
+       lg->rbuf = GDKmalloc(lg->rbufsize);
+       lg->wbufsize = 64*1024;
+       lg->wbuf = GDKmalloc(lg->wbufsize);
+       if (lg->fn == NULL || lg->dir == NULL ||
+           lg->rbuf == NULL || lg->wbuf == NULL) {
                TRC_CRITICAL(GDK, "strdup failed\n");
                GDKfree(lg->fn);
                GDKfree(lg->dir);
-               GDKfree(lg->buf);
+               GDKfree(lg->rbuf);
+               GDKfree(lg->wbuf);
                GDKfree(lg);
                return NULL;
        }
@@ -2189,7 +2194,8 @@ logger_destroy(logger *lg)
        }
        GDKfree(lg->fn);
        GDKfree(lg->dir);
-       GDKfree(lg->buf);
+       GDKfree(lg->rbuf);
+       GDKfree(lg->wbuf);
        logger_close_input(lg);
        logger_close_output(lg);
        GDKfree(lg);
@@ -2423,9 +2429,9 @@ log_constant(logger *lg, int type, ptr v
 static gdk_return
 string_writer(logger *lg, BAT *b, lng offset, lng nr)
 {
-       size_t bufsz = lg->bufsize, resize = 0;
+       size_t bufsz = lg->wbufsize, resize = 0;
        BUN end = (BUN)(offset + nr);
-       char *buf = lg->buf;
+       char *buf = lg->wbuf;
        gdk_return res = GDK_SUCCEED;
 
        if (!buf)
@@ -2435,12 +2441,12 @@ string_writer(logger *lg, BAT *b, lng of
        for ( ; p < end; ) {
                size_t sz = 0;
                if (resize) {
-                       if (!(buf = GDKrealloc(lg->buf, resize))) {
+                       if (!(buf = GDKrealloc(lg->wbuf, resize))) {
                                res = GDK_FAIL;
                                break;
                        }
-                       lg->buf = buf;
-                       lg->bufsize = bufsz = resize;
+                       lg->wbuf = buf;
+                       lg->wbufsize = bufsz = resize;
                        resize = 0;
                }
                char *dst = buf;
diff --git a/gdk/gdk_logger_internals.h b/gdk/gdk_logger_internals.h
--- a/gdk/gdk_logger_internals.h
+++ b/gdk/gdk_logger_internals.h
@@ -62,8 +62,10 @@ struct logger {
        BAT *type_nme;          /* names of types */
        BAT *type_nr;           /* atom number of this type (transient) */
 
-       void *buf;
-       size_t bufsize;
+       void *rbuf;
+       size_t rbufsize;
+       void *wbuf;
+       size_t wbufsize;
 };
 
 struct old_logger {
diff --git a/gdk/gdk_logger_old.c b/gdk/gdk_logger_old.c
--- a/gdk/gdk_logger_old.c
+++ b/gdk/gdk_logger_old.c
@@ -492,8 +492,8 @@ log_read_updates(old_logger *lg, trans *
                if (ht == TYPE_void && l->flag == LOG_INSERT) {
                        lng nr = l->nr;
                        for (; res == LOG_OK && nr > 0; nr--) {
-                               size_t tlen = lg->lg->bufsize;
-                               void *t = rt(lg->lg->buf, &tlen, lg->log, 1);
+                               size_t tlen = lg->lg->rbufsize;
+                               void *t = rt(lg->lg->rbuf, &tlen, lg->log, 1);
 
                                if (t == NULL) {
                                        /* see if failure was due to
@@ -506,8 +506,8 @@ log_read_updates(old_logger *lg, trans *
                                                res = LOG_ERR;
                                        break;
                                } else {
-                                       lg->lg->buf = t;
-                                       lg->lg->bufsize = tlen;
+                                       lg->lg->rbuf = t;
+                                       lg->lg->rbufsize = tlen;
                                }
                                if (BUNappend(r, t, true) != GDK_SUCCEED)
                                        res = LOG_ERR;
@@ -523,13 +523,13 @@ log_read_updates(old_logger *lg, trans *
                        if (!pax) {
                                lng nr = l->nr;
                                for (; res == LOG_OK && nr > 0; nr--) {
-                                       size_t tlen = lg->lg->bufsize;
+                                       size_t tlen = lg->lg->rbufsize;
                                        void *h = rh(hv, &hlen, lg->log, 1);
-                                       void *t = rt(lg->lg->buf, &tlen, 
lg->log, 1);
+                                       void *t = rt(lg->lg->rbuf, &tlen, 
lg->log, 1);
 
                                        if (t != NULL) {
-                                               lg->lg->buf = t;
-                                               lg->lg->bufsize = tlen;
+                                               lg->lg->rbuf = t;
+                                               lg->lg->rbufsize = tlen;
                                        }
                                        if (h == NULL)
                                                res = LOG_EOF;
@@ -571,8 +571,8 @@ log_read_updates(old_logger *lg, trans *
                                }
                                nr = l->nr;
                                for (; res == LOG_OK && nr > 0; nr--) {
-                                       size_t tlen = lg->lg->bufsize;
-                                       void *t = rt(lg->lg->buf, &tlen, 
lg->log, 1);
+                                       size_t tlen = lg->lg->rbufsize;
+                                       void *t = rt(lg->lg->rbuf, &tlen, 
lg->log, 1);
 
                                        if (t == NULL) {
                                                if (strstr(GDKerrbuf, "malloc") 
== NULL)
@@ -580,8 +580,8 @@ log_read_updates(old_logger *lg, trans *
                                                else
                                                        res = LOG_ERR;
                                        } else {
-                                               lg->lg->buf = t;
-                                               lg->lg->bufsize = tlen;
+                                               lg->lg->rbuf = t;
+                                               lg->lg->rbufsize = tlen;
                                                if (BUNappend(r, t, true) != 
GDK_SUCCEED)
                                                        res = LOG_ERR;
                                        }
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to