// storageMigrationActive checks and warns against in-progress storage migrations.
// This function will block until storage is available.
555611
func (c *ServerCommand) storageMigrationActive(backend physical.Backend) bool {
	first := true

	for {
		migrationStatus, err := CheckStorageMigration(backend)
		if err == nil {
			if migrationStatus != nil {
				startTime := migrationStatus.Start.Format(time.RFC3339)
				c.UI.Error(wrapAtLength(fmt.Sprintf("ERROR! Storage migration in progress (started: %s). "+
					"Server startup is prevented until the migration completes. Use 'vault operator migrate -reset' "+
					"to force clear the migration lock.", startTime)))
				return true
			}
			return false
		}
		if first {
			first = false
			c.UI.Warn("\nWARNING! Unable to read storage migration status.")

			// unexpected state, so stop buffering log messages
			c.logGate.Flush()
		}
		c.logger.Warn("storage migration check error", "error", err.Error())

		select {
		case <-time.After(2 * time.Second):
		case <-c.ShutdownCh:
			return true
		}
	}
}
257278
func (m *Migrator) migrateStableStore() error {
	op := "Migrating stable store"
	m.sendProgress(op, 0, 1)

	total := len(stableStoreKeys)
	for i, key := range stableStoreKeys {
		val, err := m.mdbStore.Get(key)
		if err != nil {
			if err.Error() != "not found" {
				return fmt.Errorf("Error getting key '%s': %s", string(key), err)
			}
			m.sendProgress(op, i+1, total)
			continue
		}
		if err := m.boltStore.Set(key, val); err != nil {
			return fmt.Errorf("Error storing key '%s': %s", string(key), err)
		}
		m.sendProgress(op, i+1, total)
	}
	return nil
}
911389
func (ctx *context) ActiveConnections() []net.Conn {
	var connections []net.Conn
	ctx.mutex.Lock()
	defer ctx.mutex.Unlock()
	for _, v := range ctx.storage {
		if s, ok := v.(Session); ok == true {
			connections = append(connections, s.Connection())
		}
	}

	return connections
}
1073090
func (c *Client) FindStoragePoolsForMigration(p *FindStoragePoolsForMigrationParameter) (*StoragePool, error) {
	obj, err := c.Request("findStoragePoolsForMigration", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*StoragePool), err
}
686085
func NewMoveBatchArg(Entries []*RelocationPath) *MoveBatchArg {
	s := new(MoveBatchArg)
	s.Entries = Entries
	s.Autorename = false
	s.AllowOwnershipTransfer = false
	return s
}
537391
func (c *Connection) TransactionActive() bool {
	c.dbMu.RLock()
	defer c.dbMu.RUnlock()
	if c.db == nil {
		return false
	}
	return c.db.TransactionActive()
}
625030
func (md *MDServerMemory) StartImplicitTeamMigration(
	ctx context.Context, id tlf.ID) (err error) {
	md.lock.Lock()
	defer md.lock.Unlock()
	md.iTeamMigrationLocks[id] = true
	return nil
}
350772
func (axp *TxPool) LogActive() {
	axp.logMu.Lock()
	defer axp.logMu.Unlock()
	if time.Since(axp.lastLog) < txLogInterval {
		return
	}
	axp.lastLog = time.Now()
	conns := axp.activePool.GetAll()
	for _, c := range conns {
		c.(*TxConnection).LogToFile.Set(1)
	}
}
484439
func (s *PoolService) FindStoragePoolsForMigration(p *FindStoragePoolsForMigrationParams) (*FindStoragePoolsForMigrationResponse, error) {
	resp, err := s.cs.newRequest("findStoragePoolsForMigration", p.toURLValues())
	if err != nil {
		return nil, err
	}

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

	return &r, nil
}
718850
func (mr *MockDiskMockRecorder) NeedsMigration(arg0, arg1 interface{}) *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NeedsMigration", reflect.TypeOf((*MockDisk)(nil).NeedsMigration), arg0, arg1)
}
445748
func ApplicationMigrations(prefix string) map[string]storage.MigrateFunction {
	funcs := make(map[string]storage.MigrateFunction)
	for v, f := range applicationMigrations {
		funcs[v] = f(prefix)
	}
	return funcs
}
815776
func (p *localPrevAlloc) Migrate(ctx context.Context, dest *allocdir.AllocDir) error {
	if !p.sticky {
		// Not a sticky volume, nothing to migrate
		return nil
	}

	p.waitingLock.Lock()
	p.migrating = true
	p.waitingLock.Unlock()
	defer func() {
		p.waitingLock.Lock()
		p.migrating = false
		p.waitingLock.Unlock()
	}()

	p.logger.Debug("copying previous alloc")

	moveErr := dest.Move(p.prevAllocDir, p.tasks)

	// Always cleanup previous alloc
	if err := p.prevAllocDir.Destroy(); err != nil {
		p.logger.Error("error destroying alloc dir",
			"error", err, "previous_alloc_dir", p.prevAllocDir.AllocDir)
	}

	return moveErr
}
710070
func (a *UnitAgent) validateMigration(apiCaller base.APICaller) error {
	// TODO(mjs) - more extensive checks to come.
	unitTag := names.NewUnitTag(a.UnitName)
	facade := uniter.NewState(apiCaller, unitTag)
	_, err := facade.Unit(unitTag)
	if err != nil {
		return errors.Trace(err)
	}
	model, err := facade.Model()
	if err != nil {
		return errors.Trace(err)
	}
	curModelUUID := a.CurrentConfig().Model().Id()
	newModelUUID := model.UUID
	if newModelUUID != curModelUUID {
		return errors.Errorf("model mismatch when validating: got %q, expected %q",
			newModelUUID, curModelUUID)
	}
	return nil
}
512922
func (cp *ConnectionPool) Active() int64 {
	p := cp.pool()
	if p == nil {
		return 0
	}
	return p.Active()
}
85927
func (ls *LocalStore) Migrate() error {
	actualDbSchema, err := ls.DbStore.GetSchema()
	if err != nil {
		log.Error(err.Error())
		return err
	}

	if actualDbSchema == CurrentDbSchema {
		return nil
	}

	log.Debug("running migrations for", "schema", actualDbSchema, "runtime-schema", CurrentDbSchema)

	if actualDbSchema == DbSchemaNone {
		ls.migrateFromNoneToPurity()
		actualDbSchema = DbSchemaPurity
	}

	if err := ls.DbStore.PutSchema(actualDbSchema); err != nil {
		return err
	}

	if actualDbSchema == DbSchemaPurity {
		if err := ls.migrateFromPurityToHalloween(); err != nil {
			return err
		}
		actualDbSchema = DbSchemaHalloween
	}

	if err := ls.DbStore.PutSchema(actualDbSchema); err != nil {
		return err
	}
	return nil
}
1192748
func (t *seriesPartitionTracker) IncCompactionsActive() {
	if !t.enabled {
		return
	}

	labels := t.Labels()
	labels["component"] = "index" // TODO(edd): when we add segment compactions we will add a new label value.
	t.metrics.CompactionsActive.With(labels).Inc()
}
657158
func (m *Migrator) migrateLogStore() error {
	op := "Migrating log store"
	m.sendProgress(op, 0, 1)

	first, err := m.mdbStore.FirstIndex()
	if err != nil {
		return err
	}
	if first == 0 {
		return errFirstIndexZero
	}

	last, err := m.mdbStore.LastIndex()
	if err != nil {
		return err
	}
	if last == 0 {
		return errLastIndexZero
	}
	total := int(last - first)

	current := 0
	for i := first; i <= last; i++ {
		log := &raft.Log{}
		if err := m.mdbStore.GetLog(i, log); err != nil {
			return err
		}
		if err := m.boltStore.StoreLog(log); err != nil {
			return err
		}
		current++
		m.sendProgress(op, current, total)
	}
	return nil
}