// TryFallback routes the message to the configured fallback stream.
172555
func (prod *SimpleProducer) TryFallback(msg *Message) {
	if err := RouteOriginal(msg, prod.fallbackStream); err != nil {
		prod.Logger.WithError(err).Error("Failed to route to fallback")
	}
}
569798
func Callback(f func()) Streamer {
	return StreamerFunc(func(samples [][2]float64) (n int, ok bool) {
		if f != nil {
			f()
			f = nil
		}
		return 0, false
	})
}
1090090
func fallbackNewRandom(random *rand.Rand) *rand.Rand {
	// Return the passed in value if it's already not null
	if nil != random {
		return random
	}

	seed := time.Now().UnixNano()

	return rand.New(rand.NewSource(seed))
}
506756
func Rollback(c *client.Client, appID string, version int) (int, error) {
	u := fmt.Sprintf("/v1/apps/%s/releases/rollback/", appID)

	req := api.ReleaseRollback{Version: version}

	var err error
	var reqBody []byte
	if version != -1 {
		reqBody, err = json.Marshal(req)

		if err != nil {
			return -1, err
		}
	}

	body, err := c.BasicRequest("POST", u, reqBody)

	if err != nil {
		return -1, err
	}

	response := api.ReleaseRollback{}

	if err = json.Unmarshal([]byte(body), &response); err != nil {
		return -1, err
	}

	return response.Version, nil
}
1127098
func (b *Breaker) fallback(err error, fb ...Fallback) error {
	var final error
	if len(fb) == 0 {
		final = err
		b.stat.update(err, nil, false)
	} else {
		final = fb[0](err)
		b.stat.update(final, err, true)
	}

	if final != nil && b.cond(b.stat.counter) && atomic.CompareAndSwapInt32(&b.state, Closed, Open) {
		b.expiry = time.Now().Add(b.opts.Window)
		b.stat.reset(false, true)
		b.logger.Warn("breaker > open circuit: ", b.name)
	}
	return final
}
748653
func (s *releasesService) Rollback(ctx context.Context, db *gorm.DB, opts RollbackOpts) (*Release, error) {
	app, version := opts.App, opts.Version
	r, err := releasesFind(db, ReleasesQuery{App: app, Version: &version})
	if err != nil {
		return nil, err
	}

	desc := fmt.Sprintf("Rollback to v%d", version)
	desc = appendMessageToDescription(desc, opts.User, opts.Message)
	return s.CreateAndRelease(ctx, db, &Release{
		App:         app,
		Config:      r.Config,
		Slug:        r.Slug,
		Formation:   r.Formation,
		Description: desc,
	}, nil)
}
422180
func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) {
	// println(">>>>>>>>> DecFallback")
	rv := reflect.ValueOf(iv)
	if chkPtr {
		rv = f.d.ensureDecodeable(rv)
	}
	f.d.decodeValue(rv, nil, false)
	// f.d.decodeValueFallback(rv)
}
867499
func (vtg *VTGate) Rollback(ctx context.Context, request *vtgatepb.RollbackRequest) (response *vtgatepb.RollbackResponse, err error) {
	defer vtg.server.HandlePanic(&err)
	ctx = withCallerIDContext(ctx, request.CallerId)
	vtgErr := vtg.server.Rollback(ctx, request.Session)
	response = &vtgatepb.RollbackResponse{}
	if vtgErr == nil {
		return response, nil
	}
	return nil, vterrors.ToGRPC(vtgErr)
}
69651
func FallbackFormater(sl *Slog) ([]byte, error) {
	buf := Pool.Get().([]byte)
	buf = append(buf, sl.Log.Domain...)
	buf = append(buf, sep...)
	FormatTime(&buf, sl.Log.Timestamp)
	buf = append(buf, sep...)
	buf = append(buf, sl.Log.Priority.Byte()...)
	buf = append(buf, sep...)
	if len(*sl.Log.Tags) > 0 {
		buf = append(buf, []byte(sl.Log.Tags.String())...)
		buf = append(buf, sepTags...)
	}
	if sl.Log.DoDi {
		buf = append(buf, []byte(sl.Log.file)...)
		buf = append(buf, sep...)
	}
	buf = append(buf, []byte(sl.Log.FormatMessage())...)
	return buf, nil
}
1129063
func (axp *TxPool) Rollback(ctx context.Context, transactionID int64) error {
	span, ctx := trace.NewSpan(ctx, "TxPool.Rollback")
	defer span.Finish()

	conn, err := axp.Get(transactionID, "for rollback")
	if err != nil {
		return err
	}
	return axp.localRollback(ctx, conn)
}
822841
func (j *leftOuterJoiner) tryToMatch(outer chunk.Row, inners chunk.Iterator, chk *chunk.Chunk) (bool, bool, error) {
	if inners.Len() == 0 {
		return false, false, nil
	}
	j.chk.Reset()
	chkForJoin := j.chk
	if len(j.conditions) == 0 {
		chkForJoin = chk
	}

	numToAppend := chk.RequiredRows() - chk.NumRows()
	for ; inners.Current() != inners.End() && numToAppend > 0; numToAppend-- {
		j.makeJoinRowToChunk(chkForJoin, outer, inners.Current())
		inners.Next()
	}
	if len(j.conditions) == 0 {
		return true, false, nil
	}

	// reach here, chkForJoin is j.chk
	matched, err := j.filter(chkForJoin, chk, outer.Len())
	if err != nil {
		return false, false, err
	}
	return matched, false, nil
}
449670
func NewRedirectFallbackWithLogger(r Redirect, l *log.Logger) (*RedirectFallback, error) {
	u, err := url.ParseRequestURI(r.URL)
	if err != nil {
		return nil, err
	}
	return &RedirectFallback{r: r, u: u, log: l}, nil
}
203909
func (tx *Tx) tryRun(i int, fn TxFn, locked *[]*Ref) (ret interface{}, err error) {

	ret, err = nil, nil

	defer func() {
		r := recover()
		if r == retryError {
			ret, err = nil, retryError
		} else if r != nil {
			panic(r)
		}
	}()

	tx.getReadPoint()
	if i == 0 {
		tx.startPoint = tx.readPoint
		tx.startTime = time.Now()
	}

	tx.info = newTxInfo(txRunning, tx.startPoint)
	ret = fn(tx)

	// make sure no one has killed us before this point, and can't from now on
	if atomic.CompareAndSwapUint32(&tx.info.status, txRunning, txCommitting) {
		for r, calls := range tx.commutes {
			if _, ok := tx.sets[r]; ok {
				continue
			}
			_, wasEnsured := tx.ensures[r]
			tx.releaseIfEnsured(r)
			tryWriteLock(r)
			*locked = append(*locked, r)
			if wasEnsured && r.currValPoint() > tx.readPoint {
				panic(retryError)
			}

			refInfo := r.tinfo
			if refInfo != nil && refInfo != tx.info && refInfo.isRunning() {
				if !tx.barge(refInfo) {
					panic(retryError)
				}
			}
			val := r.tryGetVal()
			tx.vals[r] = val
			for _, call := range calls {
				tx.vals[r] = call.fn(tx.vals[r], call.args...)
			}
		}

		for r, _ := range tx.sets {
			tryWriteLock(r)
			*locked = append(*locked, r)
		}

		// if we do validations for refs, it goes here

		// at this point,
		//    all values are calculated,
		//    all refs to be written are locked
		//    no more client code to be called
		commitPoint := getCommitPoint()
		for r, newV := range tx.vals {
			//oldV := r.tryGetVal()
			r.setValue(newV, commitPoint)
			// todo: call notifies
		}
		atomic.StoreUint32(&tx.info.status, txCommitted)
	}

	return
}
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
}
1250874
func CompareFailed(message string, args ...interface{}) error {
	return WrapWithMessage(&CompareFailedError{Message: fmt.Sprintf(message, args...)}, message, args...)
}
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
}
1025875
func (c *client) Rollback(namespace, name string, build int, target string, params map[string]string) (*Build, error) {
	out := new(Build)
	val := mapValues(params)
	val.Set("target", target)
	uri := fmt.Sprintf(pathRollback, c.addr, namespace, name, build, val.Encode())
	err := c.post(uri, nil, out)
	return out, err
}