setLockIntent is an upgrade phase which sets the upgrade lock intent with desired parameters.
(ctx context.Context, rep repo.DirectRepositoryWriter)
| 292 | // setLockIntent is an upgrade phase which sets the upgrade lock intent with |
| 293 | // desired parameters. |
| 294 | func (c *commandRepositoryUpgrade) setLockIntent(ctx context.Context, rep repo.DirectRepositoryWriter) error { |
| 295 | if c.ioDrainTimeout < format.DefaultRepositoryBlobCacheDuration && !c.allowUnsafeUpgradeTimings { |
| 296 | return errors.Errorf("minimum required io-drain-timeout is %s", format.DefaultRepositoryBlobCacheDuration) |
| 297 | } |
| 298 | |
| 299 | now := rep.Time() |
| 300 | |
| 301 | mp, mperr := rep.ContentReader().ContentFormat().GetMutableParameters(ctx) |
| 302 | if mperr != nil { |
| 303 | return errors.Wrap(mperr, "mutable parameters") |
| 304 | } |
| 305 | |
| 306 | openOpts := c.svc.optionsFromFlags(ctx) |
| 307 | l := &format.UpgradeLockIntent{ |
| 308 | OwnerID: openOpts.UpgradeOwnerID, |
| 309 | CreationTime: now, |
| 310 | IODrainTimeout: c.ioDrainTimeout, |
| 311 | StatusPollInterval: c.statusPollInterval, |
| 312 | Message: fmt.Sprintf("Upgrading from format version %d -> %d", mp.Version, format.MaxFormatVersion), |
| 313 | MaxPermittedClockDrift: c.maxPermittedClockDrift, |
| 314 | } |
| 315 | |
| 316 | // Update format-blob and clear the cache. |
| 317 | // This will fail if we have already upgraded. |
| 318 | l, err := rep.FormatManager().SetUpgradeLockIntent(ctx, *l) |
| 319 | if err != nil { |
| 320 | if errors.Is(err, format.ErrFormatUptoDate) { |
| 321 | log(ctx).Info("Repository format is already upto date.") |
| 322 | |
| 323 | c.skip = true |
| 324 | |
| 325 | return nil |
| 326 | } |
| 327 | |
| 328 | return errors.Wrap(err, "error setting the upgrade lock intent") |
| 329 | } |
| 330 | // we need to reopen the repository after this point |
| 331 | |
| 332 | locked, _ := l.IsLocked(now) |
| 333 | if l.AdvanceNoticeDuration != 0 && !locked { |
| 334 | upgradeTime := l.UpgradeTime() |
| 335 | log(ctx).Infof("Repository upgrade advance notice has been set, you must come back and perform the upgrade at %s.", |
| 336 | upgradeTime) |
| 337 | |
| 338 | c.skip = true |
| 339 | |
| 340 | return nil |
| 341 | } |
| 342 | |
| 343 | log(ctx).Info("Repository upgrade lock intent has been placed.") |
| 344 | |
| 345 | // skip all other phases after this step |
| 346 | if c.lockOnly { |
| 347 | c.skip = true |
| 348 | } |
| 349 | |
| 350 | return nil |
| 351 | } |
nothing calls this directly
no test coverage detected