Skip to content

Commit 424ee9a

Browse files
pcmooredrakenclimber
authored andcommitted
db: handle transaction aborts properly
It turns out we don't properly handle transaction aborts as we should, this likely broke when we implemented the shadow snapshots but as the transaction concept was not exported via the API, and callers most likely abandoned the filter on error this went unnoticed. This patch ensures that transaction aborts are handled properly by correctly managing the filter's transaction stack. Signed-off-by: Paul Moore <[email protected]> Signed-off-by: Tom Hromatka <[email protected]> (imported from commit 38c8670) Signed-off-by: Paul Moore <[email protected]> Signed-off-by: Tom Hromatka <[email protected]>
1 parent 91d0fa0 commit 424ee9a

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/db.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,12 +2485,19 @@ void db_col_transaction_abort(struct db_filter_col *col)
24852485
struct db_filter **filters;
24862486
struct db_filter_snap *snap;
24872487

2488-
if (col->snapshots == NULL)
2488+
snap = col->snapshots;
2489+
if (snap == NULL)
24892490
return;
24902491

2491-
/* replace the current filter with the last snapshot */
2492-
snap = col->snapshots;
2492+
/* replace the current filter with the last snapshot, skipping shadow
2493+
* snapshots are they are duplicates of the current snapshot */
2494+
if (snap->shadow) {
2495+
struct db_filter_snap *tmp = snap;
2496+
snap = snap->next;
2497+
_db_snap_release(tmp);
2498+
}
24932499
col->snapshots = snap->next;
2500+
24942501
filter_cnt = col->filter_cnt;
24952502
filters = col->filters;
24962503
col->filter_cnt = snap->filter_cnt;
@@ -2528,8 +2535,9 @@ void db_col_transaction_commit(struct db_filter_col *col)
25282535
if (snap->shadow) {
25292536
/* leave the shadow intact, but drop the next snapshot */
25302537
if (snap->next) {
2531-
snap->next = snap->next->next;
2532-
_db_snap_release(snap->next);
2538+
struct db_filter_snap *tmp = snap->next;
2539+
snap->next = tmp->next;
2540+
_db_snap_release(tmp);
25332541
}
25342542
return;
25352543
}

0 commit comments

Comments
 (0)