Skip to content

Commit

Permalink
db: handle transaction aborts properly
Browse files Browse the repository at this point in the history
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 <paul@paul-moore.com>
  • Loading branch information
pcmoore committed May 15, 2023
1 parent f1c3196 commit 6255796
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -2513,12 +2513,19 @@ void db_col_transaction_abort(struct db_filter_col *col)
struct db_filter **filters;
struct db_filter_snap *snap;

if (col->snapshots == NULL)
snap = col->snapshots;
if (snap == NULL)
return;

/* replace the current filter with the last snapshot */
snap = col->snapshots;
/* replace the current filter with the last snapshot, skipping shadow
* snapshots are they are duplicates of the current snapshot */
if (snap->shadow) {
struct db_filter_snap *tmp = snap;
snap = snap->next;
_db_snap_release(tmp);
}
col->snapshots = snap->next;

filter_cnt = col->filter_cnt;
filters = col->filters;
col->filter_cnt = snap->filter_cnt;
Expand Down Expand Up @@ -2559,8 +2566,9 @@ void db_col_transaction_commit(struct db_filter_col *col)
if (snap->shadow) {
/* leave the shadow intact, but drop the next snapshot */
if (snap->next) {
snap->next = snap->next->next;
_db_snap_release(snap->next);
struct db_filter_snap *tmp = snap->next;
snap->next = tmp->next;
_db_snap_release(tmp);
}
return;
}
Expand Down

0 comments on commit 6255796

Please sign in to comment.