Changeset: d2a10c3cdf0b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d2a10c3cdf0b
Branch: window-tunning
Log Message:

Merged with default


diffs (truncated from 140964 to 300 lines):

diff --git a/.editorconfig b/.editorconfig
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,9 +1,11 @@
+root = true
+
 # Unix-style newlines with a newline ending every file
 [*]
 end_of_line = lf
 insert_final_newline = true
 
-[*.{c,h}]
+[*.{c,h}{,.in}]
 indent_style = tab
 tab_width = 4
 indent_size = tab
@@ -11,12 +13,13 @@ trim_trailing_whitespace = true
 charset = utf-8
 max_line_length = 120
 
-[*.py]
+[*.py{,.in}]
 indent_style = space
 indent_size = 4
 trim_trailing_whitespace = true
 charset = utf-8
 
-[gdk/*.{c,h}]
-tab_width = 8
-max_line_length = 72
+[{CMakeLists.txt,*.cmake}{,.in}]
+indent_style = space
+indent_size = 2
+trim_trailing_whitespace = true
diff --git a/MonetDB.spec b/MonetDB.spec
--- a/MonetDB.spec
+++ b/MonetDB.spec
@@ -140,6 +140,13 @@ BuildRequires: pkgconfig(openssl)
 BuildRequires: pkgconfig(libpcre) >= 4.5
 %endif
 BuildRequires: pkgconfig(zlib)
+%if %{?rhel:0}%{!?rhel:1} || 0%{?rhel} > 7
+# not on RHEL 7
+BuildRequires: pkgconfig(liblz4) >= 1.8
+%global LZ4 ON
+%else
+%global LZ4 OFF
+%endif
 %if %{with py3integration}
 BuildRequires: pkgconfig(python3) >= 3.5
 BuildRequires: python3-numpy
@@ -149,8 +156,6 @@ BuildRequires: pkgconfig(libR)
 %endif
 # if we were to compile with cmocka support (-DWITH_CMOCKA=ON):
 # BuildRequires: pkgconfig(cmocka)
-# if we were to compile with lz4 support (-DWITH_LZ4=ON):
-# BuildRequires: pkgconfig(liblz4)
 # if we were to compile with NetCDF support (-DNETCDF=ON):
 # BuildRequires: pkgconfig(netcdf)
 # if we were to compile with proj support (-DWITH_PROJ=ON):
@@ -801,7 +806,7 @@ export CFLAGS
        -DWITH_CMOCKA=OFF \
        -DWITH_CRYPTO=ON \
        -DWITH_CURL=ON \
-       -DWITH_LZ4=OFF \
+       -DWITH_LZ4=%{LZ4} \
        -DWITH_LZMA=ON \
        -DWITH_PCRE=ON \
        -DWITH_PROJ=OFF \
diff --git a/debian/control b/debian/control
--- a/debian/control
+++ b/debian/control
@@ -7,7 +7,7 @@ Vcs-Browser: https://dev.monetdb.org/hg/
 Vcs-Hg: https://dev.monetdb.org/hg/MonetDB/
 Build-Depends: debhelper (>= 9), cmake (>= 3.12), bison,
  libbz2-dev, libcurl4-gnutls-dev, libgeos-dev (>= 3.4.0),
- libpcre3-dev, libreadline-dev, liblzma-dev,
+ libpcre3-dev, libreadline-dev, liblzma-dev, liblz4-dev (>= 1.8.0),
  libssl-dev, libxml2-dev, pkg-config,
  python3, python3-dev, python3-numpy,
  unixodbc-dev, uuid-dev, zlib1g-dev, r-base-dev,
diff --git a/debian/rules b/debian/rules
--- a/debian/rules
+++ b/debian/rules
@@ -31,7 +31,7 @@ override_dh_auto_configure:
        -DWITH_CMOCKA=OFF \
        -DWITH_CRYPTO=ON \
        -DWITH_CURL=ON \
-       -DWITH_LZ4=OFF \
+       -DWITH_LZ4=ON \
        -DWITH_LZMA=ON \
        -DWITH_PCRE=ON \
        -DWITH_PROJ=OFF \
diff --git a/gdk/.editorconfig b/gdk/.editorconfig
new file mode 100644
--- /dev/null
+++ b/gdk/.editorconfig
@@ -0,0 +1,3 @@
+[*.{c,h}]
+tab_width = 8
+max_line_length = 72
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -1334,17 +1334,18 @@ gdk_export bat BBPlimit;
 gdk_export BBPrec *BBP[N_BBPINIT];
 
 /* fast defines without checks; internal use only  */
-#define BBP_cache(i)   BBP[(i)>>BBPINITLOG][(i)&(BBPINIT-1)].cache
-#define BBP_logical(i) BBP[(i)>>BBPINITLOG][(i)&(BBPINIT-1)].logical
-#define BBP_bak(i)     BBP[(i)>>BBPINITLOG][(i)&(BBPINIT-1)].bak
-#define BBP_next(i)    BBP[(i)>>BBPINITLOG][(i)&(BBPINIT-1)].next
-#define BBP_physical(i)        BBP[(i)>>BBPINITLOG][(i)&(BBPINIT-1)].physical
-#define BBP_options(i) BBP[(i)>>BBPINITLOG][(i)&(BBPINIT-1)].options
-#define BBP_desc(i)    BBP[(i)>>BBPINITLOG][(i)&(BBPINIT-1)].desc
-#define BBP_refs(i)    BBP[(i)>>BBPINITLOG][(i)&(BBPINIT-1)].refs
-#define BBP_lrefs(i)   BBP[(i)>>BBPINITLOG][(i)&(BBPINIT-1)].lrefs
-#define BBP_status(i)  BBP[(i)>>BBPINITLOG][(i)&(BBPINIT-1)].status
-#define BBP_pid(i)     BBP[(i)>>BBPINITLOG][(i)&(BBPINIT-1)].pid
+#define BBP_record(i)  BBP[(i)>>BBPINITLOG][(i)&(BBPINIT-1)]
+#define BBP_cache(i)   BBP_record(i).cache
+#define BBP_logical(i) BBP_record(i).logical
+#define BBP_bak(i)     BBP_record(i).bak
+#define BBP_next(i)    BBP_record(i).next
+#define BBP_physical(i)        BBP_record(i).physical
+#define BBP_options(i) BBP_record(i).options
+#define BBP_desc(i)    BBP_record(i).desc
+#define BBP_refs(i)    BBP_record(i).refs
+#define BBP_lrefs(i)   BBP_record(i).lrefs
+#define BBP_status(i)  BBP_record(i).status
+#define BBP_pid(i)     BBP_record(i).pid
 #define BATgetId(b)    BBP_logical((b)->batCacheid)
 #define BBPvalid(i)    (BBP_logical(i) != NULL && *BBP_logical(i) != '.')
 
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -3624,6 +3624,10 @@ BBPdiskscan(const char *parent, size_t b
                                /* older versions used .thash which we
                                 * can simply ignore */
                                delete = true;
+                       } else if (strncmp(p + 1, "thsh", 4) == 0) {
+                               /* temporary hash files which we can
+                                * simply ignore */
+                               delete = true;
                        } else if (strncmp(p + 1, "timprints", 9) == 0) {
                                BAT *b = getdesc(bid);
                                delete = b == NULL;
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
@@ -60,17 +60,51 @@ static struct rusage prevUsage;
 #define LOGLEN 8192
 #define lognew()  loglen = 0; logbase = logbuffer; *logbase = 0;
 
+/*
+ * We use a buffer (`logbuffer`) where we incrementally create the output JSON 
object. Initially we allocate LOGLEN (8K)
+ * bytes and we keep the capacity of the buffer (`logcap`) and the length of 
the current string (`loglen`).
+ *
+ * We use the `logadd` macro to add data to our buffer (usually key-value 
pairs). This macro offers an interface similar
+ * to printf.
+ *
+ * The first snprintf bellow happens in a statically allocated buffer that 
might be much smaller than logcap. We do not
+ * care. We only need to perform this snprintf to get the actual length of the 
string that is to be produced.
+ *
+ * There are three cases:
+ *
+ * 1. The new string fits in the current buffer -> we just update the buffer
+ *
+ * 2. The new string does not fit in the current buffer, but is smaller than 
the capacity of the buffer -> we output the
+ * current contents of the buffer and start at the beginnig.
+ *
+ * 3. The new string exceeds the current capacity of the buffer -> we output 
the current contents and reallocate the
+ * buffer. The new capacity is 1.5 times the length of the new string.
+ */
 #define logadd(...)                                                            
                                                \
        do {                                                                    
                                                        \
                char tmp_buff[LOGLEN];                                          
                                        \
-               int tmp_len = 0;                                                
                                                \
+               size_t tmp_len = 0;                                             
                                                \
                tmp_len = snprintf(tmp_buff, LOGLEN, __VA_ARGS__);              
                \
-               if (loglen + tmp_len < LOGLEN)                                  
                                \
-                       loglen += snprintf(logbase+loglen, LOGLEN - loglen, 
__VA_ARGS__); \
-               else {                                                          
                                                        \
+               if (loglen + tmp_len < logcap)                                  
                                \
+                       loglen += snprintf(logbase+loglen, logcap - loglen, 
__VA_ARGS__); \
+               else if (tmp_len < logcap) {                                    
                                \
                        logjsonInternal(logbuffer);                             
                                        \
                        lognew();                                               
                                                        \
-                       loglen += snprintf(logbase+loglen, LOGLEN - loglen, 
__VA_ARGS__); \
+                       loglen += snprintf(logbase+loglen, logcap - loglen, 
__VA_ARGS__); \
+               }                                                               
                                                                \
+               else {                                                          
                                                        \
+                       char *alloc_buff;                                       
                                                \
+                       logjsonInternal(logbuffer);                             
                                        \
+                       logcap = tmp_len + tmp_len/2;                           
                                \
+                       alloc_buff = (char *)realloc(logbuffer, logcap);        
                \
+                       if (alloc_buff == NULL) {                               
                                        \
+                               TRC_ERROR(MAL_SERVER, "Profiler JSON buffer 
reallocation failure\n"); \
+                               free(logbuffer);                                
                                                \
+                               return;                                         
                                                        \
+                       }                                                       
                                                                \
+                       logbuffer = alloc_buff;                                 
                                        \
+                       lognew();                                               
                                                        \
+                       loglen += snprintf(logbase+loglen, logcap - loglen, 
__VA_ARGS__); \
                }                                                               
                                                                \
        } while (0)
 
@@ -89,27 +123,6 @@ static void logjsonInternal(char *logbuf
        MT_lock_unset(&mal_profileLock);
 }
 
-static char *
-truncate_string(char *inp)
-{
-       size_t len;
-       char *ret;
-       size_t ret_len = LOGLEN/2;
-       size_t padding = 64;
-
-       len = strlen(inp);
-       ret = (char *)GDKmalloc(ret_len + 1);
-       if (ret == NULL) {
-               return NULL;
-       }
-
-       snprintf(ret, ret_len + 1, "%.*s...<truncated>...%.*s",
-                        (int) (ret_len/2), inp, (int) (ret_len/2 - padding),
-                        inp + (len - ret_len/2 + padding));
-
-       return ret;
-}
-
 /* JSON rendering method of performance data.
  * The eventparser may assume this layout for ease of parsing
 EXAMPLE:
@@ -127,8 +140,8 @@ EXAMPLE:
 static void
 renderProfilerEvent(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, 
int start)
 {
-       char logbuffer[LOGLEN], *logbase;
-       size_t loglen;
+       char *logbuffer = NULL, *logbase;
+       size_t loglen, logcap = LOGLEN;
        str c;
        str stmtq;
        lng usec;
@@ -150,6 +163,12 @@ renderProfilerEvent(Client cntxt, MalBlk
        if(malprofileruser!= MAL_ADMIN && malprofileruser != cntxt->user)
                return;
 
+       logbuffer = (char *)malloc(logcap);
+       if (logbuffer == NULL) {
+               TRC_ERROR(MAL_SERVER, "Profiler JSON buffer allocation 
failure\n");
+               return;
+       }
+
        usec= pci->clock;
        microseconds = (uint64_t)usec - ((uint64_t)startup_time.tv_sec*1000000 
- (uint64_t)startup_time.tv_usec);
        /* make profile event tuple  */
@@ -275,17 +294,11 @@ This information can be used to determin
                                        logadd(",\"count\":"BUNFMT, cnt);
                                        logadd(",\"size\":" LLFMT, total);
                                } else{
-                                       char *truncated = NULL;
                                        tname = getTypeName(tpe);
                                        logadd(",\"type\":\"%s\"", tname);
                                        logadd(",\"const\":%d", 
isVarConstant(mb, getArg(pci,j)));
                                        cv = 
VALformat(&stk->stk[getArg(pci,j)]);
                                        stmtq = cv ? mal_quote(cv, strlen(cv)) 
: NULL;
-                                       if (stmtq != NULL && strlen(stmtq) > 
LOGLEN/2) {
-                                               truncated = 
truncate_string(stmtq);
-                                               GDKfree(stmtq);
-                                               stmtq = truncated;
-                                       }
                                        if (stmtq)
                                                logadd(",\"value\":\"%s\"", 
stmtq);
                                        GDKfree(cv);
@@ -302,6 +315,7 @@ This information can be used to determin
                }
        logadd("}\n"); // end marker
        logjsonInternal(logbuffer);
+       free(logbuffer);
 }
 
 /* the OS details on cpu load are read from /proc/stat
@@ -381,8 +395,8 @@ void
 profilerHeartbeatEvent(char *alter)
 {
        char cpuload[BUFSIZ];
-       char logbuffer[LOGLEN], *logbase;
-       int loglen;
+       char *logbuffer = NULL, *logbase;
+       size_t loglen, logcap = LOGLEN;
        lng usec;
        uint64_t microseconds;
 
@@ -395,6 +409,12 @@ profilerHeartbeatEvent(char *alter)
        if (getCPULoad(cpuload))
                return;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to