fix: replace named locks with Galera-compatible row locks
Test / test (push) Successful in 25m39s
Build and publish image / image (push) Successful in 16m16s

This commit is contained in:
bryanpedini committed 2026-11-20 16:27:15 +01:00
1 parent ee07866d1c
commit 65d16c2fc6
22 files changed
+314 -365

No files matched your search

+32 -37
View File
@@ -849,49 +849,44 @@ type zoneAPIWrite struct {
func (h zoneHandlers) writeZone(ctx context.Context, c *apiContext, creating bool, change func(zoneAPIWrite) (apiResponse, error)) (apiResponse, error) {
var response apiResponse
var committed bool
err := withZoneLock(ctx, h.server.db, h.server.tables, c.Zone, h.server.log, func(conn *sql.Conn) error {
err := runInTx(ctx, conn, func(tx *sql.Tx) error {
w := zoneAPIWrite{ctx: ctx, api: c, records: newRecordStore(tx, h.server.tables), delegations: newDelegationStore(tx, h.server.tables)}
actor, err := newUserStore(tx, h.server.tables).UserByIDForShare(ctx, c.Principal.User.ID)
if err != nil && !errors.Is(err, errRowNotFound) {
return err
}
if err != nil || actor.DeletedAt.Valid || actor.Role != c.Principal.User.Role {
return errZoneNotFound()
}
if actor.Role == "user" {
allowed, err := w.delegations.HasDelegationForShare(ctx, c.Zone, actor.ID)
if err != nil {
return err
}
if !allowed {
return errZoneNotFound()
}
}
w.rows, err = w.records.ZoneRowsForUpdate(ctx, c.Zone)
err := runZoneTx(ctx, h.server.db, h.server.tables, c.Zone, h.server.log, func(tx *sql.Tx) error {
w := zoneAPIWrite{ctx: ctx, api: c, records: newRecordStore(tx, h.server.tables), delegations: newDelegationStore(tx, h.server.tables)}
actor, err := newUserStore(tx, h.server.tables).UserByIDForShare(ctx, c.Principal.User.ID)
if err != nil && !errors.Is(err, errRowNotFound) {
return err
}
if err != nil || actor.DeletedAt.Valid || actor.Role != c.Principal.User.Role {
return errZoneNotFound()
}
if actor.Role == "user" {
allowed, err := w.delegations.HasDelegationForShare(ctx, c.Zone, actor.ID)
if err != nil {
return err
}
if creating && len(w.rows) != 0 {
return &apiError{Status: http.StatusConflict, Message: "zone already exists"}
}
if !creating && len(w.rows) == 0 {
if !allowed {
return errZoneNotFound()
}
response, err = change(w)
if err != nil {
return err
}
if c.Entry.Before != nil || c.Entry.After != nil {
return c.writeChangeAudit(ctx, tx, response.Status)
}
return nil
})
committed = err == nil
return err
}
w.rows, err = w.records.ZoneRowsForUpdate(ctx, c.Zone)
if err != nil {
return err
}
if creating && len(w.rows) != 0 {
return &apiError{Status: http.StatusConflict, Message: "zone already exists"}
}
if !creating && len(w.rows) == 0 {
return errZoneNotFound()
}
response, err = change(w)
if err != nil {
return err
}
if c.Entry.Before != nil || c.Entry.After != nil {
return c.writeChangeAudit(ctx, tx, response.Status)
}
return nil
})
if !committed {
if err != nil {
c.auditDone = false
c.Entry.Before, c.Entry.After = nil, nil
if errors.Is(err, errLockTimeout) {