-
Notifications
You must be signed in to change notification settings - Fork 493
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
[WIP] - Add exclusive session level advisory lock (postgres only) #483
Conversation
@@ -45,6 +68,24 @@ func UpTo(db *sql.DB, dir string, version int64, opts ...OptionsFunc) error { | |||
return err | |||
} | |||
|
|||
switch option.lockMode { | |||
case LockModeAdvisorySession: | |||
conn, err := db.Conn(ctx) |
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.
This connection should be re-used in the event *sql.DB
was configured with a maximum of 1 open connection. Otherwise, this will block indefinitely.
@@ -7,12 +7,15 @@ import ( | |||
"fmt" | |||
"sort" | |||
"strings" | |||
|
|||
"go.uber.org/multierr" |
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.
Will probably remove this package dep, just so happens I'm quite familiar with it.
return retry.RetryableError(err) | ||
} | ||
if !unlocked { | ||
// TODO(mf): provide the user with some documentation on how they can unlock |
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.
Consider removing this check, see code comment.
func (s *store) LockSession(ctx context.Context, conn *sql.Conn) error { | ||
switch t := s.querier.(type) { | ||
case *dialectquery.Postgres: | ||
// TODO(mf): need to be VERY careful about the retry logic here to avoid |
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.
Revisit this retry logic, see code comment.
Hello! Do you have any estimation for this feature? |
This is implemented in #493 for the I'm hoping to tag a |
I'm not sure adding locking in the My comments from the description still hold, and I have not spent much time thinking about it further as I've been more occupied with getting things to work in /v4
Closing this PR in favor of adding this feature to the /v4 module. |
First pass to fix #335
The default is no lock mode, but
lock=session
(cli) andgoose.WithLock(...)
(pkg) are now functional.EDIT: not overly happy with this implementation because it's awkward to thread the
*sql.Conn
through the rest of the functions and the*Migration
methods. The interface seems fine to start and can be expanded to other databases.This implementation is functional, but it does mean the max number of connections must be greater than 1. This probably solves the most common use case, but it's not ideal.
The long-term solution is uplifting goose and implementing this properly in a major version alongside #379.
goose
CLI:goose package:
*sql.DB
was set withdb.SetMaxOpenConns(1)
it'll hangpg_advisory_unlock
value check