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

+21 -13
View File
@@ -1058,13 +1058,11 @@ func (f *zoneAPITestDB) query(query string, args []any) fdbResponse {
}
}
switch {
case has("GET_LOCK"):
case has("webui_locks"):
if f.locked {
return fdbResponse{rows: fdbRow(int64(0))}
return fdbResponse{err: errLockTimeout}
}
return fdbResponse{rows: fdbRow(int64(1))}
case has("RELEASE_LOCK"):
return fdbResponse{rows: fdbRow(int64(1))}
return fdbResponse{rowsAffected: 1}
case has("SELECT u.") && has("LOCK IN SHARE MODE"):
if !f.hasActor {
return fdbResponse{}
@@ -1147,6 +1145,18 @@ func zoneAPITestKey(zone string) string {
return zone
}
func zoneAPIHasDataWrites(state *fdbState) bool {
for _, query := range state.Queries() {
if strings.Contains(query, "webui_locks") {
continue
}
if strings.HasPrefix(query, "INSERT INTO") || strings.HasPrefix(query, "UPDATE ") || strings.HasPrefix(query, "DELETE FROM") {
return true
}
}
return false
}
func zoneAPITestingSQL(state *fdbState, contains string) []fdbCall {
var result []fdbCall
for _, call := range state.Calls() {
@@ -1194,7 +1204,7 @@ func TestZoneAPIReadHandlers(t *testing.T) {
}
})
}
if len(zoneAPITestingSQL(state, "INSERT INTO")) != 0 {
if zoneAPIHasDataWrites(state) {
t.Fatal("read wrote to the database")
}
user := userRow{ID: 17, Role: "user", Username: "alice"}
@@ -1291,9 +1301,8 @@ func TestZoneAPIWriteHandlers(t *testing.T) {
t.Fatalf("delegations in the after snapshot: %s", c.Entry.After)
}
calls := state.Queries()
if !strings.Contains(calls[0], "GET_LOCK") || !strings.HasSuffix(calls[1], "LOCK IN SHARE MODE") ||
!strings.HasSuffix(calls[2], "FOR UPDATE") || !strings.Contains(calls[len(calls)-2], "INSERT INTO `coredns_webui_audit`") ||
!strings.Contains(calls[len(calls)-1], "RELEASE_LOCK") {
if !strings.Contains(calls[0], "webui_locks") || !strings.HasSuffix(calls[1], "LOCK IN SHARE MODE") ||
!strings.HasSuffix(calls[2], "FOR UPDATE") || !strings.Contains(calls[len(calls)-1], "INSERT INTO `coredns_webui_audit`") {
t.Fatalf("write query order: %v", calls)
}
})
@@ -1416,7 +1425,7 @@ func TestZoneAPIWriteRefusals(t *testing.T) {
t.Fatalf("busy error = %q", apiErr.Message)
}
if c.auditDone || c.Entry.Before != nil || c.Entry.After != nil ||
len(zoneAPITestingSQL(state, "INSERT INTO"))+len(zoneAPITestingSQL(state, "UPDATE `"))+len(zoneAPITestingSQL(state, "DELETE FROM")) != 0 {
zoneAPIHasDataWrites(state) {
t.Fatalf("refusal wrote data: %+v, queries %v", c.Entry, state.Queries())
}
})
@@ -1477,7 +1486,7 @@ func TestZoneAPISOAFieldNames(t *testing.T) {
if !errors.As(err, &invalid) || invalid.Status != 422 || len(invalid.Fields) != 1 || invalid.Fields[field] == "" {
t.Fatalf("field %q: error %+v", field, err)
}
if c.auditDone || len(zoneAPITestingSQL(state, "INSERT INTO")) != 0 || len(zoneAPITestingSQL(state, "UPDATE `")) != 0 {
if c.auditDone || zoneAPIHasDataWrites(state) {
t.Fatalf("invalid field wrote data: %v", state.Queries())
}
})
@@ -1502,8 +1511,7 @@ func TestZoneAPIRollback(t *testing.T) {
c := zoneAPITestRequest(server, f.actor, "record_create", zoneAPITestName, "", "", zoneAPITestRecord)
resp, err := zoneAPITestCall(t.Context(), c)
if !errors.Is(err, failure) || resp.Status != 0 || c.auditDone || c.Entry.Before != nil || c.Entry.After != nil ||
state.commits != 0 || (failAt != "commit" && state.rollbacks != 1) ||
!strings.Contains(state.Queries()[len(state.Queries())-1], "RELEASE_LOCK") {
state.commits != 0 || (failAt != "commit" && state.rollbacks != 1) {
t.Fatalf("response %+v, err %v, audit %+v, SQL %v", resp, err, c.Entry, state.Queries())
}
})