This is an automated email from the ASF dual-hosted git repository.

lahirujayathilake pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git


The following commit(s) were added to refs/heads/master by this push:
     new 2fb42b817 Lock project rows FOR NO KEY UPDATE (#719)
2fb42b817 is described below

commit 2fb42b81717ddf277c43cf8487cb3016fed551fa
Author: Yasith Jayawardana <[email protected]>
AuthorDate: Thu Nov 12 23:53:58 2026 -0500

    Lock project rows FOR NO KEY UPDATE (#719)
    
    A create or renewal packet for an inactive project with no allocation
    hung: the packet tx locked the project FOR UPDATE, and the allocation
    insert in a second tx waited on its foreign-key KEY SHARE lock forever.
    FOR NO KEY UPDATE still serializes status changes but lets
    foreign-key inserts through.
---
 internal/store/project_store.go | 2 +-
 internal/store/store.go         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/internal/store/project_store.go b/internal/store/project_store.go
index efc6f455c..931bfbb95 100644
--- a/internal/store/project_store.go
+++ b/internal/store/project_store.go
@@ -89,7 +89,7 @@ func (s *pgProjectStore) FindByID(ctx context.Context, id 
string) (*models.Proje
 func (s *pgProjectStore) FindByIDTx(ctx context.Context, tx *sql.Tx, id 
string) (*models.Project, error) {
        var r models.Project
        err := (&sqlx.Tx{Tx: tx, Mapper: s.db.Mapper}).GetContext(ctx, &r,
-               `SELECT `+projectColumns+` FROM projects WHERE id = $1 FOR 
UPDATE`, id)
+               `SELECT `+projectColumns+` FROM projects WHERE id = $1 
`+string(NoKeyUpdateLock), id)
        if errors.Is(err, sql.ErrNoRows) {
                return nil, nil
        }
diff --git a/internal/store/store.go b/internal/store/store.go
index 1fed92261..dc987fa33 100644
--- a/internal/store/store.go
+++ b/internal/store/store.go
@@ -144,7 +144,7 @@ type UserIdentityStore interface {
 type ProjectStore interface {
        // FindByID returns the project with the given ID, or nil if not found.
        FindByID(ctx context.Context, id string) (*models.Project, error)
-       // FindByIDTx returns the project locked FOR UPDATE in tx, or nil if 
not found.
+       // FindByIDTx returns the project locked FOR NO KEY UPDATE in tx, or 
nil if not found.
        FindByIDTx(ctx context.Context, tx *sql.Tx, id string) 
(*models.Project, error)
        // FindByOriginatedID returns the project matching the external 
originated ID, or nil if not found.
        FindByOriginatedID(ctx context.Context, originatedID string) 
(*models.Project, error)

Reply via email to