func (c *Core) stopRollback() error {
	if c.rollback != nil {
		c.rollback.Stop()
		c.rollback = nil
	}
	return nil
}
stopRollback is used to stop running the rollback manager before sealing
package vault
import (
	"strings"
	"sync"
	"time"
	log "github.com/mgutz/logxi/v1"
	"github.com/armon/go-metrics"
	"github.com/hashicorp/vault/logical"
)
const (
	rollbackPeriod = time.Minute
)
type RollbackManager struct {
	logger log.Logger
	backends func() []*MountEntry
	router *Router
	period time.Duration
	inflightAll  sync.WaitGroup
	inflight     map[string]*rollbackState
	inflightLock sync.RWMutex
	doneCh       chan struct{}
	shutdown     bool
	shutdownCh   chan struct{}
	shutdownLock sync.Mutex
}
type rollbackState struct {
	lastError error
	sync.WaitGroup
}
func NewRollbackManager(logger log.Logger, backendsFunc func() []*MountEntry, router *Router) *RollbackManager {
	r := &RollbackManager{
		logger:     logger,
		backends:   backendsFunc,
		router:     router,
		period:     rollbackPeriod,
		inflight:   make(map[string]*rollbackState),
		doneCh:     make(chan struct{}),
		shutdownCh: make(chan struct{}),
	}
	return r
}
func (m *RollbackManager) Start() {
	go m.run()
}
func (m *RollbackManager) Stop() {
	m.shutdownLock.Lock()
	defer m.shutdownLock.Unlock()
	if !m.shutdown {
		m.shutdown = true
		close(m.shutdownCh)
		<-m.doneCh
	}
	m.inflightAll.Wait()
}
func (m *RollbackManager) run() {
	m.logger.Info("rollback: starting rollback manager")
	tick := time.NewTicker(m.period)
	defer tick.Stop()
	defer close(m.doneCh)
	for {
		select {
		case <-tick.C:
			m.triggerRollbacks()
		case <-m.shutdownCh:
			m.logger.Info("rollback: stopping rollback manager")
			return
		}
	}
}
func (m *RollbackManager) triggerRollbacks() {
	backends := m.backends()
	for _, e := range backends {
		path := e.Path
		if e.Table == credentialTableType {
			path = "auth/" + path
		}
		m.inflightLock.RLock()
		_, ok := m.inflight[path]
		m.inflightLock.RUnlock()
		if !ok {
			m.startRollback(path)
		}
	}
}
func (m *RollbackManager) startRollback(path string) *rollbackState {
	rs := &rollbackState{}
	rs.Add(1)
	m.inflightAll.Add(1)
	m.inflightLock.Lock()
	m.inflight[path] = rs
	m.inflightLock.Unlock()
	go m.attemptRollback(path, rs)
	return rs
}
func (m *RollbackManager) attemptRollback(path string, rs *rollbackState) (err error) {
	defer metrics.MeasureSince([]string{"rollback", "attempt", strings.Replace(path, "/", "-", -1)}, time.Now())
	if m.logger.IsDebug() {
		m.logger.Debug("rollback: attempting rollback", "path", path)
	}
	defer func() {
		rs.lastError = err
		rs.Done()
		m.inflightAll.Done()
		m.inflightLock.Lock()
		delete(m.inflight, path)
		m.inflightLock.Unlock()
	}()
	req := &logical.Request{
		Operation: logical.RollbackOperation,
		Path:      path,
	}
	_, err = m.router.Route(req)
	if err == logical.ErrUnsupportedOperation {
		err = nil
	}
	if err != nil {
		m.logger.Error("rollback: error rolling back", "path", path, "error", err)
	}
	return
}
func (m *RollbackManager) Rollback(path string) error {
	m.inflightLock.RLock()
	rs, ok := m.inflight[path]
	m.inflightLock.RUnlock()
	if !ok {
		rs = m.startRollback(path)
	}
	rs.Wait()
	return rs.lastError
}
func (c *Core) startRollback() error {
	backendsFunc := func() []*MountEntry {
		ret := []*MountEntry{}
		c.mountsLock.RLock()
		defer c.mountsLock.RUnlock()
		if c.mounts != nil {
			for _, entry := range c.mounts.Entries {
				ret = append(ret, entry)
			}
		}
		c.authLock.RLock()
		defer c.authLock.RUnlock()
		if c.auth != nil {
			for _, entry := range c.auth.Entries {
				ret = append(ret, entry)
			}
		}
		return ret
	}
	c.rollback = NewRollbackManager(c.logger, backendsFunc, c.router)
	c.rollback.Start()
	return nil
}