Changeset: 5d7e8652fef9 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/5d7e8652fef9
Branch: sql_profiler
Log Message:
Merge with default.
diffs (truncated from 557 to 300 lines):
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -810,6 +810,7 @@ typedef struct BAT {
MT_Lock theaplock; /* lock protecting heap reference changes */
MT_RWLock thashlock; /* lock specifically for hash management */
MT_Lock batIdxLock; /* lock to manipulate other indexes/properties
*/
+ Heap *oldtail; /* old tail heap, to be destroyed after commit
*/
} BAT;
/* macros to hide complexity of the BAT structure */
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -3502,45 +3502,13 @@ do_backup(const char *srcdir, const char
{
gdk_return ret = GDK_SUCCEED;
char extnew[16];
- bool istail = strncmp(ext, "tail", 4) == 0;
if (h->wasempty) {
return GDK_SUCCEED;
}
/* direct mmap is unprotected (readonly usage, or has WAL
- * protection); however, if we're backing up for subcommit
- * and a backup already exists in the main backup directory
- * (see GDKupgradevarheap), move the file */
- if (subcommit) {
- strcpy_len(extnew, ext, sizeof(extnew));
- char *p = extnew + strlen(extnew) - 1;
- if (*p == 'l') {
- p++;
- p[1] = 0;
- }
- bool exists;
- for (;;) {
- exists = file_exists(h->farmid, BAKDIR, nme, extnew);
- if (exists)
- break;
- if (!istail)
- break;
- if (*p == '1')
- break;
- if (*p == '2')
- *p = '1';
-#if SIZEOF_VAR_T == 8
- else if (*p != '4')
- *p = '4';
-#endif
- else
- *p = '2';
- }
- if (exists &&
- file_move(h->farmid, BAKDIR, SUBDIR, nme, extnew) !=
GDK_SUCCEED)
- return GDK_FAIL;
- }
+ * protection) */
if (h->storage != STORE_MMAP) {
/* STORE_PRIV saves into X.new files. Two cases could
* happen. The first is when a valid X.new exists
@@ -3552,75 +3520,21 @@ do_backup(const char *srcdir, const char
* these we write X.new.kill files in the backup
* directory (see heap_move). */
gdk_return mvret = GDK_SUCCEED;
- bool exists;
-
- if (istail) {
- exists = file_exists(h->farmid, BAKDIR, nme,
"tail.new") ||
-#if SIZEOF_VAR_T == 8
- file_exists(h->farmid, BAKDIR, nme,
"tail4.new") ||
-#endif
- file_exists(h->farmid, BAKDIR, nme,
"tail2.new") ||
- file_exists(h->farmid, BAKDIR, nme,
"tail1.new") ||
- file_exists(h->farmid, BAKDIR, nme, "tail") ||
-#if SIZEOF_VAR_T == 8
- file_exists(h->farmid, BAKDIR, nme, "tail4") ||
-#endif
- file_exists(h->farmid, BAKDIR, nme, "tail2") ||
- file_exists(h->farmid, BAKDIR, nme, "tail1");
- } else {
- exists = file_exists(h->farmid, BAKDIR, nme,
"theap.new") ||
- file_exists(h->farmid, BAKDIR, nme, "theap");
- }
strconcat_len(extnew, sizeof(extnew), ext, ".new", NULL);
- if (dirty && !exists) {
+ if (dirty &&
+ !file_exists(h->farmid, BAKDIR, nme, extnew) &&
+ !file_exists(h->farmid, BAKDIR, nme, ext)) {
/* if the heap is dirty and there is no heap
* file (with or without .new extension) in
* the BAKDIR, move the heap (preferably with
* .new extension) to the correct backup
* directory */
- if (istail) {
- if (file_exists(h->farmid, srcdir, nme,
"tail.new"))
- mvret = heap_move(h, srcdir,
- subcommit ? SUBDIR :
BAKDIR,
- nme, "tail.new");
-#if SIZEOF_VAR_T == 8
- else if (file_exists(h->farmid, srcdir, nme,
"tail4.new"))
- mvret = heap_move(h, srcdir,
- subcommit ? SUBDIR :
BAKDIR,
- nme, "tail4.new");
-#endif
- else if (file_exists(h->farmid, srcdir, nme,
"tail2.new"))
- mvret = heap_move(h, srcdir,
- subcommit ? SUBDIR :
BAKDIR,
- nme, "tail2.new");
- else if (file_exists(h->farmid, srcdir, nme,
"tail1.new"))
- mvret = heap_move(h, srcdir,
- subcommit ? SUBDIR :
BAKDIR,
- nme, "tail1.new");
- else if (file_exists(h->farmid, srcdir, nme,
"tail"))
- mvret = heap_move(h, srcdir,
- subcommit ? SUBDIR :
BAKDIR,
- nme, "tail");
-#if SIZEOF_VAR_T == 8
- else if (file_exists(h->farmid, srcdir, nme,
"tail4"))
- mvret = heap_move(h, srcdir,
- subcommit ? SUBDIR :
BAKDIR,
- nme, "tail4");
-#endif
- else if (file_exists(h->farmid, srcdir, nme,
"tail2"))
- mvret = heap_move(h, srcdir,
- subcommit ? SUBDIR :
BAKDIR,
- nme, "tail2");
- else if (file_exists(h->farmid, srcdir, nme,
"tail1"))
- mvret = heap_move(h, srcdir,
- subcommit ? SUBDIR :
BAKDIR,
- nme, "tail1");
- } else if (file_exists(h->farmid, srcdir, nme, extnew))
+ if (file_exists(h->farmid, srcdir, nme, extnew))
mvret = heap_move(h, srcdir,
subcommit ? SUBDIR : BAKDIR,
nme, extnew);
- else
+ else if (file_exists(h->farmid, srcdir, nme, ext))
mvret = heap_move(h, srcdir,
subcommit ? SUBDIR : BAKDIR,
nme, ext);
@@ -3885,32 +3799,6 @@ BBPsync(int cnt, bat *restrict subcommit
break;
}
}
- } else {
- if (subcommit && (b = BBP_desc(i)) &&
BBP_status(i) & BBPDELETED) {
- char o[10];
- char *f;
- snprintf(o, sizeof(o), "%o", (unsigned)
b->batCacheid);
- f = GDKfilepath(b->theap->farmid,
BAKDIR, o, BATtailname(b));
- if (f == NULL) {
- if (lock)
-
MT_lock_unset(&GDKswapLock(i));
- ret = GDK_FAIL;
- goto bailout;
- }
- if (MT_access(f, F_OK) == 0)
- file_move(b->theap->farmid,
BAKDIR, SUBDIR, o, BATtailname(b));
- GDKfree(f);
- f = GDKfilepath(b->theap->farmid,
BAKDIR, o, "theap");
- if (f == NULL) {
- if (lock)
-
MT_lock_unset(&GDKswapLock(i));
- ret = GDK_FAIL;
- goto bailout;
- }
- if (MT_access(f, F_OK) == 0)
- file_move(b->theap->farmid,
BAKDIR, SUBDIR, o, "theap");
- GDKfree(f);
- }
}
if (lock)
MT_lock_unset(&GDKswapLock(i));
@@ -4029,7 +3917,7 @@ BBPsync(int cnt, bat *restrict subcommit
TRC_DEBUG(PERF, "%s (ready time %d)\n",
ret == GDK_SUCCEED ? "" : " failed",
(t0 = GDKms()) - t1);
- bailout:
+
/* turn off the BBPSYNCING bits for all bats, even when things
* didn't go according to plan (i.e., don't check for ret ==
* GDK_SUCCEED) */
diff --git a/gdk/gdk_heap.c b/gdk/gdk_heap.c
--- a/gdk/gdk_heap.c
+++ b/gdk/gdk_heap.c
@@ -394,23 +394,6 @@ HEAPshrink(Heap *h, size_t size)
return GDK_FAIL;
}
-/* returns 1 if the file exists */
-static int
-file_exists(int farmid, const char *dir, const char *name, const char *ext)
-{
- char *path;
- struct stat st;
- int ret;
-
- path = GDKfilepath(farmid, dir, name, ext);
- if (path == NULL)
- return -1;
- ret = MT_stat(path, &st);
- TRC_DEBUG(IO_, "stat(%s) = %d\n", path, ret);
- GDKfree(path);
- return (ret == 0);
-}
-
/* grow the string offset heap so that the value v fits (i.e. wide
* enough to fit the value), and it has space for at least cap elements;
* copy ncopy BUNs, or up to the heap size, whichever is smaller */
@@ -427,7 +410,6 @@ GDKupgradevarheap(BAT *b, var_t v, BUN c
#endif
size_t i, n;
size_t newsize;
- const char *filename;
bat bid = b->batCacheid;
Heap *old, *new;
@@ -460,104 +442,7 @@ GDKupgradevarheap(BAT *b, var_t v, BUN c
n = MIN(ncopy, old->size >> b->tshift);
- if (width > b->twidth)
- MT_thread_setalgorithm(n ? "widen offset heap" : "widen empty
offset heap");
- /* Create a backup copy before widening.
- *
- * If the file is memory-mapped, this solves a problem that we
- * don't control what's in the actual file until the next
- * commit happens, so a crash might otherwise leave the file
- * (and the database) in an inconsistent state. If, on the
- * other hand, the heap is allocated, it may happen that later
- * on the heap is extended and converted into a memory-mapped
- * file. Then the same problem arises.
- *
- * also see do_backup in gdk_bbp.c */
- filename = strrchr(old->filename, DIR_SEP);
- if (filename == NULL)
- filename = old->filename;
- else
- filename++;
- int exists = 0;
- if (BBP_status(bid) & (BBPEXISTING|BBPDELETED) && width > b->twidth) {
- char fname[sizeof(old->filename)];
- char *p = strrchr(old->filename, DIR_SEP);
- strcpy_len(fname, p ? p + 1 : old->filename, sizeof(fname));
- p = fname + strlen(fname) - 1;
- if (*p == 'l') {
- p++;
- p[1] = 0;
- }
- MT_lock_set(&GDKtmLock);
- for (;;) {
- exists = file_exists(old->farmid, BAKDIR, fname, NULL);
- if (exists == -1) {
- MT_lock_unset(&GDKtmLock);
- return GDK_FAIL;
- }
- if (exists == 1)
- break;
- if (*p == '1')
- break;
- if (*p == '2')
- *p = '1';
-#if SIZEOF_VAR_T == 8
- else if (*p != '4')
- *p = '4';
-#endif
- else
- *p = '2';
- }
- if (exists == 0 &&
- (old->storage != STORE_MEM ||
- GDKmove(old->farmid, BATDIR, old->filename, NULL,
- BAKDIR, filename, NULL, false) != GDK_SUCCEED)) {
- int fd;
- ssize_t ret = 0;
- size_t size = n << b->tshift;
- const char *base = old->base;
-
- /* first save heap in file with extra .tmp extension */
- if ((fd = GDKfdlocate(old->farmid, old->filename, "wb",
"tmp")) < 0) {
- MT_lock_unset(&GDKtmLock);
- return GDK_FAIL;
- }
- while (size > 0) {
- ret = write(fd, base, (unsigned) MIN(1 << 30,
size));
- if (ret < 0)
- size = 0;
- size -= ret;
- base += ret;
- }
- if (ret < 0 ||
- (!(GDKdebug & NOSYNCMASK)
-#if defined(NATIVE_WIN32)
- && _commit(fd) < 0
-#elif defined(HAVE_FDATASYNC)
- && fdatasync(fd) < 0
-#elif defined(HAVE_FSYNC)
- && fsync(fd) < 0
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]