Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warden/group: add rollback to transactions #494

Merged
merged 1 commit into from
Jun 5, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions warden/group/manager_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,20 @@ func (m *SQLManager) AddGroupMembers(group string, subjects []string) error {
if err != nil {
return errors.Wrap(err, "Could not begin transaction")
}

for _, subject := range subjects {
if _, err := tx.Exec(m.DB.Rebind("INSERT INTO hydra_warden_group_member (group_id, member) VALUES (?, ?)"), group, subject); err != nil {
if err := tx.Rollback(); err != nil {
return errors.WithStack(err)
}
return errors.WithStack(err)
}
}

if err := tx.Commit(); err != nil {
if err := tx.Rollback(); err != nil {
return errors.WithStack(err)
}
return errors.Wrap(err, "Could not commit transaction")
}
return nil
Expand All @@ -100,11 +107,17 @@ func (m *SQLManager) RemoveGroupMembers(group string, subjects []string) error {
}
for _, subject := range subjects {
if _, err := m.DB.Exec(m.DB.Rebind("DELETE FROM hydra_warden_group_member WHERE member=? AND group_id=?"), subject, group); err != nil {
if err := tx.Rollback(); err != nil {
return errors.WithStack(err)
}
return errors.WithStack(err)
}
}

if err := tx.Commit(); err != nil {
if err := tx.Rollback(); err != nil {
return errors.WithStack(err)
}
return errors.Wrap(err, "Could not commit transaction")
}
return nil
Expand Down