MonetDB: nospare - more cleanup

2021-01-28 Thread Niels Nes
Changeset: c84fc0202fda for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c84fc0202fda
Modified Files:
sql/common/sql_list.c
sql/storage/bat/bat_storage.c
sql/storage/sql_storage.h
sql/storage/store.c
Branch: nospare
Log Message:

more cleanup


diffs (184 lines):

diff --git a/sql/common/sql_list.c b/sql/common/sql_list.c
--- a/sql/common/sql_list.c
+++ b/sql/common/sql_list.c
@@ -49,18 +49,20 @@ sa_list(sql_allocator *sa)
return list_init(l, sa, NULL);
 }
 
+/*
 static void
 _free(void *dummy, void *data)
 {
(void)dummy;
GDKfree(data);
 }
+*/
 
 list *
 sa_list_append(sql_allocator *sa, list *l, void *data)
 {
if (!l)
-   l = SA_LIST(sa, _free);
+   l = SA_LIST(sa, NULL);
return list_append(l, data);
 }
 
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
@@ -2798,7 +2798,15 @@ tc_gc_col( sql_store Store, sql_change *
 #endif
if (c->data != change->data) /* data is freed by commit */
return 1;
-   return LOG_OK;
+   sql_delta *d = (sql_delta*)change->data;
+   if (d->next) {
+   if (d->ts > oldest)
+   return LOG_OK; /* cannot cleanup yet */
+
+   destroy_delta(d->next);
+   d->next = NULL;
+   }
+   return 1;
 }
 
 static int
@@ -2828,7 +2836,15 @@ tc_gc_idx( sql_store Store, sql_change *
 #endif
if (i->data != change->data) /* data is freed by commit */
return 1;
-   return LOG_OK;
+   sql_delta *d = (sql_delta*)change->data;
+   if (d->next) {
+   if (d->ts > oldest)
+   return LOG_OK; /* cannot cleanup yet */
+
+   destroy_delta(d->next);
+   d->next = NULL;
+   }
+   return 1;
 }
 
 static int
@@ -2858,7 +2874,15 @@ tc_gc_del( sql_store Store, sql_change *
 #endif
if (t->data != change->data) /* data is freed by commit */
return 1;
-   return LOG_OK;
+   sql_dbat *d = (sql_dbat*)change->data;
+   if (d->next) {
+   if (d->ts > oldest)
+   return LOG_OK; /* cannot cleanup yet */
+
+   destroy_dbat(d->next);
+   d->next = NULL;
+   }
+   return 1;
 }
 
 void
