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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

new IP allocator and add postgres to integration tests. #1756

Merged
merged 10 commits into from Feb 18, 2024

Conversation

kradalby
Copy link
Collaborator

@kradalby kradalby commented Feb 15, 2024

This PR adds a new IP allocator which should be more efficient, stable and less racy. This was necessary to deal with a discovered race condition in the allocation after adding postgresql integration tests.

I believe this is replacing the first "real" code I contributed to the project, and man, that was ver much needed 馃槅.

In addition it adds a new option to the integration tests to run them against postgresql instead of sqlite to ensure we do not have this regression again.

The last commit is the generation of new gh actions jobs and can be ignored as generated.

Fixes #1755

Signed-off-by: Kristoffer Dalby kristoffer@tailscale.com

@kradalby kradalby force-pushed the postgres-tests branch 3 times, most recently from 6296b05 to da45a20 Compare February 15, 2024 15:59
@kradalby kradalby changed the title rollback gorm, add postgres to integration tests. add postgres to integration tests. Feb 16, 2024
This new allocator keeps the used space in memory and
loads the database only on startup. If it allocates but
something errors before it gets saved to the database,
then thats fine because it will be cleared on next restart.

This should resolve races between ip allocation with postgres
and as a side effect should make it easier to implement random
allocation instead of serial if we so desire.

Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
@kradalby kradalby changed the title add postgres to integration tests. new IP allocator and add postgres to integration tests. Feb 17, 2024
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit removes the old IP allocation logic which means
that we no longer need to pass IP Prefixes all around the place,
this allowed us to clean up some quite racy database code and
addresses are now allocated before interacting with the database
and fetched before registering the machines.

Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
@@ -98,6 +99,10 @@ func (api headscaleV1APIServer) ListUsers(
response[index] = user.Proto()
}

sort.Slice(response, func(i, j int) bool {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good lord, yes.

@kradalby kradalby merged commit 384ca03 into juanfont:main Feb 18, 2024
96 of 97 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LastInsertId is not supported by Postgres
2 participants