changeset 86164:52cba3e788de smart-merge-jan22

Remove committing transaction from remaining actives.
author Aris Koning <aris.koning@monetdbsolutions.com>
date Tue, 26 Jul 2022 14:39:06 +0200
parents 45a83ef60c1a
children 5873fe7ba498
files sql/storage/bat/bat_storage.c sql/storage/store.c
diffstat 2 files changed, 11 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/sql/storage/bat/bat_storage.c
+++ b/sql/storage/bat/bat_storage.c
@@ -408,7 +408,6 @@ merge_segments(storage *s, sql_trans *tr
 				int merge = 1;
 				for (int i = 0; active[i] != 0; i++) {
 					assert(active[i] != seg->ts && active[i] != cur->ts);
-					if (active[i] != tr->ts) /* the transaction can ignore its own active timestamp since it's committing */
 					if ((active[i] > seg->ts && active[i] < cur->ts) ||
 						(active[i] < seg->ts && active[i] > cur->ts)) {
 						/* cannot safely merge since there is an active transaction between the segments */
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -58,14 +58,17 @@ store_oldest(sqlstore *store)
 }
 
 static ulng *
-store_get_active(sqlstore *store)
-{
-	ulng *active = malloc(sizeof(ulng) * (store->active->cnt + 1));
+store_get_active(sqlstore *store, sql_trans* tr)
+{
+	ulng *active = malloc(sizeof(ulng) * store->active->cnt);
 	node *cur = store->active->h;
+	int j = 0;
 	for (int i = 0; i < store->active->cnt; i++, cur = cur->next) {
-		active[i] = ((sql_session*)cur->data)->tr->ts;
-	}
-	active[store->active->cnt] = 0;
+		ulng ts = ((sql_session*)cur->data)->tr->ts;
+		if (ts != tr->ts)
+			active[j++] = ((sql_session*)cur->data)->tr->ts;
+	}
+	active[j] = 0;
 	return active;
 }
 
@@ -3636,7 +3639,7 @@ sql_trans_rollback(sql_trans *tr, bool c
 		store_lock(store);
 		ulng oldest = store_oldest(store);
 		ulng commit_ts = store_get_timestamp(store); /* use most recent timestamp such that we can cleanup savely */
-		ulng *active = store_get_active(store); /* get active transactions (to merge segments) */
+		ulng *active = store_get_active(store, tr); /* get active transactions (to merge segments) */
 		for(node *n=nl->h; n; n = n->next) {
 			sql_change *c = n->data;
 
@@ -3989,7 +3992,7 @@ sql_trans_commit(sql_trans *tr)
 		if (ATOMIC_GET(&store->nr_active) == 1 && !tr->parent)
 			oldest = commit_ts;
 		store_pending_changes(store, oldest);
-		ulng *active = store_get_active(store); /* get active transactions (to merge segments) */
+		ulng *active = store_get_active(store, tr); /* get active transactions (to merge segments) */
 		for(node *n=tr->changes->h; n && ok == LOG_OK; n = n->next) {
 			sql_change *c = n->data;