Changeset: f23219516173 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/f23219516173
Modified Files:
        gdk/gdk_interprocess.c
        gdk/gdk_logger.c
        gdk/gdk_private.h
        monetdb5/modules/mal/tablet.c
        sql/ChangeLog.Sep2022
Branch: multi-cachelock
Log Message:

revert to Sep2022 8th of December e3bf73edad44


diffs (127 lines):

diff --git a/gdk/gdk_interprocess.c b/gdk/gdk_interprocess.c
--- a/gdk/gdk_interprocess.c
+++ b/gdk/gdk_interprocess.c
@@ -51,7 +51,7 @@ GDKuniqueid(size_t offset)
 }
 
 //! Create a memory mapped file if it does not exist and open it
-/* id: The unique identifier of the memory mapped file (use GDKuniquemmapid to 
get a unique identifier)
+/* id: The unique identifier of the memory mapped file (use GDKuniqueid to get 
a unique identifier)
  * size: Minimum required size of the file
  * return: Return value pointing into the file, NULL if not successful
 */
@@ -67,11 +67,12 @@ GDKinitmmap(size_t id, size_t size, size
        GDKmmapfile(address, sizeof(address), id);
 
        /* round up to multiple of GDK_mmap_pagesize with a
-        * minimum of one
-        size = (maxsize + GDK_mmap_pagesize - 1) & ~(GDK_mmap_pagesize - 1);
-        if (size == 0)
-        size = GDK_mmap_pagesize; */
-       path = GDKfilepath(0, BATDIR, address, "tmp");
+        * minimum of one */
+       size = (size + GDK_mmap_pagesize - 1) & ~(GDK_mmap_pagesize - 1);
+       if (size == 0)
+               size = GDK_mmap_pagesize;
+       int farmid = BBPselectfarm(TRANSIENT, TYPE_bte, dataheap);
+       path = GDKfilepath(farmid, BATDIR, address, "tmp");
        if (path == NULL) {
                return NULL;
        }
@@ -113,7 +114,8 @@ GDKreleasemmap(void *ptr, size_t size, s
        if (GDKmunmap(ptr, size) != GDK_SUCCEED) {
                return GDK_FAIL;
        }
-       path = GDKfilepath(0, BATDIR, address, "tmp");
+       int farmid = BBPselectfarm(TRANSIENT, TYPE_bte, dataheap);
+       path = GDKfilepath(farmid, BATDIR, address, "tmp");
        if (path == NULL) {
                return GDK_FAIL;
        }
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -2789,12 +2789,9 @@ new_logfile(logger *lg)
        const lng log_large = (GDKdebug & FORCEMITOMASK)?LOG_MINI:LOG_LARGE;
 
        gdk_return result = GDK_SUCCEED;
-       MT_lock_set(&lg->rotation_lock);
        const lng p = (lng) getfilepos(getFile(lg->output_log));
-       if (p == -1) {
-               MT_lock_unset(&lg->rotation_lock);
+       if (p == -1)
                return GDK_FAIL;
-       }
        if (( p > log_large || (lg->end*1024) > log_large )) {
                log_lock(lg);
                if (ATOMIC_GET(&lg->refcount) == 1) {
@@ -2809,7 +2806,6 @@ new_logfile(logger *lg)
                }
                log_unlock(lg);
        }
-       MT_lock_unset(&lg->rotation_lock);
        return result;
 }
 
@@ -2916,16 +2912,19 @@ log_tflush(logger* lg, ulng log_file_id,
                        /* number of transactions in the group commit */
                        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) {
                                /* flush failed */
+                               MT_lock_unset(&lg->rotation_lock);
                                MT_lock_unset(&lg->flush_lock);
                                (void) ATOMIC_DEC(&lg->refcount);
                                return GDK_FAIL;
                        }
                        else {
                                /* flush succeeded */
+                               MT_lock_unset(&lg->rotation_lock);
                                left_truncate_flush_queue(lg, fqueue_length);
                        }
                }
diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h
--- a/gdk/gdk_private.h
+++ b/gdk/gdk_private.h
@@ -29,7 +29,8 @@ enum heaptype {
        hashheap,
        imprintsheap,
        orderidxheap,
-       strimpheap
+       strimpheap,
+       dataheap
 };
 
 gdk_return ATOMheap(int id, Heap *hp, size_t cap)
diff --git a/monetdb5/modules/mal/tablet.c b/monetdb5/modules/mal/tablet.c
--- a/monetdb5/modules/mal/tablet.c
+++ b/monetdb5/modules/mal/tablet.c
@@ -133,10 +133,12 @@ TABLETcreate_bats(Tablet *as, BUN est)
                fmt[i].c = void_bat_create(fmt[i].adt, est);
                if (!fmt[i].c) {
                        while (i > 0) {
-                               if (!fmt[--i].skip)
+                               if (!fmt[--i].skip) {
                                        BBPreclaim(fmt[i].c);
+                                       fmt[i].c = NULL;
+                               }
                        }
-                       throw(SQL, "copy", "Failed to create bat of size " 
BUNFMT "\n", as->nr);
+                       throw(SQL, "copy", "Failed to create bat of size " 
BUNFMT "\n", est);
                }
                fmt[i].ci = bat_iterator_nolock(fmt[i].c);
                nr++;
diff --git a/sql/ChangeLog.Sep2022 b/sql/ChangeLog.Sep2022
--- a/sql/ChangeLog.Sep2022
+++ b/sql/ChangeLog.Sep2022
@@ -1,3 +1,7 @@
 # ChangeLog file for sql
 # This file is updated with Maddlog
 
+* Wed Dec  7 2022 Sjoerd Mullender <[email protected]>
+- Fixed a double cleanup after a failed allocation in COPY INTO.  The
+  double cleanup could cause a crash due to a race condition it enabled.
+
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to