Changeset: 6eb21224de6b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/6eb21224de6b
Modified Files:
        gdk/gdk_logger.c
        gdk/gdk_logger_internals.h
        monetdb5/modules/mal/mal_mapi.c
Branch: default
Log Message:

Merge with Sep2022 branch.


diffs (183 lines):

diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -1095,6 +1095,9 @@ log_close_input(logger *lg)
 static inline void
 log_close_output(logger *lg)
 {
+       if (lg->flushing_output_log)
+               return;
+
        if (!LOG_DISABLED(lg))
                close_stream(lg->output_log);
        lg->output_log = NULL;
@@ -2806,10 +2809,21 @@ log_delta(logger *lg, BAT *uid, BAT *uva
 #define LOG_LARGE      (LL_CONSTANT(2)*1024*1024*1024)
 
 static gdk_return
-new_logfile(logger *lg)
+new_logfile(logger *lg, stream* output_log, ulng id)
 {
        assert(!LOG_DISABLED(lg));
 
+       MT_lock_set(&lg->rotation_lock);
+       assert(lg->flushing_output_log);
+       lg->flushing_output_log = false;
+       if (lg->id != id) {
+               /* lg->output_log was rotated during the flush */
+               assert(lg->output_log != output_log && lg->id > id);
+               close_stream(output_log);
+               MT_lock_unset(&lg->rotation_lock);
+               return GDK_SUCCEED;
+       }
+       MT_lock_unset(&lg->rotation_lock);
 
        const lng log_large = (GDKdebug & FORCEMITOMASK)?LOG_MINI:LOG_LARGE;
 
@@ -2928,7 +2942,12 @@ log_tflush(logger* lg, ulng log_file_id,
                return GDK_SUCCEED;
        }
 
-       if (log_file_id == lg->id) {
+
+       ulng id;
+       MT_lock_set(&lg->rotation_lock);
+       id = lg->id;
+       MT_lock_unset(&lg->rotation_lock);
+       if (log_file_id == id) {
                unsigned int number = request_number_flush_queue(lg);
 
                MT_lock_set(&lg->flush_lock);
@@ -2938,10 +2957,16 @@ log_tflush(logger* lg, ulng log_file_id,
                        const int fqueue_length = flush_queue_length(lg);
                        /* flush + fsync */
                        MT_lock_set(&lg->rotation_lock);
-                       if (mnstr_flush(lg->output_log, MNSTR_FLUSH_DATA) ||
-                                       (!(GDKdebug & NOSYNCMASK) && 
mnstr_fsync(lg->output_log)) ||
-                                       new_logfile(lg) != GDK_SUCCEED) {
+                       lg->flushing_output_log = true;
+                       stream* output_log = lg->output_log;
+                       id = lg->id;
+                       MT_lock_unset(&lg->rotation_lock);
+                       if (mnstr_flush(output_log, MNSTR_FLUSH_DATA) ||
+                                       (!(GDKdebug & NOSYNCMASK) && 
mnstr_fsync(output_log)) ||
+                                       new_logfile(lg, output_log, id) != 
GDK_SUCCEED) {
                                /* flush failed */
+                               MT_lock_set(&lg->rotation_lock);
+                               lg->flushing_output_log = false;
                                MT_lock_unset(&lg->rotation_lock);
                                MT_lock_unset(&lg->flush_lock);
                                (void) ATOMIC_DEC(&lg->refcount);
@@ -2949,7 +2974,6 @@ log_tflush(logger* lg, ulng log_file_id,
                        }
                        else {
                                /* flush succeeded */
-                               MT_lock_unset(&lg->rotation_lock);
                                left_truncate_flush_queue(lg, fqueue_length);
                        }
                }
@@ -3132,7 +3156,7 @@ log_tstart(logger *lg, bool flushnow, ul
 {
        MT_lock_set(&lg->rotation_lock);
        log_lock(lg);
-       if (flushnow || (lg->request_rotation && ATOMIC_GET(&lg->refcount) == 
0)) {
+       if ((flushnow || (lg->request_rotation && ATOMIC_GET(&lg->refcount) == 
0)) && lg->end > 0) {
                lg->id++;
                log_close_output(lg);
                /* start new file */
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
@@ -47,6 +47,7 @@ struct logger {
        lng end;                /* end of pre-allocated blocks for faster 
f(data)sync */
 
        ATOMIC_TYPE refcount; /* Number of active writers and flushers in the 
logger */ // TODO check refcount in c->log and c->end
+       bool flushing_output_log; /* prevent output_log that is currently being 
flushed from being closed */
        MT_Lock rotation_lock;
        MT_Lock lock;
        /* Store log_bids (int) to circumvent trouble with reference counting */
diff --git a/monetdb5/modules/mal/mal_mapi.c b/monetdb5/modules/mal/mal_mapi.c
--- a/monetdb5/modules/mal/mal_mapi.c
+++ b/monetdb5/modules/mal/mal_mapi.c
@@ -570,12 +570,25 @@ start_listen(SOCKET *sockp, int *portp, 
                                sock = INVALID_SOCKET;
                                continue;
                        }
-                       if (bind(sock, rp->ai_addr, (SOCKLEN) rp->ai_addrlen) 
== SOCKET_ERROR) {
+                       if ((e = bind(sock, rp->ai_addr, (SOCKLEN) 
rp->ai_addrlen)) != 0) {
+                               /* return value of 1 is currently undocumented, 
but
+                                * seems to occur when binding a port to an 
IPv4 socket
+                                * when the same port is already bound to an 
IPv6 socket
+                                * that already also listens to IPv4; in this 
case the
+                                * port that is actually bound to here is a 
different
+                                * one, and we don't want that, so we close the 
socket
+                                * without error (if bind returned 
SOCKET_ERROR, we do
+                                * report the error) */
+                               if (e == SOCKET_ERROR) {
 #ifdef _MSC_VER
-                               e = WSAGetLastError();
+                                       e = WSAGetLastError();
 #else
-                               e = errno;
+                                       e = errno;
 #endif
+                               } else if (nsock == 0) {
+                                       assert(e == 1);
+                                       e = 0;
+                               }
                                closesocket(sock);
                                sock = INVALID_SOCKET;
                                continue;
diff --git a/tools/merovingian/daemon/connections.c 
b/tools/merovingian/daemon/connections.c
--- a/tools/merovingian/daemon/connections.c
+++ b/tools/merovingian/daemon/connections.c
@@ -106,29 +106,35 @@ openConnectionIP(int *socks, bool udp, c
                                                   (const char *) &(int){0}, 
sizeof(int)) == -1)
                                Mlevelfprintf(ERROR, log, "setsockopt 
IPV6_V6ONLY: %s\n", strerror(e));
 
-                       if (!udp) {
-                               if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
-                                                          (const char *) &on, 
sizeof on) < 0) {
-                                       e = errno;
-                                       closesocket(sock);
-                                       continue;
-                               }
+                       if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
+                                                  (const char *) &on, sizeof 
on) < 0) {
+                               e = errno;
+                               closesocket(sock);
+                               continue;
+                       }
 #ifdef SO_EXCLUSIVEADDRUSE
-                               if (setsockopt(sock, SOL_SOCKET, 
SO_EXCLUSIVEADDRUSE,
-                                                          (const char *) &on, 
sizeof on) < 0)
-                                       Mlevelfprintf(ERROR, log, "setsockopt 
SO_EXCLUSIVEADDRUSE: %s\n", strerror(e));
+                       if (setsockopt(sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE,
+                                                  (const char *) &on, sizeof 
on) < 0)
+                               Mlevelfprintf(ERROR, log, "setsockopt 
SO_EXCLUSIVEADDRUSE: %s\n", strerror(e));
 #endif
 #ifdef SO_EXCLBIND
-                               if (setsockopt(sock, SOL_SOCKET, SO_EXCLBIND,
-                                                          (const char *) &on, 
sizeof on) < 0)
-                                       Mlevelfprintf(ERROR, log, "setsockopt 
SO_EXCLBIND: %s\n", strerror(e));
+                       if (setsockopt(sock, SOL_SOCKET, SO_EXCLBIND,
+                                                  (const char *) &on, sizeof 
on) < 0)
+                               Mlevelfprintf(ERROR, log, "setsockopt 
SO_EXCLBIND: %s\n", strerror(e));
 #endif
                        }
 
-                       if (bind(sock, rp->ai_addr, rp->ai_addrlen) == -1) {
+                       switch (bind(sock, rp->ai_addr, rp->ai_addrlen)) {
+                       case -1:
                                e = errno;
                                closesocket(sock);
                                continue;
+                       case 0:
+                               /* normal return */
+                               break;
+                       case 1:
+                               closesocket(sock);
+                               continue;
                        }
                        if (!udp && listen(sock, 5) == -1) {
                                e = errno;
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to