[prev in list] [next in list] [prev in thread] [next in thread]
List: monetdb-checkins
Subject: MonetDB: Jan2022 - Fixing several drop cascade leaks and cleanup...
From: Pedro_Ferreira <commits+pedro.ferreira=monetdbsolutions.com () mon
Date: 2022-01-28 20:45:04
Message-ID: hg.b8005c77c08a.1643402704.-8786352299810849262 () dev ! monetdb ! org
[Download RAW message or body]
Changeset: b8005c77c08a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/b8005c77c08a
Modified Files:
sql/server/sql_mvc.c
sql/storage/store.c
Branch: Jan2022
Log Message:
Fixing several drop cascade leaks and cleanup. Always clean the 'dropped' at the end \
of the transaction (it could have failed at some point)
diffs (166 lines):
diff --git a/sql/server/sql_mvc.c b/sql/server/sql_mvc.c
--- a/sql/server/sql_mvc.c
+++ b/sql/server/sql_mvc.c
@@ -1076,7 +1076,7 @@ mvc_drop_type(mvc *m, sql_schema *s, sql
{
TRC_DEBUG(SQL_TRANS, "Drop type: %s %s\n", s->base.name, t->base.name);
if (t)
- return sql_trans_drop_type(m->session->tr, s, t->base.id, drop_action);
+ return sql_trans_drop_type(m->session->tr, s, t->base.id, drop_action ? \
DROP_CASCADE_START : DROP_RESTRICT); return 0;
}
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -3707,6 +3707,8 @@ sql_trans_destroy(sql_trans *tr)
}
store_unlock(store);
MT_lock_destroy(&tr->lock);
+ if (!list_empty(tr->dropped))
+ list_destroy(tr->dropped);
_DELETE(tr);
return res;
}
@@ -4833,10 +4835,31 @@ sql_trans_drop_type(sql_trans *tr, sql_s
sql_type *t = sql_trans_find_type(tr, s, id);
int res = LOG_OK;
+ if (drop_action == DROP_CASCADE_START || drop_action == DROP_CASCADE) {
+ sqlid* local_id = MNEW(sqlid);
+ if (!local_id)
+ return -1;
+
+ if (!tr->dropped) {
+ tr->dropped = list_create((fdestroy) &id_destroy);
+ if (!tr->dropped) {
+ _DELETE(local_id);
+ return -1;
+ }
+ }
+ *local_id = t->base.id;
+ list_append(tr->dropped, local_id);
+ }
+
if ((res = sys_drop_type(tr, t, drop_action)))
return res;
if ((res = os_del(s->types, tr, t->base.name, dup_base(&t->base))))
return res;
+
+ if (drop_action == DROP_CASCADE_START && tr->dropped) {
+ list_destroy(tr->dropped);
+ tr->dropped = NULL;
+ }
return res;
}
@@ -4979,22 +5002,17 @@ build_drop_func_list_item(sql_trans *tr,
int
sql_trans_drop_all_func(sql_trans *tr, sql_schema *s, list *list_func, int \
drop_action) {
- node *n = NULL;
- sql_func *func = NULL;
- list* to_drop = NULL;
+ list *to_drop = NULL;
int res = LOG_OK;
(void) drop_action;
-
- if (!tr->dropped) {
- tr->dropped = list_create((fdestroy) &id_destroy);
- if (!tr->dropped)
- return -1;
- }
- for (n = list_func->h; n ; n = n->next ) {
- func = (sql_func *) n->data;
-
- if (! list_find_id(tr->dropped, func->base.id)){
+ if (!tr->dropped && !(tr->dropped = list_create((fdestroy) &id_destroy)))
+ return -1;
+
+ for (node *n = list_func->h; n ; n = n->next ) {
+ sql_func *func = (sql_func *) n->data;
+
+ if (!list_find_id(tr->dropped, func->base.id)) {
sqlid *local_id = MNEW(sqlid);
if (!local_id) {
list_destroy(tr->dropped);
@@ -5003,33 +5021,32 @@ sql_trans_drop_all_func(sql_trans *tr, s
list_destroy(to_drop);
return -1;
}
- if (!to_drop) {
- to_drop = list_create(NULL);
- if (!to_drop) {
- list_destroy(tr->dropped);
- return -1;
- }
+ if (!to_drop && !(to_drop = list_create(NULL))) {
+ list_destroy(tr->dropped);
+ tr->dropped = NULL;
+ return -1;
}
*local_id = func->base.id;
list_append(tr->dropped, local_id);
list_append(to_drop, func);
- //sql_trans_drop_func(tr, s, func->base.id, drop_action ? DROP_CASCADE : \
DROP_RESTRICT); }
}
if (to_drop) {
- for (n = to_drop->h; n ; n = n->next ) {
- func = (sql_func *) n->data;
- if ((res = build_drop_func_list_item(tr, s, func->base.id)))
+ for (node *n = to_drop->h; n ; n = n->next ) {
+ sql_func *func = (sql_func *) n->data;
+ if ((res = build_drop_func_list_item(tr, s, func->base.id))) {
+ list_destroy(tr->dropped);
+ tr->dropped = NULL;
+ list_destroy(to_drop);
return res;
+ }
}
list_destroy(to_drop);
}
- if ( tr->dropped) {
- list_destroy(tr->dropped);
- tr->dropped = NULL;
- }
+ list_destroy(tr->dropped);
+ tr->dropped = NULL;
return res;
}
@@ -6806,10 +6823,31 @@ sql_trans_drop_sequence(sql_trans *tr, s
{
int res = LOG_OK;
+ if (drop_action == DROP_CASCADE_START || drop_action == DROP_CASCADE) {
+ sqlid* local_id = MNEW(sqlid);
+ if (!local_id)
+ return -1;
+
+ if (!tr->dropped) {
+ tr->dropped = list_create((fdestroy) &id_destroy);
+ if (!tr->dropped) {
+ _DELETE(local_id);
+ return -1;
+ }
+ }
+ *local_id = seq->base.id;
+ list_append(tr->dropped, local_id);
+ }
+
if ((res = sys_drop_sequence(tr, seq, drop_action)))
return res;
if ((res = os_del(s->seqs, tr, seq->base.name, dup_base(&seq->base))))
return res;
+
+ if (drop_action == DROP_CASCADE_START && tr->dropped) {
+ list_destroy(tr->dropped);
+ tr->dropped = NULL;
+ }
return res;
}
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic