[PR #1701] [MERGED] Replace database locks with transactions #2264

Closed
opened 2025-12-29 03:20:28 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/juanfont/headscale/pull/1701
Author: @kradalby
Created: 1/27/2024
Status: Merged
Merged: 2/8/2024
Merged by: @kradalby

Base: mainHead: db-remove-lock-use-tx


📝 Commits (1)

  • 0d773b0 Replace database calls with transactions

📊 Changes

32 files changed (+1495 additions, -1127 deletions)

View changed files

📝 CHANGELOG.md (+1 -1)
📝 cmd/headscale/headscale.go (+0 -14)
📝 hscontrol/app.go (+52 -6)
📝 hscontrol/auth.go (+45 -18)
📝 hscontrol/db/addresses.go (+13 -6)
📝 hscontrol/db/addresses_test.go (+30 -16)
📝 hscontrol/db/api_key.go (+6 -27)
📝 hscontrol/db/db.go (+47 -15)
📝 hscontrol/db/node.go (+209 -350)
📝 hscontrol/db/node_test.go (+28 -52)
📝 hscontrol/db/preauth_keys.go (+60 -63)
📝 hscontrol/db/preauth_keys_test.go (+12 -8)
📝 hscontrol/db/routes.go (+196 -229)
📝 hscontrol/db/routes_test.go (+276 -47)
📝 hscontrol/db/suite_test.go (+0 -2)
📝 hscontrol/db/users.go (+53 -51)
📝 hscontrol/db/users_test.go (+3 -3)
📝 hscontrol/derp/server/derp_server.go (+1 -1)
📝 hscontrol/grpcv1.go (+144 -43)
📝 hscontrol/mapper/mapper.go (+15 -4)

...and 12 more files

📄 Description

This commits removes the locks used to guard data integrity for the
database and replaces them with Transactions, turns out that SQL had
a way to deal with this all along.

This reduces the complexity we had with multiple locks that might stack
or recurse (database, nofitifer, mapper). All notifications and state
updates are now triggered after a database change.

Signed-off-by: Kristoffer Dalby kristoffer@dalby.cc


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/juanfont/headscale/pull/1701 **Author:** [@kradalby](https://github.com/kradalby) **Created:** 1/27/2024 **Status:** ✅ Merged **Merged:** 2/8/2024 **Merged by:** [@kradalby](https://github.com/kradalby) **Base:** `main` ← **Head:** `db-remove-lock-use-tx` --- ### 📝 Commits (1) - [`0d773b0`](https://github.com/juanfont/headscale/commit/0d773b09aa3f5bf6f55b2a858bfa0428f6f29f97) Replace database calls with transactions ### 📊 Changes **32 files changed** (+1495 additions, -1127 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -1) 📝 `cmd/headscale/headscale.go` (+0 -14) 📝 `hscontrol/app.go` (+52 -6) 📝 `hscontrol/auth.go` (+45 -18) 📝 `hscontrol/db/addresses.go` (+13 -6) 📝 `hscontrol/db/addresses_test.go` (+30 -16) 📝 `hscontrol/db/api_key.go` (+6 -27) 📝 `hscontrol/db/db.go` (+47 -15) 📝 `hscontrol/db/node.go` (+209 -350) 📝 `hscontrol/db/node_test.go` (+28 -52) 📝 `hscontrol/db/preauth_keys.go` (+60 -63) 📝 `hscontrol/db/preauth_keys_test.go` (+12 -8) 📝 `hscontrol/db/routes.go` (+196 -229) 📝 `hscontrol/db/routes_test.go` (+276 -47) 📝 `hscontrol/db/suite_test.go` (+0 -2) 📝 `hscontrol/db/users.go` (+53 -51) 📝 `hscontrol/db/users_test.go` (+3 -3) 📝 `hscontrol/derp/server/derp_server.go` (+1 -1) 📝 `hscontrol/grpcv1.go` (+144 -43) 📝 `hscontrol/mapper/mapper.go` (+15 -4) _...and 12 more files_ </details> ### 📄 Description This commits removes the locks used to guard data integrity for the database and replaces them with Transactions, turns out that SQL had a way to deal with this all along. This reduces the complexity we had with multiple locks that might stack or recurse (database, nofitifer, mapper). All notifications and state updates are now triggered _after_ a database change. Signed-off-by: Kristoffer Dalby <kristoffer@dalby.cc> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 03:20:28 +01:00
adam closed this issue 2025-12-29 03:20:28 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/headscale#2264