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(&store->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(&store->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;
+
+ if (c->cleanup && c->cleanup(store, c,
commit_ts, oldest)) {
+ list_remove_node(store->changes, store,
n);
+ _DELETE(c);
+ }
+ n = next;
+ }
+ }
for(node *n=nl->h; n; n = n->next) {
sql_change *c = n->data;
- if (c->cleanup)
- c->cleanup(store, c, commit_ts, oldest);
+ if (c->cleanup && !c->cleanup(store, c, commit_ts,
oldest))
+ store->changes = sa_list_append(tr->sa,
store->changes, c);
+ else
+ _DELETE(c);
}
list_destroy(nl);
list_destroy(tr->changes);
@@ -3568,21 +3597,17 @@ sql_trans_commit(sql_trans *tr)
node *next = n->next;
sql_change *c = n->data;
- if (c->cleanup && c->cleanup(store, c, commit_ts,
oldest))
+ if (c->cleanup && c->cleanup(store, c, commit_ts,
oldest)) {
list_remove_node(tr->changes, store, n);
+ _DELETE(c);
+ } else if (tr->parent) {
+ tr->parent->changes = sa_list_append(tr->sa,
tr->parent->changes, c);
+ } else {
+ store->changes = sa_list_append(tr->sa,
store->changes, c);
+ }
n = next;
}
- if (tr->parent && !list_empty(tr->changes)) {
- if (!tr->parent->changes)
- tr->parent->changes = tr->changes;
- else {
- tr->parent->changes =
list_merge(tr->parent->changes, tr->changes, NULL);
- tr->changes->destroy = NULL;
- list_destroy(tr->changes);
- }
- } else {
- list_destroy(tr->changes); /* TODO move leftovers into
store for later gc */
- }
+ list_destroy(tr->changes);
tr->changes = NULL;
}
tr->ts = commit_ts;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list