// attemptRollback invokes a RollbackOperation for the given path
346415
func (m *RollbackManager) attemptRollback(ctx context.Context, fullPath string, rs *rollbackState, grabStatelock bool) (err error) {
	defer metrics.MeasureSince([]string{"rollback", "attempt", strings.Replace(fullPath, "/", "-", -1)}, time.Now())
	if m.logger.IsDebug() {
		m.logger.Debug("attempting rollback", "path", fullPath)
	}

	defer func() {
		rs.lastError = err
		rs.Done()
		m.inflightAll.Done()
		m.inflightLock.Lock()
		delete(m.inflight, fullPath)
		m.inflightLock.Unlock()
	}()

	ns, err := namespace.FromContext(ctx)
	if err != nil {
		return err
	}
	if ns == nil {
		return namespace.ErrNoNamespace
	}

	// Invoke a RollbackOperation
	req := &logical.Request{
		Operation: logical.RollbackOperation,
		Path:      ns.TrimmedPath(fullPath),
	}

	releaseLock := true
	if grabStatelock {
		doneCh := make(chan struct{})
		defer close(doneCh)

		stopCh := make(chan struct{})
		go func() {
			defer close(stopCh)

			select {
			case <-m.shutdownCh:
			case <-rs.cancelLockGrabCtx.Done():
			case <-doneCh:
			}
		}()

		// Grab the statelock or stop
		if stopped := grabLockOrStop(m.core.stateLock.RLock, m.core.stateLock.RUnlock, stopCh); stopped {
			// If we stopped due to shutdown, return. Otherwise another thread
			// is holding the lock for us, continue on.
			select {
			case <-m.shutdownCh:
				return errors.New("rollback shutting down")
			default:
				releaseLock = false
			}
		}
	}

	var cancelFunc context.CancelFunc
	ctx, cancelFunc = context.WithTimeout(ctx, DefaultMaxRequestDuration)
	_, err = m.router.Route(ctx, req)
	if grabStatelock && releaseLock {
		m.core.stateLock.RUnlock()
	}
	cancelFunc()

	// If the error is an unsupported operation, then it doesn't
	// matter, the backend doesn't support it.
	if err == logical.ErrUnsupportedOperation {
		err = nil
	}
	// If we failed due to read-only storage, we can't do anything; ignore
	if err != nil && strings.Contains(err.Error(), logical.ErrReadOnly.Error()) {
		err = nil
	}
	if err != nil {
		m.logger.Error("error rolling back", "path", fullPath, "error", err)
	}
	return
}
15686
func (tx *Tx) RollbackEx(ctx context.Context) error {
	if tx.status != TxStatusInProgress {
		return ErrTxClosed
	}

	_, tx.err = tx.conn.ExecEx(ctx, "rollback", nil)
	if tx.err == nil {
		tx.status = TxStatusRollbackSuccess
	} else {
		tx.status = TxStatusRollbackFailure
		// A rollback failure leaves the connection in an undefined state
		tx.conn.die(errors.New("rollback failed"))
	}

	if tx.connPool != nil {
		tx.connPool.Release(tx.conn)
	}

	return tx.err
}
45056
func (tree *MutableTree) Rollback() {
	if tree.version > 0 {
		tree.ImmutableTree = tree.lastSaved.clone()
	} else {
		tree.ImmutableTree = &ImmutableTree{ndb: tree.ndb, version: 0}
	}
	tree.orphans = map[string]int64{}
}
1311852
func (mp *Proxy) Rollback(ctx context.Context, session *ProxySession) error {
	return mp.doRollback(ctx, session)
}
1108837
func (f *Facade) Rollback(ctx datastore.Context, snapshotID string, force bool) error {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.Rollback"))
	// Do not DFSLock here, ControlPlaneDao does that
	logger := plog.WithField("snapshotid", snapshotID)
	logger.Infof("Started rollback of snapshot")
	info, err := f.dfs.Info(snapshotID)
	if err != nil {
		logger.WithError(err).Debug("Could not get info for snapshot")
		return err
	}
	logger = logger.WithField("tenantid", info.TenantID)
	if err := f.lockTenant(ctx, info.TenantID); err != nil {
		logger.WithError(err).Debug("Could not lock tenant")
		return err
	}
	defer f.retryUnlockTenant(ctx, info.TenantID, nil, time.Second)
	logger.Info("Got tenant lock")
	svcs, err := f.GetServices(ctx, dao.ServiceRequest{TenantID: info.TenantID})
	if err != nil {
		logger.WithError(err).Debug("Could not get services under tenant")
		return err
	}
	serviceids := make([]string, len(svcs))
	servicesToStop := []*service.Service{}
	var stoppedServiceIds []string
	for i, _ := range svcs {
		svc := &svcs[i]
		if svc.DesiredState == int(service.SVCRun) {
			servicesToStop = append(servicesToStop, svc)
			stoppedServiceIds = append(stoppedServiceIds, svc.ID)
			if !force {
				logger.WithFields(logrus.Fields{
					"servicename": svc.Name,
					"serviceid":   svc.ID,
				}).Debug("Could not rollback to snapshot; service is running")
				return errors.New("service is running")
			}
		}
		serviceids[i] = svc.ID
	}

	// Stop the services that need stopping in a batch
	if _, err := scheduleServices(f, servicesToStop, ctx, info.TenantID, service.SVCStop, false); err != nil {
		logger.WithError(err).Debug("Could not stop services for rollback")
		return err
	}

	defer func() {
		// Refresh service objects in case something has changed (like current state)
		servicesToStop = f.GetServicesForScheduling(ctx, stoppedServiceIds)
		scheduleServices(f, servicesToStop, ctx, info.TenantID, service.SVCRun, false)
	}()

	if err := f.WaitService(ctx, service.SVCStop, f.dfs.Timeout(), false, serviceids...); err != nil {
		logger.WithError(err).Debug("Could not wait for services to stop during rollback of snapshot")
		return err
	}
	logger.Info("Services are all stopped")
	if err := f.RestoreServices(ctx, info.TenantID, info.Services); err != nil {
		logger.WithError(err).Debug("Could not restore services")
		return err
	}
	logger.Infof("Service data is rolled back")
	if err := f.dfs.Rollback(snapshotID); err != nil {
		logger.WithError(err).Debug("Could not rollback snapshot")
		return err
	}
	logger.Info("Successfully restored application data from snapshot")
	return nil
}
1193218
func (u *UpdateJob) RollbackOnFail(rollback bool) *UpdateJob {
	u.req.Settings.RollbackOnFailure = rollback
	return u
}
487275
func (q *query) Rollback(ctx context.Context, request *querypb.RollbackRequest) (response *querypb.RollbackResponse, err error) {
	defer q.server.HandlePanic(&err)
	ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx),
		request.EffectiveCallerId,
		request.ImmediateCallerId,
	)
	if err := q.server.Rollback(ctx, request.Target, request.TransactionId); err != nil {
		return nil, vterrors.ToGRPC(err)
	}

	return &querypb.RollbackResponse{}, nil
}
732775
func (s *Service) ReleaseRollback(ctx context.Context, appIdentity string, o ReleaseRollbackOpts) (*Release, error) {
	var release Release
	return &release, s.Post(ctx, &release, fmt.Sprintf("/apps/%v/releases", appIdentity), o)
}
1225664
func MigrateRollback(currpath, driver, connStr, dir string) {
	migrate("rollback", currpath, driver, connStr, dir)
}
1330048
func (q *Qbs) Rollback() error {
	err := q.tx.Rollback()
	q.tx = nil
	for _, v := range q.txStmtMap {
		v.Close()
	}
	q.txStmtMap = nil
	return q.updateTxError(err)
}
229923
func (tx *Tx) Rollback() error {
	err := tx.Tx.Rollback()
	if err != nil {
		return tx.EventErr("dbr.rollback", err)
	}
	tx.Event("dbr.rollback")
	return nil
}
229419
func (transaction *Transaction) Rollback() error {
	var (
		cErr *C.char
	)
	C.rocksdb_transaction_rollback(transaction.c, &cErr)

	if cErr != nil {
		defer C.free(unsafe.Pointer(cErr))
		return errors.New(C.GoString(cErr))
	}
	return nil
}
1269870
func (f *jsonFileTransaction) Rollback() error {
	f.f.G().Log.Debug("+ Rolling back %s to state from %s", f.f.which, f.f.filename)
	err := f.f.Load(false)
	if !f.f.exists {
		// Before transaction there was no file, so set in-memory
		// wrapper to clean state as well.
		f.f.jw = jsonw.NewDictionary()
		f.f.G().Log.Debug("+ Rolling back to clean state because f.exists is false")
	}
	f.f.G().Log.Debug("- Rollback -> %s", ErrToOk(err))
	return err
}
190989
func (np *Netplan) Rollback() (err error) {
	if np.writtenFile != "" {
		os.Remove(np.writtenFile)
	}
	for oldFile, newFile := range np.backedFiles {
		err = os.Rename(newFile, oldFile)
		if err != nil {
			logger.Errorf("Cannot rename %s to %s - %q", newFile, oldFile, err.Error())
		}
	}
	np.backedFiles = nil
	np.writtenFile = ""
	return nil
}
1346978
func (dao *ControlPlaneDao) Rollback(req model.RollbackRequest, _ *int) (err error) {
	ctx := datastore.Get()

	// synchronize the dfs
	dfslocker := dao.facade.DFSLock(ctx)
	dfslocker.Lock("rollback")
	defer dfslocker.Unlock()
	err = dao.facade.Rollback(ctx, req.SnapshotID, req.ForceRestart)
	return
}
893455
func (a *api) Rollback(snapshotID string, forceRestart bool) error {
	client, err := a.connectDAO()
	if err != nil {
		return err
	}

	if err := client.Rollback(dao.RollbackRequest{snapshotID, forceRestart}, &unusedInt); err != nil {
		return err
	}

	return nil
}
1028260
func (mr *MockTransactionalMockRecorder) Rollback(arg0 interface{}) *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Rollback", reflect.TypeOf((*MockTransactional)(nil).Rollback), arg0)
}