Changeset: abdda4d9394d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/abdda4d9394d
Modified Files:
        gdk/gdk_heap.c
        gdk/gdk_rtree.c
        gdk/gdk_storage.c
Branch: default
Log Message:

Use proper open modes so that we don't need the HACK to only sometimes truncate 
files being opened.


diffs (143 lines):

diff --git a/gdk/gdk_heap.c b/gdk/gdk_heap.c
--- a/gdk/gdk_heap.c
+++ b/gdk/gdk_heap.c
@@ -355,40 +355,34 @@ HEAPextend(Heap *h, size_t size, bool ma
                         * to STORE_PRIV (copy-on-write memory mapped files),
                         * but if the heap file doesn't exist yet, the BAT is
                         * new and we can use STORE_MMAP */
-                       int fd = GDKfdlocate(h->farmid, nme, "rb", ext);
+                       int fd = GDKfdlocate(h->farmid, nme, "r+b", ext);
                        if (fd >= 0) {
                                assert(h->hasfile);
+                               gdk_return rc = GDKextendf(fd, size, nme);
                                close(fd);
-                               fd = GDKfdlocate(h->farmid, nme, "wb", ext);
-                               if (fd >= 0) {
-                                       gdk_return rc = GDKextendf(fd, size, 
nme);
-                                       close(fd);
-                                       if (rc != GDK_SUCCEED) {
-                                               failure = "h->storage == 
STORE_MEM && can_map && fd >= 0 && GDKextendf() != GDK_SUCCEED";
-                                               goto failed;
-                                       }
-                                       h->storage = h->newstorage == 
STORE_MMAP && !mayshare ? STORE_PRIV : h->newstorage;
-                                       /* make sure we really MMAP */
-                                       if (must_mmap && h->newstorage == 
STORE_MEM)
-                                               h->storage = STORE_MMAP;
-                                       h->newstorage = h->storage;
+                               if (rc != GDK_SUCCEED) {
+                                       failure = "h->storage == STORE_MEM && 
can_map && fd >= 0 && GDKextendf() != GDK_SUCCEED";
+                                       goto failed;
+                               }
+                               h->storage = h->newstorage == STORE_MMAP && 
!mayshare ? STORE_PRIV : h->newstorage;
+                               /* make sure we really MMAP */
+                               if (must_mmap && h->newstorage == STORE_MEM)
+                                       h->storage = STORE_MMAP;
+                               h->newstorage = h->storage;
 
-                                       h->base = NULL;
-                                       TRC_DEBUG(HEAP, "Converting malloced to 
%s mmapped heap %s\n", h->newstorage == STORE_MMAP ? "shared" : "privately", 
h->filename);
-                                       /* try to allocate a memory-mapped based
-                                        * heap */
-                                       if (HEAPload(h, nme, ext, false) == 
GDK_SUCCEED) {
-                                               /* copy data to heap and free 
old
-                                                * memory */
-                                               memcpy(h->base, bak.base, 
bak.free);
-                                               HEAPfree(&bak, false);
-                                               return GDK_SUCCEED;
-                                       }
-                                       failure = "h->storage == STORE_MEM && 
can_map && fd >= 0 && HEAPload() != GDK_SUCCEED";
-                                       /* we failed */
-                               } else {
-                                       failure = "h->storage == STORE_MEM && 
can_map && fd < 0";
+                               h->base = NULL;
+                               TRC_DEBUG(HEAP, "Converting malloced to %s 
mmapped heap %s\n", h->newstorage == STORE_MMAP ? "shared" : "privately", 
h->filename);
+                               /* try to allocate a memory-mapped based
+                                * heap */
+                               if (HEAPload(h, nme, ext, false) == 
GDK_SUCCEED) {
+                                       /* copy data to heap and free old
+                                        * memory */
+                                       memcpy(h->base, bak.base, bak.free);
+                                       HEAPfree(&bak, false);
+                                       return GDK_SUCCEED;
                                }
+                               failure = "h->storage == STORE_MEM && can_map 
&& fd >= 0 && HEAPload() != GDK_SUCCEED";
+                               /* we failed */
                        } else {
                                /* no pre-existing heap file, so create a new
                                 * one */
diff --git a/gdk/gdk_rtree.c b/gdk/gdk_rtree.c
--- a/gdk/gdk_rtree.c
+++ b/gdk/gdk_rtree.c
@@ -159,7 +159,7 @@ RTREEexistsonfile(BAT *b)
        if (!b->theap) return false;
 
        int farmid = b->theap->farmid;
-       int fd = GDKfdlocate(farmid, filename, "r", "bsrt");
+       int fd = GDKfdlocate(farmid, filename, "rb", "bsrt");
 
        //Do we have the rtree on file?
        if (fd == -1) {
diff --git a/gdk/gdk_storage.c b/gdk/gdk_storage.c
--- a/gdk/gdk_storage.c
+++ b/gdk/gdk_storage.c
@@ -41,13 +41,12 @@
 #endif
 #endif
 
-/* GDKfilepath writes the path name of a database file into path and
- * returns a pointer to it.  The arguments are the buffer into which the
- * path is written, the size of that buffer, the farmID or -1, the name
- * of a subdirectory within the farm (i.e., something like BATDIR or
- * BAKDIR -- see gdk.h) or NULL, the name of a BAT (i.e. the name that
- * is stored in BBP.dir -- something like 07/714), and finally the file
- * extension.
+/* GDKfilepath writes the path name of a database file into path.  The
+ * arguments are the buffer into which the path is written, the size of
+ * that buffer, the farmID or -1, the name of a subdirectory within the
+ * farm (i.e., something like BATDIR or BAKDIR -- see gdk.h) or NULL,
+ * the name of a BAT (i.e. the name that is stored in BBP.dir --
+ * something like 07/714), and finally the file extension.
  *
  * If farmid is >= 0, GDKfilepath returns the complete path to the
  * specified farm concatenated with the other arguments with appropriate
@@ -220,29 +219,19 @@ GDKfdlocate(int farmid, const char *nme,
                nme = path;
        }
 
-       if (*mode == 'm') {     /* file open for mmap? */
-               mode++;
-#ifdef _CYGNUS_H_
+       if (strchr(mode, 'w')) {
+               flags |= O_CREAT | O_TRUNC;
+               if (strchr(mode, '+')) {
+                       flags |= O_RDWR;
+               } else {
+                       flags |= O_WRONLY;
+               }
+       } else if (strchr(mode, '+')) {
+               flags |= O_RDWR;
        } else {
-               flags |= _FRDSEQ;       /* WIN32 
CreateFile(FILE_FLAG_SEQUENTIAL_SCAN) */
-#endif
+               flags |= O_RDONLY;
        }
-
-       if (strchr(mode, 'w')) {
-               flags |= O_WRONLY | O_CREAT;
-               /* HACK ALERT: text files also get truncated but binary
-                * files not!  This is because mmap extend depends on
-                * files not getting truncated, and a second hot
-                * snapshot needs to completely overwrite a pre-existing
-                * (from an earlier snapshot) BBP.dir file. */
-               if (strchr(mode, 'b') == NULL)
-                       flags |= O_TRUNC;
-       } else if (!strchr(mode, '+')) {
-               flags |= O_RDONLY;
-       } else {
-               flags |= O_RDWR;
-       }
-#ifdef WIN32
+#ifdef O_BINARY
        flags |= strchr(mode, 'b') ? O_BINARY : O_TEXT;
 #endif
        fd = MT_open(nme, flags);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to