// MigrateWAL rewrites the deprecated write ahead log into the new format.
16458
func MigrateWAL(logger log.Logger, dir string) (err error) {
	if logger == nil {
		logger = log.NewNopLogger()
	}
	if exists, err := deprecatedWALExists(logger, dir); err != nil || !exists {
		return err
	}
	level.Info(logger).Log("msg", "migrating WAL format")

	tmpdir := dir + ".tmp"
	if err := os.RemoveAll(tmpdir); err != nil {
		return errors.Wrap(err, "cleanup replacement dir")
	}
	repl, err := wal.New(logger, nil, tmpdir)
	if err != nil {
		return errors.Wrap(err, "open new WAL")
	}

	// It should've already been closed as part of the previous finalization.
	// Do it once again in case of prior errors.
	defer func() {
		if err != nil {
			repl.Close()
		}
	}()

	w, err := OpenSegmentWAL(dir, logger, time.Minute, nil)
	if err != nil {
		return errors.Wrap(err, "open old WAL")
	}
	defer w.Close()

	rdr := w.Reader()

	var (
		enc RecordEncoder
		b   []byte
	)
	decErr := rdr.Read(
		func(s []RefSeries) {
			if err != nil {
				return
			}
			err = repl.Log(enc.Series(s, b[:0]))
		},
		func(s []RefSample) {
			if err != nil {
				return
			}
			err = repl.Log(enc.Samples(s, b[:0]))
		},
		func(s []Stone) {
			if err != nil {
				return
			}
			err = repl.Log(enc.Tombstones(s, b[:0]))
		},
	)
	if decErr != nil {
		return errors.Wrap(err, "decode old entries")
	}
	if err != nil {
		return errors.Wrap(err, "write new entries")
	}
	// We explicitly close even when there is a defer for Windows to be
	// able to delete it. The defer is in place to close it in-case there
	// are errors above.
	if err := w.Close(); err != nil {
		return errors.Wrap(err, "close old WAL")
	}
	if err := repl.Close(); err != nil {
		return errors.Wrap(err, "close new WAL")
	}
	if err := fileutil.Replace(tmpdir, dir); err != nil {
		return errors.Wrap(err, "replace old WAL")
	}
	return nil
}
1275981
func (c *Client) MigrateVirtualMachine(p *MigrateVirtualMachineParameter) (*VirtualMachine, error) {
	obj, err := c.Request("migrateVirtualMachine", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*VirtualMachine), err
}
447328
func (c *Conn) writeFatal(err error) error {
	err = hideTempErr(err)
	c.writeErrMu.Lock()
	if c.writeErr == nil {
		c.writeErr = err
	}
	c.writeErrMu.Unlock()
	return err
}
827621
func MigrateWD(from From) error {
	wd, err := os.Getwd()
	if err != nil {
		return err
	}
	return Migrate(from, wd)
}
1279839
func MigrateRefresh(currpath, driver, connStr, dir string) {
	migrate("refresh", currpath, driver, connStr, dir)
}
714347
func MigrateColl(db *mgo.Database, collection string, fieldName string, from string, to string) (err error) {
	change, err := db.C(collection).UpdateAll(
		bson.M{
			fieldName: from,
		},
		bson.M{
			"$set": bson.M{
				fieldName: to,
			},
		},
	)
	handle_errors(err)
	fmt.Println("Updated", change.Updated, "documents in `", collection, "` collection")
	return
}
1111623
func NewWAL(path string) *WAL {
	logger := zap.NewNop()
	return &WAL{
		path:    path,
		enabled: true,

		// these options should be overridden by any options in the config
		SegmentSize: DefaultSegmentSize,
		closing:     make(chan struct{}),
		syncWaiters: make(chan chan error, 1024),
		limiter:     limiter.NewFixed(defaultWaitingWALWrites),
		logger:      logger,
	}
}
753877
func (d *Domain) MigrateStartPostCopy(flags uint32) error {
	if C.LIBVIR_VERSION_NUMBER < 1003003 {
		return makeNotImplementedError("virDomainMigrateStartPostCopy")
	}

	var err C.virError
	ret := C.virDomainMigrateStartPostCopyWrapper(d.ptr, C.uint(flags), &err)
	if ret == -1 {
		return makeError(&err)
	}

	return nil
}
720359
func (c *OperatorMigrateCommand) migrate(config *migratorConfig) error {
	from, err := c.newBackend(config.StorageSource.Type, config.StorageSource.Config)
	if err != nil {
		return errwrap.Wrapf("error mounting 'storage_source': {{err}}", err)
	}

	if c.flagReset {
		if err := SetStorageMigration(from, false); err != nil {
			return errwrap.Wrapf("error reseting migration lock: {{err}}", err)
		}
		return nil
	}

	to, err := c.newBackend(config.StorageDestination.Type, config.StorageDestination.Config)
	if err != nil {
		return errwrap.Wrapf("error mounting 'storage_destination': {{err}}", err)
	}

	migrationStatus, err := CheckStorageMigration(from)
	if err != nil {
		return errwrap.Wrapf("error checking migration status: {{err}}", err)
	}

	if migrationStatus != nil {
		return fmt.Errorf("Storage migration in progress (started: %s).", migrationStatus.Start.Format(time.RFC3339))
	}

	if err := SetStorageMigration(from, true); err != nil {
		return errwrap.Wrapf("error setting migration lock: {{err}}", err)
	}

	defer SetStorageMigration(from, false)

	ctx, cancelFunc := context.WithCancel(context.Background())

	doneCh := make(chan error)
	go func() {
		doneCh <- c.migrateAll(ctx, from, to)
	}()

	select {
	case err := <-doneCh:
		cancelFunc()
		return err
	case <-c.ShutdownCh:
		c.UI.Output("==> Migration shutdown triggered\n")
		cancelFunc()
		<-doneCh
		return errAbort
	}
}
1336974
func (c *Connection) MigrateReset(path string) error {
	oncer.Deprecate(0, "pop.Connection#MigrateReset", "Use pop.FileMigrator#Reset instead.")

	mig, err := NewFileMigrator(path, c)
	if err != nil {
		return errors.WithStack(err)
	}
	return mig.Reset()
}
364271
func (m *Migrate) RollbackMigration(mig *Migration) error {
	if mig.Rollback == nil {
		return ErrRollbackImpossible
	}

	if err := mig.Rollback(m.db); err != nil {
		return err
	}

	sql := fmt.Sprintf("DELETE FROM %s WHERE %s = ?", m.options.TableName, m.options.IDColumnName)
	if _, err := m.db.Exec(sql, mig.ID); err != nil {
		return err
	}
	return nil
}
761886
func (rules *ClientConfigLoadingRules) Migrate() error {
	if rules.MigrationRules == nil {
		return nil
	}

	for destination, source := range rules.MigrationRules {
		if _, err := os.Stat(destination); err == nil {
			// if the destination already exists, do nothing
			continue
		} else if os.IsPermission(err) {
			// if we can't access the file, skip it
			continue
		} else if !os.IsNotExist(err) {
			// if we had an error other than non-existence, fail
			return err
		}

		if sourceInfo, err := os.Stat(source); err != nil {
			if os.IsNotExist(err) || os.IsPermission(err) {
				// if the source file doesn't exist or we can't access it, there's no work to do.
				continue
			}

			// if we had an error other than non-existence, fail
			return err
		} else if sourceInfo.IsDir() {
			return fmt.Errorf("cannot migrate %v to %v because it is a directory", source, destination)
		}

		in, err := os.Open(source)
		if err != nil {
			return err
		}
		defer in.Close()
		out, err := os.Create(destination)
		if err != nil {
			return err
		}
		defer out.Close()

		if _, err = io.Copy(out, in); err != nil {
			return err
		}
	}

	return nil
}
683474
func (m *Migrator) RollbackAll() error {
	migrations := m.Migrations(Active)
	return m.RollbackN(len(migrations))
}
1155385
func (a *ActivityTypeMigrator) Migrate() {
	for _, d := range a.DeprecatedActivityTypes {
		if a.isDeprecated(d.Domain, d.ActivityType.Name, d.ActivityType.Version) {
			log.Printf("action=migrate at=deprecate-activity domain=%s activity=%s version=%s status=previously-deprecated", d.Domain, d.ActivityType.Name, d.ActivityType.Version)
		} else {
			a.deprecate(d)
			log.Printf("action=migrate at=depreacate-activity domain=%s activity=%s version=%s status=deprecated", d.Domain, d.ActivityType.Name, d.ActivityType.Version)
		}
	}
	for _, r := range a.RegisteredActivityTypes {
		if a.isRegisteredNotDeprecated(r) {
			log.Printf("action=migrate at=register-activity domain=%s activity=%s version=%s status=previously-registered", r.Domain, r.Name, r.Version)
		} else {
			a.register(r)
			log.Printf("action=migrate at=register-activity domain=%s activity=%s version=%s status=registered", r.Domain, r.Name, r.Version)
		}
	}
}
897290
func (s *VolumeService) MigrateVolume(p *MigrateVolumeParams) (*MigrateVolumeResponse, error) {
	resp, err := s.cs.newRequest("migrateVolume", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r MigrateVolumeResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	// If we have a async client, we need to wait for the async result
	if s.cs.async {
		b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
		if err != nil {
			if err == AsyncTimeoutErr {
				return &r, err
			}
			return nil, err
		}

		b, err = getRawValue(b)
		if err != nil {
			return nil, err
		}

		if err := json.Unmarshal(b, &r); err != nil {
			return nil, err
		}
	}

	return &r, nil
}
1160116
func (ev *MigrateServedTypes) Syslog() (syslog.Priority, string) {
	var format string
	if ev.Reverse {
		format = "%s [migrate served-types {%v} <- {%v}] %s"
	} else {
		format = "%s [migrate served-types {%v} -> {%v}] %s"
	}

	sourceShards := make([]string, len(ev.SourceShards))
	for i, shard := range ev.SourceShards {
		if shard == nil {
			continue
		}
		sourceShards[i] = shard.ShardName()
	}
	destShards := make([]string, len(ev.DestinationShards))
	for i, shard := range ev.DestinationShards {
		if shard == nil {
			continue
		}
		destShards[i] = shard.ShardName()
	}

	return syslog.LOG_INFO, fmt.Sprintf(format,
		ev.KeyspaceName, strings.Join(sourceShards, ", "),
		strings.Join(destShards, ", "), ev.Status)
}
623175
func (m Migration) Migrate(client *Client) error {
	complete, err := IsMigrationComplete(client.db, m.ID)
	if err != nil {
		return err
	}
	if complete {
		return nil
	}

	if client.logger != nil {
		client.logger.Info("Running migration ", m.ID, "")
	}

	if err = m.Up(client.db); err != nil {
		return err
	}

	return MarkMigrationAsComplete(client.db, m.ID)
}