Skip to content

Commit 4ba6957

Browse files
SJrXSteve Ramage
and
Steve Ramage
authored
Resolves #647 - Fixes typos in Mongo advisory locking parameters (#648)
* Resolves #647 - Fixes typos in Mongo advisory locking parameters * PR Feedback for #647 - Error out when both params set * Fixes lint issues with #647 * Additional PR Fixes #647 * Lint fixes again #647 * One more tweak to CONTRIBUTING.md * One more tweak to CONTRIBUTING.md, again Co-authored-by: Steve Ramage <[email protected]>
1 parent efa49bc commit 4ba6957

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

Diff for: database/mongodb/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
| `x-transaction-mode` | `TransactionMode` | If set to `true` wrap commands in [transaction](https://docs.mongodb.com/manual/core/transactions). Available only for replica set. Driver is using [strconv.ParseBool](https://golang.org/pkg/strconv/#ParseBool) for parsing|
1616
| `x-advisory-locking` | `true` | Feature flag for advisory locking, if set to false, disable advisory locking |
1717
| `x-advisory-lock-collection` | `migrate_advisory_lock` | The name of the collection to use for advisory locking.|
18-
| `x-advisory-lock-timout` | `15` | The max time in seconds that the advisory lock will wait if the db is already locked. |
19-
| `x-advisory-lock-timout-interval` | `10` | The max timeout in seconds interval that the advisory lock will wait if the db is already locked. |
18+
| `x-advisory-lock-timeout` | `15` | The max time in seconds that migrate will wait to acquire a lock before failing. |
19+
| `x-advisory-lock-timeout-interval` | `10` | The max time in seconds between attempts to acquire the advisory lock, the lock is attempted to be acquired using an exponential backoff algorithm. |
2020
| `dbname` | `DatabaseName` | The name of the database to connect to |
2121
| `user` | | The user to sign in as. Can be omitted |
2222
| `password` | | The user's password. Can be omitted |

Diff for: database/mongodb/mongodb.go

+20-4
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ const LockIndexName = "lock_unique_key" // the name of the inde
3636
const contextWaitTimeout = 5 * time.Second // how long to wait for the request to mongo to block/wait for.
3737

3838
var (
39-
ErrNoDatabaseName = fmt.Errorf("no database name")
40-
ErrNilConfig = fmt.Errorf("no config")
39+
ErrNoDatabaseName = fmt.Errorf("no database name")
40+
ErrNilConfig = fmt.Errorf("no config")
41+
ErrLockTimeoutConfigConflict = fmt.Errorf("both x-advisory-lock-timeout-interval and x-advisory-lock-timout-interval were specified")
4142
)
4243

4344
type Mongo struct {
@@ -137,7 +138,22 @@ func (m *Mongo) Open(dsn string) (database.Driver, error) {
137138
if err != nil {
138139
return nil, err
139140
}
140-
maxLockingIntervals, err := parseInt(unknown.Get("x-advisory-lock-timout-interval"), DefaultLockTimeoutInterval)
141+
142+
lockTimeoutIntervalValue := unknown.Get("x-advisory-lock-timeout-interval")
143+
// The initial release had a typo for this argument but for backwards compatibility sake, we will keep supporting it
144+
// and we will error out if both values are set.
145+
lockTimeoutIntervalValueFromTypo := unknown.Get("x-advisory-lock-timout-interval")
146+
147+
lockTimeout := lockTimeoutIntervalValue
148+
149+
if lockTimeoutIntervalValue != "" && lockTimeoutIntervalValueFromTypo != "" {
150+
return nil, ErrLockTimeoutConfigConflict
151+
} else if lockTimeoutIntervalValueFromTypo != "" {
152+
lockTimeout = lockTimeoutIntervalValueFromTypo
153+
}
154+
155+
maxLockCheckInterval, err := parseInt(lockTimeout, DefaultLockTimeoutInterval)
156+
141157
if err != nil {
142158
return nil, err
143159
}
@@ -157,7 +173,7 @@ func (m *Mongo) Open(dsn string) (database.Driver, error) {
157173
CollectionName: lockCollection,
158174
Timeout: lockingTimout,
159175
Enabled: advisoryLockingFlag,
160-
Interval: maxLockingIntervals,
176+
Interval: maxLockCheckInterval,
161177
},
162178
})
163179
if err != nil {

0 commit comments

Comments
 (0)