Changeset: 090b57f9574b for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/090b57f9574b Modified Files: gdk/gdk_logger.c sql/backends/monet5/sql_upgrades.c sql/storage/bat/bat_storage.c Branch: Jun2023 Log Message:
When BATdescriptor returns NULL it's almost invariably an error. So return an error, don't just do nothing. diffs (164 lines): diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c --- a/gdk/gdk_logger.c +++ b/gdk/gdk_logger.c @@ -2085,6 +2085,12 @@ log_load(const char *fn, const char *log lg->seqs_val = BATdescriptor(BBPindex(bak)); strconcat_len(bak, sizeof(bak), fn, "_dseqs", NULL); lg->dseqs = BATdescriptor(BBPindex(bak)); + if (lg->seqs_id == NULL || + lg->seqs_val == NULL || + lg->dseqs == NULL) { + GDKerror("Logger_new: cannot load seqs bats"); + goto error; + } } else { lg->seqs_id = logbat_new(TYPE_int, 1, PERSISTENT); lg->seqs_val = logbat_new(TYPE_lng, 1, PERSISTENT); diff --git a/sql/backends/monet5/sql_upgrades.c b/sql/backends/monet5/sql_upgrades.c --- a/sql/backends/monet5/sql_upgrades.c +++ b/sql/backends/monet5/sql_upgrades.c @@ -190,26 +190,28 @@ check_sys_tables(Client c, mvc *m, sql_s if (err) return err; BAT *b; - if ((b = BATdescriptor(output->cols[0].b)) != NULL) { - if (BATcount(b) > 0) { - BATiter bi = bat_iterator(b); - needsystabfix = * (int *) BUNtloc(bi, 0) != id; - bat_iterator_end(&bi); - } - BBPunfix(b->batCacheid); + b = BATdescriptor(output->cols[0].b); + res_table_destroy(output); + if (b == NULL) + throw(SQL, "sql.catalog", SQLSTATE(HY013) MAL_MALLOC_FAIL); + if (BATcount(b) > 0) { + BATiter bi = bat_iterator(b); + needsystabfix = * (int *) BUNtloc(bi, 0) != id; + bat_iterator_end(&bi); } - res_table_destroy(output); + BBPunfix(b->batCacheid); if (i == 0 && !needsystabfix) { snprintf(buf, sizeof(buf), "select a.type from sys.functions f join sys.args a on f.id = a.func_id where f.name = 'quarter' and f.schema_id = 2000 and a.inout = 0 and a.type = 'int';\n"); err = SQLstatementIntern(c, buf, "update", true, false, &output); if (err) return err; - if ((b = BATdescriptor(output->cols[0].b)) != NULL) { - needsystabfix = BATcount(b) > 0; - BBPunfix(b->batCacheid); - } + b = BATdescriptor(output->cols[0].b); res_table_destroy(output); + if (b == NULL) + throw(SQL, "sql.catalog", SQLSTATE(HY013) MAL_MALLOC_FAIL); + needsystabfix = BATcount(b) > 0; + BBPunfix(b->batCacheid); } if (needsystabfix) return sql_fix_system_tables(c, m); @@ -1703,6 +1705,11 @@ sql_update_jun2020_bam(Client c, mvc *m) return err; } b = BATdescriptor(output->cols[0].b); + res_table_destroy(output); + if (b == NULL) { + GDKfree(buf); + throw(SQL, "sql.catalog", SQLSTATE(HY013) MAL_MALLOC_FAIL); + } pos = 0; pos += snprintf(buf + pos, bufsize - pos, "update sys.schemas set system = false where name = 'bam';\n" @@ -1718,20 +1725,17 @@ sql_update_jun2020_bam(Client c, mvc *m) "drop function bam.seq_char cascade;\n" "drop procedure bam.sam_export cascade;\n" "drop procedure bam.bam_export cascade;\n"); - if (b) { - if (BATcount(b) > 0 && *(lng *) Tloc(b, 0) == 0) { - /* tables in bam schema are empty: drop them */ - pos += snprintf(buf + pos, bufsize - pos, - "drop table bam.sq cascade;\n" - "drop table bam.rg cascade;\n" - "drop table bam.pg cascade;\n" - "drop table bam.export cascade;\n" - "drop table bam.files cascade;\n" - "drop schema bam cascade;\n"); - } - BBPunfix(b->batCacheid); + if (BATcount(b) > 0 && *(lng *) Tloc(b, 0) == 0) { + /* tables in bam schema are empty: drop them */ + pos += snprintf(buf + pos, bufsize - pos, + "drop table bam.sq cascade;\n" + "drop table bam.rg cascade;\n" + "drop table bam.pg cascade;\n" + "drop table bam.export cascade;\n" + "drop table bam.files cascade;\n" + "drop schema bam cascade;\n"); } - res_table_destroy(output); + BBPunfix(b->batCacheid); assert(pos < bufsize); @@ -1943,6 +1947,8 @@ sql_update_oscar(Client c, mvc *sql) err = SQLstatementIntern(c, buf, "update", true, false, NULL); } BBPunfix(b->batCacheid); + } else { + err = createException(SQL, "sql.catalog", SQLSTATE(HY013) MAL_MALLOC_FAIL); } res_table_destroy(output); GDKfree(buf); @@ -2080,6 +2086,8 @@ sql_update_oct2020(Client c, mvc *sql) goto bailout; err = sql_update_storagemodel(c, sql, true); /* because of day interval addition, we have to recreate the storagmodel views */ } + } else { + err = createException(SQL, "sql.catalog", SQLSTATE(HY013) MAL_MALLOC_FAIL); } bailout: @@ -3148,6 +3156,8 @@ sql_update_jul2021(Client c, mvc *sql) fflush(stdout); err = SQLstatementIntern(c, buf, "update", true, false, NULL); } + } else { + err = createException(SQL, "sql.catalog", SQLSTATE(HY013) MAL_MALLOC_FAIL); } bailout: @@ -3229,6 +3239,8 @@ sql_update_jul2021_5(Client c, mvc *sql) err = SQLstatementIntern(c, buf, "update", true, false, NULL); } BBPunfix(b->batCacheid); + } else { + err = createException(SQL, "sql.catalog", SQLSTATE(HY013) MAL_MALLOC_FAIL); } res_table_destroy(output); } diff --git a/sql/storage/bat/bat_storage.c b/sql/storage/bat/bat_storage.c --- a/sql/storage/bat/bat_storage.c +++ b/sql/storage/bat/bat_storage.c @@ -1614,13 +1614,15 @@ cs_update_bat( sql_trans *tr, sql_delta if (b == NULL) { res = LOG_ERR; - } else if (BATcount(b)==0) { - if (BATappend(b, updates, NULL, true) != GDK_SUCCEED) /* alter add column */ + } else { + if (BATcount(b)==0) { + if (BATappend(b, updates, NULL, true) != GDK_SUCCEED) /* alter add column */ + res = LOG_ERR; + } else if (BATreplace(b, tids, updates, true) != GDK_SUCCEED) res = LOG_ERR; - } else if (BATreplace(b, tids, updates, true) != GDK_SUCCEED) - res = LOG_ERR; - BBPcold(b->batCacheid); - bat_destroy(b); + BBPcold(b->batCacheid); + bat_destroy(b); + } } unlock_table(tr->store, t->base.id); if (otids != tids) _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org