Changeset: b656dee6819f for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/b656dee6819f
Modified Files:
gdk/gdk.h
gdk/gdk_aggr.c
gdk/gdk_bbp.c
gdk/gdk_heap.c
gdk/gdk_join.c
gdk/gdk_logger.c
monetdb5/mal/mal.c
monetdb5/mal/mal_embedded.c
monetdb5/mal/mal_instruction.c
monetdb5/mal/mal_interpreter.c
monetdb5/mal/mal_namespace.c
monetdb5/mal/mal_resolve.c
monetdb5/mal/mal_session.c
monetdb5/modules/mal/calc.c
monetdb5/modules/mal/orderidx.c
sql/backends/monet5/UDF/pyapi3/conversion3.c
sql/backends/monet5/sql.c
sql/backends/monet5/sql_scenario.c
sql/storage/bat/bat_logger.c
sql/storage/bat/bat_storage.c
sql/storage/bat/bat_table.c
sql/storage/sql_storage.h
sql/storage/store.c
Branch: default
Log Message:
Merge with Sep2022 branch.
diffs (truncated from 1163 to 300 lines):
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -343,6 +343,8 @@
#define gdk_export extern
#endif
+/* Only ever compare with GDK_SUCCEED, never with GDK_FAIL, and do not
+ * use as a Boolean. */
typedef enum { GDK_FAIL, GDK_SUCCEED } gdk_return;
gdk_export _Noreturn void GDKfatal(_In_z_ _Printf_format_string_ const char
*format, ...)
diff --git a/gdk/gdk_aggr.c b/gdk/gdk_aggr.c
--- a/gdk/gdk_aggr.c
+++ b/gdk/gdk_aggr.c
@@ -56,6 +56,8 @@
* This function finds the minimum and maximum group id (and the
* number of groups) and initializes the variables for candidates
* selection.
+ *
+ * In case of error, returns an error message.
*/
const char *
BATgroupaggrinit(BAT *b, BAT *g, BAT *e, BAT *s,
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -3403,6 +3403,8 @@ BBPprepare(bool subcommit)
/* starting a subcommit. Make sure SUBDIR and DELDIR
* are clean */
ret = BBPrecover_subdir();
+ if (ret != GDK_SUCCEED)
+ return ret;
}
if (backup_files == 0) {
backup_dir = 0;
@@ -3435,7 +3437,7 @@ BBPprepare(bool subcommit)
GDKfree(subdirpath);
return GDK_FAIL;
}
- TRC_DEBUG(IO_, "mkdir %s = %d\n", subdirpath, (int) ret);
+ TRC_DEBUG(IO_, "mkdir %s\n", subdirpath);
GDKfree(subdirpath);
}
if (backup_dir != set) {
@@ -3943,6 +3945,7 @@ force_move(int farmid, const char *srcdi
if (ret != GDK_SUCCEED) {
char *srcpath;
+ GDKclrerr();
/* two legal possible causes: file exists or dir
* doesn't exist */
if(!(dstpath = GDKfilepath(farmid, dstdir, name, NULL)))
@@ -4112,10 +4115,10 @@ BBPrecover_subdir(void)
if (dent->d_name[0] == '.')
continue;
ret = GDKmove(0, SUBDIR, dent->d_name, NULL, BAKDIR,
dent->d_name, NULL, true);
- if (ret == GDK_SUCCEED && strcmp(dent->d_name, "BBP.dir") == 0)
- backup_dir = 1;
if (ret != GDK_SUCCEED)
break;
+ if (strcmp(dent->d_name, "BBP.dir") == 0)
+ backup_dir = 1;
}
closedir(dirp);
diff --git a/gdk/gdk_heap.c b/gdk/gdk_heap.c
--- a/gdk/gdk_heap.c
+++ b/gdk/gdk_heap.c
@@ -163,21 +163,28 @@ HEAPalloc(Heap *h, size_t nitems, size_t
h->base = GDKmalloc(h->size);
TRC_DEBUG(HEAP, "%s %zu %p\n", h->filename, h->size, h->base);
}
+
+ char *nme = NULL;
if (!GDKinmemory(h->farmid) && h->base == NULL) {
- char *nme;
-
nme = GDKfilepath(h->farmid, BATDIR, h->filename, NULL);
if (nme == NULL)
return GDK_FAIL;
h->storage = STORE_MMAP;
h->base = HEAPcreatefile(NOFARM, &h->size, nme);
h->hasfile = true;
- GDKfree(nme);
}
if (h->base == NULL) {
+ /* remove file we may just have created */
+ if (nme != NULL) {
+ /* file may or may not exist, depending on what
+ * failed */
+ (void) MT_remove(nme);
+ GDKfree(nme);
+ }
GDKerror("Insufficient space for HEAP of %zu bytes.", h->size);
return GDK_FAIL;
}
+ GDKfree(nme);
h->newstorage = h->storage;
if (h->farmid == 1) {
QryCtx *qc = MT_thread_get_qry_ctx();
diff --git a/gdk/gdk_join.c b/gdk/gdk_join.c
--- a/gdk/gdk_join.c
+++ b/gdk/gdk_join.c
@@ -3061,7 +3061,7 @@ hashjoin(BAT **r1p, BAT **r2p, BAT *l, B
/* Count the number of unique values for the first half and the complete
* set (the sample s of b) and return the two values in *cnt1 and
* *cnt2. In case of error, both values are 0. */
-static void
+static gdk_return
count_unique(BAT *b, BAT *s, BUN *cnt1, BUN *cnt2)
{
struct canditer ci;
@@ -3087,7 +3087,7 @@ count_unique(BAT *b, BAT *s, BUN *cnt1,
/* trivial: already unique */
*cnt1 = half;
*cnt2 = ci.ncand;
- return;
+ return GDK_SUCCEED;
}
(void) BATordered(b);
@@ -3098,7 +3098,7 @@ count_unique(BAT *b, BAT *s, BUN *cnt1,
/* trivial: all values are the same */
*cnt1 = *cnt2 = 1;
bat_iterator_end(&bi);
- return;
+ return GDK_SUCCEED;
}
assert(bi.type != TYPE_void);
@@ -3159,7 +3159,7 @@ count_unique(BAT *b, BAT *s, BUN *cnt1,
seen = GDKzalloc((65536 / 32) * sizeof(seen[0]));
if (seen == NULL) {
bat_iterator_end(&bi);
- return;
+ return GDK_FAIL;
}
for (i = 0; i < ci.ncand; i++) {
if (i == half) {
@@ -3203,7 +3203,7 @@ count_unique(BAT *b, BAT *s, BUN *cnt1,
HEAPfree(&hs.heaplink, true);
HEAPfree(&hs.heapbckt, true);
bat_iterator_end(&bi);
- return;
+ return GDK_FAIL;
}
for (i = 0; i < ci.ncand; i++) {
if (i == half)
@@ -3236,7 +3236,7 @@ count_unique(BAT *b, BAT *s, BUN *cnt1,
ALGOBATPAR(b), ALGOOPTBATPAR(s),
*cnt1, *cnt2, algomsg, GDKusec() - t0);
- return;
+ return GDK_SUCCEED;
}
static double
@@ -3261,12 +3261,19 @@ guess_uniques(BAT *b, struct canditer *c
s1 = BATsample_with_seed(b, 1000, (uint64_t) GDKusec() *
(uint64_t) b->batCacheid);
} else {
BAT *s2 = BATsample_with_seed(ci->s, 1000, (uint64_t) GDKusec()
* (uint64_t) b->batCacheid);
+ if (s2 == NULL)
+ return -1;
s1 = BATproject(s2, ci->s);
BBPreclaim(s2);
}
+ if (s1 == NULL)
+ return -1;
BUN n2 = BATcount(s1);
BUN n1 = n2 / 2;
- count_unique(b, s1, &cnt1, &cnt2);
+ if (count_unique(b, s1, &cnt1, &cnt2) != GDK_SUCCEED) {
+ BBPreclaim(s1);
+ return -1;
+ }
BBPreclaim(s1);
double A = (double) (cnt2 - cnt1) / (n2 - n1);
@@ -3349,8 +3356,11 @@ joincost(BAT *r, struct canditer *lci, s
MT_lock_set(&r->theaplock);
double unique_est = r->tunique_est;
MT_lock_unset(&r->theaplock);
- if (unique_est == 0)
+ if (unique_est == 0) {
unique_est = guess_uniques(r, &(struct
canditer){.tpe=cand_dense, .ncand=BATcount(r)});
+ if (unique_est < 0)
+ return -1;
+ }
/* we have an estimate of the number of unique
* values, assume some collisions */
rcost *= 1.1 * ((double) cnt / unique_est);
@@ -3379,8 +3389,11 @@ joincost(BAT *r, struct canditer *lci, s
MT_lock_set(&r->theaplock);
double unique_est = r->tunique_est;
MT_lock_unset(&r->theaplock);
- if (unique_est == 0)
+ if (unique_est == 0) {
unique_est = guess_uniques(r, rci);
+ if (unique_est < 0)
+ return -1;
+ }
/* we have an estimate of the number of unique
* values, assume some chains */
rccost = 1.1 * ((double) cnt / unique_est);
@@ -3901,6 +3914,10 @@ leftjoin(BAT **r1p, BAT **r2p, BAT *l, B
}
}
rcost = joincost(r, &lci, &rci, &rhash, &prhash, &rcand);
+ if (rcost < 0) {
+ rc = GDK_FAIL;
+ goto doreturn;
+ }
if (!nil_on_miss && !only_misses && !not_in && !max_one && !min_one) {
/* maybe do a hash join on the swapped operands; if we
@@ -3910,6 +3927,10 @@ leftjoin(BAT **r1p, BAT **r2p, BAT *l, B
double lcost;
lcost = joincost(l, &rci, &lci, &lhash, &plhash, &lcand);
+ if (lcost < 0) {
+ rc = GDK_FAIL;
+ goto doreturn;
+ }
if (semi)
lcost += rci.ncand; /* cost of BATunique(r) */
/* add cost of sorting; obviously we don't know the
@@ -4241,6 +4262,10 @@ BATjoin(BAT **r1p, BAT **r2p, BAT *l, BA
lcost = joincost(l, &rci, &lci, &lhash, &plhash, &lcand);
rcost = joincost(r, &lci, &rci, &rhash, &prhash, &rcand);
+ if (lcost < 0 || rcost < 0) {
+ rc = GDK_FAIL;
+ goto doreturn;
+ }
/* if the cost of doing searches on l is lower than the cost
* of doing searches on r, we swap */
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -738,8 +738,9 @@ log_read_destroy(logger *lg, trans *tr,
tr->changes[tr->nr].type = LOG_DESTROY;
tr->changes[tr->nr].cid = id;
tr->nr++;
+ return LOG_OK;
}
- return LOG_OK;
+ return LOG_ERR;
}
static gdk_return
@@ -774,9 +775,9 @@ log_read_create(logger *lg, trans *tr, l
tr->changes[tr->nr].tt = tpe;
tr->changes[tr->nr].cid = id;
tr->nr++;
+ return LOG_OK;
}
-
- return LOG_OK;
+ return LOG_ERR;
}
static gdk_return
@@ -1261,7 +1262,7 @@ log_readlog(logger *lg, char *filename,
}
gdk_return res = log_open_input(lg, filename, filemissing);
- if (!lg->input_log)
+ if (!lg->input_log || res != GDK_SUCCEED)
return res;
int fd;
if ((fd = getFileNo(lg->input_log)) < 0 || fstat(fd, &sb) < 0) {
@@ -1303,8 +1304,8 @@ log_readlog(logger *lg, char *filename,
/* we cannot distinguish errors from incomplete transactions
* (even if we would log aborts in the logs). So we simply
* abort and move to the next log file */
- //return err == LOG_ERR ? GDK_FAIL : GDK_SUCCEED;
- return GDK_SUCCEED;
+ return err == LOG_ERR ? GDK_FAIL : GDK_SUCCEED;
+ //return GDK_SUCCEED;
}
/*
@@ -2674,7 +2675,7 @@ log_bat_transient(logger *lg, log_id id)
BAT *b = BBPquickdesc(bid);
assert(b);
lg->end += BATcount(b);
- gdk_return r = log_del_bat(lg, bid);
+ gdk_return r = log_del_bat(lg, bid);
log_unlock(lg);
if (r != GDK_SUCCEED)
(void) ATOMIC_DEC(&lg->refcount);
@@ -2863,7 +2864,8 @@ log_tend(logger *lg)
return result;
}
static int
-request_number_flush_queue(logger *lg) {
+request_number_flush_queue(logger *lg)
+{
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]