-
Notifications
You must be signed in to change notification settings - Fork 17
feat: add user locking to isolation reservation table #290
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
Open
porcellus
wants to merge
21
commits into
feat/isolation-reservation-table
Choose a base branch
from
feat/isolation-reservation-table-locking
base: feat/isolation-reservation-table
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 21 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
fbbe4a1
feat: improving indexes
porcellus ba125de
feat: implement LockedUser wrapper for PostgreSQL (ISO-001)
porcellus d20d144
test: add race-condition tests
porcellus 70a202a
feat(ISO-002): implement LockedUser enforcement for reserveAccountInf…
porcellus 1c41d86
feat(ISO-003): implement LockedUser enforcement for updateAccountInfo…
porcellus 73a2176
feat(ISO-004): implement LockedUser enforcement for addPrimaryUserAcc…
porcellus 5b5d87f
feat(ISO-005): implement LockedUser-based removeAccountInfoReservatio…
porcellus 248d5f5
feat(ISO-006): add LockedUser validation to addTenantIdToRecipeUser_T…
porcellus b3948ee
fix: correct LockedUser state determination and linking validation
porcellus 427f43c
feat(ISO-007): implement LockedUser enforcement for addTenantIdToPrim…
porcellus 486a86d
feat: add recipeId to LockedUserImpl and fetch during lock acquisition
porcellus 38aee3e
feat(ISO-008): use LockedUser for getRecipeIdForUser_Transaction
porcellus 89bb6d2
feat(ISO-022): remove String-based duplicate methods, migrate plugin-…
porcellus cf24aa8
fix: remove FOR UPDATE from _Transaction methods per ISO-022
porcellus de9d021
feat: convert string-based helpers to use LockedUser (ISO-024)
porcellus ee274e9
fix: self-review and test fixes
porcellus 05a3c36
test: add a way to check on query performance of tests
porcellus b1e88ee
Merge remote-tracking branch 'origin/master' into feat/isolation-rese…
porcellus 47ff687
Merge remote-tracking branch 'origin/feat/isolation-reservation-table…
porcellus 0bb7492
fix: address PR review comments
porcellus a462918
fix: restore correct jar from origin/master
porcellus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,4 +128,4 @@ tasks.withType(Test).configureEach { | |
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
104 changes: 104 additions & 0 deletions
104
src/main/java/io/supertokens/storage/postgresql/LockedUserImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /* | ||
| * Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved. | ||
| * | ||
| * This software is licensed under the Apache License, Version 2.0 (the | ||
| * "License") as published by the Apache Software Foundation. | ||
| * | ||
| * You may not use this file except in compliance with the License. You may | ||
| * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package io.supertokens.storage.postgresql; | ||
|
|
||
| import io.supertokens.pluginInterface.useridmapping.LockedUser; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
| import javax.annotation.Nullable; | ||
| import java.sql.Connection; | ||
| import java.lang.ref.WeakReference; | ||
|
|
||
| /** | ||
| * PostgreSQL implementation of LockedUser. | ||
| * Tracks the connection to validate the lock is still active. | ||
| */ | ||
| public class LockedUserImpl implements LockedUser { | ||
|
|
||
| @Nonnull | ||
| private final String recipeUserId; | ||
|
|
||
| @Nonnull | ||
| private final String recipeId; | ||
|
|
||
| @Nullable | ||
| private final String primaryUserId; | ||
|
|
||
| // WeakReference so we don't prevent connection from being garbage collected | ||
| private final WeakReference<Connection> connectionRef; | ||
|
|
||
| public LockedUserImpl(@Nonnull String recipeUserId, @Nonnull String recipeId, | ||
| @Nullable String primaryUserId, @Nonnull Connection connection) { | ||
| this.recipeUserId = recipeUserId; | ||
| this.recipeId = recipeId; | ||
| this.primaryUserId = primaryUserId; | ||
| this.connectionRef = new WeakReference<>(connection); | ||
| } | ||
|
|
||
| @Override | ||
| @Nonnull | ||
| public String getRecipeUserId() { | ||
| return recipeUserId; | ||
| } | ||
|
|
||
| @Override | ||
| @Nonnull | ||
| public String getRecipeId() { | ||
| return recipeId; | ||
| } | ||
|
|
||
| @Override | ||
| @Nullable | ||
| public String getPrimaryUserId() { | ||
| return primaryUserId; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isValidForConnection(Object connection) { | ||
| Connection originalCon = connectionRef.get(); | ||
| if (originalCon == null) { | ||
| return false; | ||
| } | ||
| // Check that the provided connection is the same instance as the one used to acquire the lock | ||
| if (originalCon != connection) { | ||
| return false; | ||
| } | ||
| try { | ||
| return !originalCon.isClosed(); | ||
| } catch (Exception e) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| Connection con = connectionRef.get(); | ||
| boolean connectionAlive = false; | ||
| try { | ||
| connectionAlive = con != null && !con.isClosed(); | ||
| } catch (Exception ignored) { | ||
| } | ||
| return "LockedUser{" + | ||
| "recipeUserId='" + recipeUserId + '\'' + | ||
| ", recipeId='" + recipeId + '\'' + | ||
| ", primaryUserId='" + primaryUserId + '\'' + | ||
| ", isLinked=" + isLinked() + | ||
| ", isPrimary=" + isPrimary() + | ||
| ", connectionAlive=" + connectionAlive + | ||
| '}'; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually don't commit these jars. It's done by release process.