diff --git a/sql/storage/sql_storage.h b/sql/storage/sql_storage.h
--- a/sql/storage/sql_storage.h
+++ b/sql/storage/sql_storage.h
@@ -475,6 +475,7 @@ typedef struct sqlstore {
int initialized;/* used during bootstrap only */
int debug;  /* debug mask */
store_type active_type;
+   list *changes;  /* pending changes too cleanup */
 
sql_allocator *sa;  /* for now a store allocator, needs a 
special version with free operations (with reuse) */
sqlid obj_id, prev_oid;
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -2146,6 +2146,22 @@ store_exit(sqlstore *store)
MT_lock_unset(>lock);
os_destroy(store->cat->objects, store);
os_destroy(store->cat->schemas, store);
+   if (store->changes) {
+   /*
+   ulng oldest = store_timestamp(store);
+   if (!list_empty(store->changes))
+   printf("pending changes %d\n", 
list_length(store->changes));
+   for(node *n=store->changes->h; n; n = n->next) {
+   sql_change *c = n->data;
+
+   if (c->cleanup && !c->cleanup(store, c, oldest, 
oldest))
+   assert(0);
+   else
+   _DELETE(c);
+   }
+   */
+   list_destroy(store->changes);
+   }
_DELETE(store->cat);
sequences_exit();
MT_lock_set(>lock);
@@ -3397,7 +3413,7 @@ sql_trans_rollback(sql_trans *tr)
}
}
if (tr->changes) {
-   /* revert this */
+   /* revert the change list */
list *nl = SA_LIST(tr->sa, (fdestroy) NULL);
for(node *n=tr->changes->h; n; n = n->next)
list_prepend(nl, n->data);
@@ -3410,12 +3426,25 @@ sql_trans_rollback(sql_trans *tr)
if (c->commit)
c->commit(tr, c, commit_ts, oldest);
}
-
+   if (!list_empty(store->changes)) { /* lets first cleanup old 
stuff */
+   for(node *n=store->changes->h; n; ) {
+   node *next = n->next;
+   sql_change *c = n->data;
+
+

MonetDB: nospare - more cleanup

2021-01-26 Thread Niels Nes
Changeset: 48de9359d1c7 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=48de9359d1c7
Modified Files:
sql/storage/store.c
Branch: nospare
Log Message:

more cleanup


diffs (11 lines):

diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -2139,6 +2139,7 @@ store_exit(sqlstore *store)
MT_lock_unset(>lock);
os_destroy(store->cat->objects, store);
os_destroy(store->cat->schemas, store);
+   _DELETE(store->cat);
sequences_exit();
MT_lock_set(>lock);
}
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: nospare - more cleanup

2021-01-26 Thread Niels Nes
Changeset: d05b9dcd1f88 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d05b9dcd1f88
Modified Files:
sql/common/sql_types.c
sql/include/sql_catalog.h
sql/server/sql_mvc.c
sql/storage/objectset.c
sql/storage/store.c
Branch: nospare
Log Message:

more cleanup


diffs (194 lines):

diff --git a/sql/common/sql_types.c b/sql/common/sql_types.c
--- a/sql/common/sql_types.c
+++ b/sql/common/sql_types.c
@@ -612,7 +612,7 @@ static sql_func *
 sql_create_func_(sql_allocator *sa, const char *name, const char *mod, const 
char *imp, sql_ftype type, bit semantics, bit side_effect,
 int fix_scale, unsigned int res_scale, 
sql_type *res, int nargs, va_list valist)
 {
-   list *ops = sa_list(sa);
+   list *ops = SA_LIST(sa, (fdestroy) _destroy);
sql_arg *fres = NULL;
sql_func *t = SA_ZNEW(sa, sql_func);
 
@@ -631,7 +631,7 @@ sql_create_func_(sql_allocator *sa, cons
if (fres) {
if (res_scale)
fres->type.scale = res_scale;
-   t->res = list_append(sa_list(sa), fres);
+   t->res = list_append(SA_LIST(sa, (fdestroy) _destroy), 
fres);
} else
t->res = NULL;
t->nr = list_length(funcs);
diff --git a/sql/include/sql_catalog.h b/sql/include/sql_catalog.h
--- a/sql/include/sql_catalog.h
+++ b/sql/include/sql_catalog.h
@@ -840,4 +840,6 @@ extract_schema_and_sequence_name(sql_all
}
 }
 
+extern void arg_destroy(sql_store store, sql_arg *a);
+
 #endif /* SQL_CATALOG_H */
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
@@ -863,7 +863,6 @@ mvc_destroy(mvc *m)
(void)sql_trans_end(m->session, 0);
while (tr->parent)
tr = sql_trans_destroy(tr);
-   m->session->tr = NULL;
}
sql_session_destroy(m->session);
store_unlock(m->store);
diff --git a/sql/storage/objectset.c b/sql/storage/objectset.c
--- a/sql/storage/objectset.c
+++ b/sql/storage/objectset.c
@@ -582,7 +582,8 @@ os_destroy(objectset *os, sql_store stor
return;
if (os->destroy) {
for(versionhead  *n=os->name_based_h; n; n=n->next) {
-   os->destroy(n->ov, store);
+   /* TODO destroy objectversion */
+   os->destroy(store, n->ov->b);
}
}
versionhead  *n = os->name_based_h;
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -95,16 +95,25 @@ type_destroy(sqlstore *store, sql_type *
_DELETE(t);
 }
 
+void
+arg_destroy(sql_store store, sql_arg *a)
+{
+   (void)store;
+   _DELETE(a);
+}
+
 static void
 func_destroy(sqlstore *store, sql_func *f)
 {
-   (void)store;
assert(f->base.refcnt > 0);
if (--(f->base.refcnt) > 0)
return;
+   if (f->res)
+   list_destroy2(f->res, store);
list_destroy2(f->ops, store);
_DELETE(f->imp);
_DELETE(f->mod);
+   _DELETE(f->query);
_DELETE(f->base.name);
_DELETE(f);
 }
@@ -912,7 +921,7 @@ load_func(sql_trans *tr, sql_schema *s, 
 
TRC_DEBUG(SQL_STORE, "Load function: %s\n", t->base.name);
 
-   t->ops = list_new(tr->sa, (fdestroy)NULL);
+   t->ops = list_new(tr->sa, (fdestroy) _destroy);
if (rs) {
for (rid = store->table_api.subrids_next(rs); !is_oid_nil(rid); 
rid = store->table_api.subrids_next(rs)) {
sql_arg *a = load_arg(tr, t, rid);
@@ -921,7 +930,7 @@ load_func(sql_trans *tr, sql_schema *s, 
return NULL;
if (a->inout == ARG_OUT) {
if (!t->res)
-   t->res = SA_LIST(tr->sa, (fdestroy) 
NULL);
+   t->res = list_new(tr->sa, (fdestroy) 
_destroy);
list_append(t->res, a);
} else {
list_append(t->ops, a);
@@ -1684,9 +1693,9 @@ store_load(sqlstore *store, sql_allocato
if (!sequences_init())
return NULL;
tr = sql_trans_create(store, NULL, NULL);
-   tr->store = store;
if (!tr)
return NULL;
+   tr->store = store;
 
/* for now use malloc and free */
store->active = list_create(NULL);
@@ -1695,7 +1704,6 @@ store_load(sqlstore *store, sql_allocato
/* cannot initialize database in readonly mode */
if (store->readonly)
return NULL;
-   tr = sql_trans_create(store, NULL, NULL);
if (!tr) {
TRC_CRITICAL(SQL_STORE, "Failed to start a transaction 
while loading the storage\n");
   

MonetDB: nospare - more cleanup

2021-01-25 Thread Niels Nes
Changeset: f4f95cd615d2 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f4f95cd615d2
Modified Files:
sql/storage/store.c
Branch: nospare
Log Message:

more cleanup


diffs (147 lines):

diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -90,11 +90,9 @@ type_destroy(sqlstore *store, sql_type *
assert(t->base.refcnt > 0);
if (--(t->base.refcnt) > 0)
return;
-   /*
_DELETE(t->sqlname);
_DELETE(t->base.name);
_DELETE(t);
-*/
 }
 
 static void
@@ -104,13 +102,11 @@ func_destroy(sqlstore *store, sql_func *
assert(f->base.refcnt > 0);
if (--(f->base.refcnt) > 0)
return;
-   /*
-   list_destroy(f->ops, store);
+   list_destroy2(f->ops, store);
_DELETE(f->imp);
_DELETE(f->mod);
_DELETE(f->base.name);
_DELETE(f);
-*/
 }
 
 static void
@@ -120,10 +116,8 @@ seq_destroy(sqlstore *store, sql_sequenc
assert(s->base.refcnt > 0);
if (--(s->base.refcnt) > 0)
return;
-   /*
_DELETE(s->base.name);
_DELETE(s);
-*/
 }
 
 static void
@@ -132,17 +126,12 @@ key_destroy(sqlstore *store, sql_key *k)
assert(k->base.refcnt > 0);
if (--(k->base.refcnt) > 0)
return;
-   /* remove key from schema */
-   list_destroy(k->columns);
+   list_destroy2(k->columns, store);
k->columns = NULL;
if ((k->type == pkey) && (k->t->pkey == (sql_ukey *) k))
k->t->pkey = NULL;
-   (void)store;
-   /*
-   list_destroy(k->columns);
_DELETE(k->base.name);
_DELETE(k);
-*/
 }
 
 static void
@@ -151,17 +140,13 @@ idx_destroy(sqlstore *store, sql_idx * i
assert(i->base.refcnt > 0);
if (--(i->base.refcnt) > 0)
return;
-   /* remove idx from schema */
-   list_destroy(i->columns);
+   list_destroy2(i->columns, store);
i->columns = NULL;
 
if (isTable(i->t))
store->storage_api.destroy_idx(store, i);
-   /*
-   list_destroy(i->columns);
_DELETE(i->base.name);
_DELETE(i);
-*/
 }
 
 static void
@@ -172,19 +157,15 @@ trigger_destroy(sqlstore *store, sql_tri
return;
/* remove trigger from schema */
if (t->columns) {
-   list_destroy(t->columns);
+   list_destroy2(t->columns, store);
t->columns = NULL;
}
-   (void)store;
-   /*
-   list_destroy(t->columns);
_DELETE(t->old_name);
_DELETE(t->new_name);
_DELETE(t->condition);
_DELETE(t->statement);
_DELETE(t->base.name);
_DELETE(t);
-*/
 }
 
 static void
@@ -195,32 +176,29 @@ column_destroy(sqlstore *store, sql_colu
return;
if (isTable(c->t))
store->storage_api.destroy_col(store, c);
-   /*
_DELETE(c->def);
_DELETE(c->base.name);
_DELETE(c);
-*/
 }
 
 static void
 table_destroy(sqlstore *store, sql_table *t)
 {
-   (void)store;
assert(t->base.refcnt > 0);
if (--(t->base.refcnt) > 0)
return;
+   if (isTable(t))
+   store->storage_api.destroy_del(store, t);
/* cleanup its parts */
cs_destroy(>members, store);
cs_destroy(>idxs, store);
cs_destroy(>keys, store);
cs_destroy(>triggers, store);
cs_destroy(>columns, store);
-   /*
-   _DELETE(t->part);
+   //_DELETE(t->part);
_DELETE(t->query);
_DELETE(t->base.name);
_DELETE(t);
-*/
 }
 
 static void
@@ -238,10 +216,8 @@ schema_destroy(sqlstore *store, sql_sche
os_destroy(s->tables, store);
os_destroy(s->funcs, store);
os_destroy(s->types, store);
-   /*
_DELETE(s->base.name);
_DELETE(s);
-*/
 }
 
 static void
___
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


MonetDB: nospare - more cleanup

2021-01-04 Thread Niels Nes
Changeset: 8ff7cb28d317 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8ff7cb28d317
Modified Files:
sql/common/sql_list.c
sql/include/sql_catalog.h
sql/include/sql_list.h
sql/storage/bat/bat_storage.c
sql/storage/bat/bat_utils.c
sql/storage/sql_storage.h
sql/storage/store.c
Branch: nospare
Log Message:

more cleanup
now handles drop table


diffs (truncated from 1070 to 300 lines):

diff --git a/sql/common/sql_list.c b/sql/common/sql_list.c
--- a/sql/common/sql_list.c
+++ b/sql/common/sql_list.c
@@ -50,6 +50,14 @@ sa_list(sql_allocator *sa)
 }
 
 list *
+sa_list_append(sql_allocator *sa, list *l, void *data)
+{
+   if (!l)
+   l = sa_list(sa);
+   return list_append(l, data);
+}
+
+list *
 list_new(sql_allocator *sa, fdestroy destroy)
 {
list *l = (sa)?SA_NEW(sa, list):MNEW(list);
@@ -760,6 +768,17 @@ list_flaten(list *l)
 }
 
 void
+list_update_data(list *l, node *n, void *data)
+{
+   MT_lock_set(>ht_lock);
+   hash_delete(l->ht, n->data);
+   n->data = data;
+   int nkey = l->ht->key(data);
+   hash_add(l->ht, nkey, data);
+   MT_lock_unset(>ht_lock);
+}
+
+void
 list_hash_delete(list *l, void *data, fcmp cmp)
 {
if (l && data) {
diff --git a/sql/include/sql_catalog.h b/sql/include/sql_catalog.h
--- a/sql/include/sql_catalog.h
+++ b/sql/include/sql_catalog.h
@@ -197,13 +197,14 @@ typedef enum commit_action_t {
 typedef int sqlid;
 
 typedef struct sql_base {
-   int allocated;
+   int deleted;
int flags;
int refcnt;
sqlid id;
char *name;
ulng ts;/* transaction start timestamp 
*/
-   struct sql_base *next;  /* older versions */
+   struct sql_base *older; /* older versions */
+   struct sql_base *newer; /* newer version */
 } sql_base;
 
 #define newFlagSet(x) ((x & TR_NEW) == TR_NEW)
@@ -267,14 +268,15 @@ typedef struct sql_catalog {
 typedef struct sql_trans {
char *name;
 
-   ulng ts;/* transaction start timestamp */
-   ulng tid;   /* transaction id */
+   ulng ts;/* transaction start timestamp */
+   ulng tid;   /* transaction id */
 
sql_store store;/* keep link into the global store */
-   list *changes;  /* list of changes */
+   list *changes;  /* list of changes */
 
-   int active; /* active transaction */
-   int status; /* status of the last query */
+   int active; /* is active transaction */
+   int status; /* status of the last query */
+
list *dropped;  /* protection against recursive cascade action*/
list *moved_tables;
 
@@ -723,7 +725,7 @@ typedef struct sql_session {
 } sql_session;
 
 extern void schema_destroy(sql_schema *s);
-extern void table_destroy(sql_table *t);
+//extern void table_destroy(sql_table *t);
 extern void column_destroy(sql_column *c);
 extern void key_destroy(sql_key *k);
 extern void idx_destroy(sql_idx * i);
diff --git a/sql/include/sql_list.h b/sql/include/sql_list.h
--- a/sql/include/sql_list.h
+++ b/sql/include/sql_list.h
@@ -38,6 +38,8 @@ extern list *list_create(fdestroy destro
 sql_export list *sa_list(sql_allocator *sa);
 extern list *list_new(sql_allocator *sa, fdestroy destroy);
 
+extern list *sa_list_append( sql_allocator *sa, list *l, void *data);
+
 extern void list_destroy(list *l);
 sql_export int list_length(list *l);
 extern int list_empty(list *l);
@@ -101,5 +103,6 @@ extern list *list_flaten(list *l);
 extern void list_hash_delete(list *l, void *data, fcmp cmp);
 extern void* list_hash_add(list *l, void *data, fcmp cmp);
 extern void list_hash_clear(list *l);
+extern void list_update_data(list *l, node *n, void *data);
 
 #endif /* LIST_H */
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
@@ -19,23 +19,9 @@
 static int log_update_col( sql_trans *tr, sql_change *c, ulng commit_ts, ulng 
oldest);
 static int log_update_idx( sql_trans *tr, sql_change *c, ulng commit_ts, ulng 
oldest);
 static int log_update_del( sql_trans *tr, sql_change *c, ulng commit_ts, ulng 
oldest);
-static int log_create_col(sql_trans *tr, sql_change *c, ulng commit_ts, ulng 
oldest);
-static int log_create_idx(sql_trans *tr, sql_change *c, ulng commit_ts, ulng 
oldest);
-static int log_create_del(sql_trans *tr, sql_change *c, ulng commit_ts, ulng 
oldest);
-static int log_destroy_col(sql_trans *tr, sql_change *change, ulng commit_ts, 
ulng oldest);
-static int log_destroy_idx(sql_trans *tr, sql_change *change, ulng commit_ts, 
ulng oldest);
-static int log_destroy_del(sql_trans *tr, sql_change *change, ulng commit_ts, 
ulng oldest);
 
 static int tr_merge_delta( sql_trans *tr, sql_delta *obat);
 
-static list *