diff --git a/database/mongodb/README.md b/database/mongodb/README.md index 32b736fae..bbebe02cd 100644 --- a/database/mongodb/README.md +++ b/database/mongodb/README.md @@ -15,8 +15,8 @@ | `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| | `x-advisory-locking` | `true` | Feature flag for advisory locking, if set to false, disable advisory locking | | `x-advisory-lock-collection` | `migrate_advisory_lock` | The name of the collection to use for advisory locking.| -| `x-advisory-lock-timout` | `15` | The max time in seconds that the advisory lock will wait if the db is already locked. | -| `x-advisory-lock-timout-interval` | `10` | The max timeout in seconds interval that the advisory lock will wait if the db is already locked. | +| `x-advisory-lock-timeout` | `15` | The max time in seconds that migrate will wait to acquire a lock before failing. | +| `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. | | `dbname` | `DatabaseName` | The name of the database to connect to | | `user` | | The user to sign in as. Can be omitted | | `password` | | The user's password. Can be omitted | diff --git a/database/mongodb/mongodb.go b/database/mongodb/mongodb.go index 3e18fd44b..00f0fd1be 100644 --- a/database/mongodb/mongodb.go +++ b/database/mongodb/mongodb.go @@ -36,8 +36,9 @@ const LockIndexName = "lock_unique_key" // the name of the inde const contextWaitTimeout = 5 * time.Second // how long to wait for the request to mongo to block/wait for. var ( - ErrNoDatabaseName = fmt.Errorf("no database name") - ErrNilConfig = fmt.Errorf("no config") + ErrNoDatabaseName = fmt.Errorf("no database name") + ErrNilConfig = fmt.Errorf("no config") + ErrLockTimeoutConfigConflict = fmt.Errorf("both x-advisory-lock-timeout-interval and x-advisory-lock-timout-interval were specified") ) type Mongo struct { @@ -137,7 +138,22 @@ func (m *Mongo) Open(dsn string) (database.Driver, error) { if err != nil { return nil, err } - maxLockingIntervals, err := parseInt(unknown.Get("x-advisory-lock-timout-interval"), DefaultLockTimeoutInterval) + + lockTimeoutIntervalValue := unknown.Get("x-advisory-lock-timeout-interval") + // The initial release had a typo for this argument but for backwards compatibility sake, we will keep supporting it + // and we will error out if both values are set. + lockTimeoutIntervalValueFromTypo := unknown.Get("x-advisory-lock-timout-interval") + + lockTimeout := lockTimeoutIntervalValue + + if lockTimeoutIntervalValue != "" && lockTimeoutIntervalValueFromTypo != "" { + return nil, ErrLockTimeoutConfigConflict + } else if lockTimeoutIntervalValueFromTypo != "" { + lockTimeout = lockTimeoutIntervalValueFromTypo + } + + maxLockCheckInterval, err := parseInt(lockTimeout, DefaultLockTimeoutInterval) + if err != nil { return nil, err } @@ -157,7 +173,7 @@ func (m *Mongo) Open(dsn string) (database.Driver, error) { CollectionName: lockCollection, Timeout: lockingTimout, Enabled: advisoryLockingFlag, - Interval: maxLockingIntervals, + Interval: maxLockCheckInterval, }, }) if err != nil {