// DetachCondAndBuildRangeForIndex will detach the index filters from table filters.
// The returned values are encapsulated into a struct DetachRangeResult, see its comments for explanation.
966516
func DetachCondAndBuildRangeForIndex(sctx sessionctx.Context, conditions []expression.Expression, cols []*expression.Column,
	lengths []int) (*DetachRangeResult, error) {
	res := &DetachRangeResult{}
	newTpSlice := make([]*types.FieldType, 0, len(cols))
	for _, col := range cols {
		newTpSlice = append(newTpSlice, newFieldType(col.RetType))
	}
	if len(conditions) == 1 {
		if sf, ok := conditions[0].(*expression.ScalarFunction); ok && sf.FuncName.L == ast.LogicOr {
			ranges, accesses, hasResidual, err := detachDNFCondAndBuildRangeForIndex(sctx, sf, cols, newTpSlice, lengths)
			if err != nil {
				return res, errors.Trace(err)
			}
			res.Ranges = ranges
			res.AccessConds = accesses
			res.IsDNFCond = true
			// If this DNF have something cannot be to calculate range, then all this DNF should be pushed as filter condition.
			if hasResidual {
				res.RemainedConds = conditions
				return res, nil
			}
			return res, nil
		}
	}
	return detachCNFCondAndBuildRangeForIndex(sctx, conditions, cols, newTpSlice, lengths, true)
}
91201
func (c Client) Detach(id string, params *stripe.SourceObjectDetachParams) (*stripe.Source, error) {
	if params.Customer == nil {
		return nil, errors.New("Invalid source detach params: Customer needs to be set")
	}

	path := stripe.FormatURLPath("/v1/customers/%s/sources/%s",
		stripe.StringValue(params.Customer), id)
	source := &stripe.Source{}
	err := c.B.Call(http.MethodDelete, path, c.Key, params, source)
	return source, err
}
511895
func (v *volumeClient) Detach(volumeID string, options map[string]string) error {
	return v.doVolumeSet(
		volumeID,
		&api.VolumeSetRequest{
			Action: &api.VolumeStateAction{
				Attach: api.VolumeActionParam_VOLUME_ACTION_PARAM_OFF,
			},
			Options: options,
		},
	)
}
845926
func detachColumnDNFConditions(sctx sessionctx.Context, conditions []expression.Expression, checker *conditionChecker) ([]expression.Expression, bool) {
	var (
		hasResidualConditions bool
		accessConditions      []expression.Expression
	)
	for _, cond := range conditions {
		if sf, ok := cond.(*expression.ScalarFunction); ok && sf.FuncName.L == ast.LogicAnd {
			cnfItems := expression.FlattenCNFConditions(sf)
			columnCNFItems, others := detachColumnCNFConditions(sctx, cnfItems, checker)
			if len(others) > 0 {
				hasResidualConditions = true
			}
			// If one part of DNF has no access condition. Then this DNF cannot get range.
			if len(columnCNFItems) == 0 {
				return nil, true
			}
			rebuildCNF := expression.ComposeCNFCondition(sctx, columnCNFItems...)
			accessConditions = append(accessConditions, rebuildCNF)
		} else if checker.check(cond) {
			accessConditions = append(accessConditions, cond)
			if checker.shouldReserve {
				hasResidualConditions = true
				checker.shouldReserve = checker.length != types.UnspecifiedLength
			}
		} else {
			return nil, true
		}
	}
	return accessConditions, hasResidualConditions
}
5516
func (s *BatchWriteOperation) SetAttachToIndex(v *BatchAttachToIndex) *BatchWriteOperation {
	s.AttachToIndex = v
	return s
}
837085
func (m *loopDeviceManager) DetachLoopDevices(rootfs, prefix string) error {
	logger.Debugf("detaching loop devices inside %q", rootfs)
	loopDevices, err := loopDevices(m.run)
	if err != nil {
		return errors.Annotate(err, "listing loop devices")
	}

	for _, info := range loopDevices {
		logger.Debugf("checking loop device: %v", info)
		if !strings.HasPrefix(info.backingFile, prefix) {
			continue
		}
		if info.backingInode == 0 {
			continue
		}
		rootedBackingFile := path.Join(rootfs, info.backingFile)
		st, err := m.stat(rootedBackingFile)
		if os.IsNotExist(err) {
			continue
		} else if err != nil {
			return errors.Annotate(err, "querying backing file")
		}
		if m.inode(st) != info.backingInode {
			continue
		}
		logger.Debugf("detaching loop device %q", info.name)
		if err := detachLoopDevice(m.run, info.name); err != nil {
			return errors.Trace(err)
		}
	}
	return nil
}
1169324
func (s *StateStore) RemoveIndex(name string) error {
	txn := s.db.Txn(true)
	defer txn.Abort()

	if _, err := txn.DeleteAll("index", "id", name); err != nil {
		return err
	}

	txn.Commit()
	return nil
}
1372198
func (s *Store) RemoveIndex(dataType interface{}, indexName string) error {
	storer := newStorer(dataType)
	return s.Bolt().Update(func(tx *bolt.Tx) error {
		return tx.DeleteBucket(indexBucketName(storer.Type(), indexName))

	})
}
635007
func (s *oracleVolumeSource) DetachVolumes(ctx context.ProviderCallContext, params []storage.VolumeAttachmentParams) ([]error, error) {
	attachAsMap, err := s.getStorageAttachments()
	if err != nil {
		return nil, errors.Trace(err)
	}
	toDelete := make([]string, len(params))
	ret := make([]error, len(params))
	for i, val := range params {
		found := false
		for _, attach := range attachAsMap[string(val.InstanceId)] {
			if val.VolumeId == attach.Storage_volume_name {
				toDelete[i] = attach.Name
				found = true
			}
		}
		if !found {
			toDelete[i] = ""
			ret[i] = errors.NotFoundf(
				"volume attachment for instance %v and volumeID %v not found",
				val.InstanceId, val.VolumeId)
		}
	}
	for i, val := range toDelete {
		if val == "" {
			continue
		}
		ret[i] = s.api.DeleteStorageAttachment(val)
	}
	return ret, nil
}
144612
func (i Indexes) RemoveOlderThan(layout, alias string, n int, now time.Time) []byte {
	var actions Actions

	for index := range i.MatchingOlderThan(layout, n, now) {
		action := Action{}
		action.Remove.Alias = alias
		action.Remove.Index = index
		actions.Actions = append(actions.Actions, action)
	}

	if len(actions.Actions) == 0 {
		return nil
	}

	b, _ := json.Marshal(actions)
	return b
}
1190642
func (f *FlatReactor) Detach(rm Reactor) {
	f.enders.Disable(rm)
	f.branches.Disable(rm)
}
338057
func (r *View) indexDestructive(needle []byte) bool {
	tbuf := make([]byte, 2*len(needle))
	idx := int64(0)
	for {
		data := r.chunkBytes()
		if len(data) == 0 {
			return false
		}

		// Scan the current chunk for needle. Note that if the current chunk is too
		// small to hold needle, this is a no-op.
		if idx = int64(bytes.Index(data, needle)); idx >= 0 {
			r.Skip(idx)
			return true
		}
		if len(data) > len(needle) {
			// The needle is definitely not in this space.
			r.Skip(int64(len(data) - len(needle)))
		}

		// needle isn't in the current chunk; however, it may begin at the end of
		// the current chunk and complete in future chunks.
		//
		// We will scan a space twice the size of the needle, as otherwise, this
		// would end up scanning for one possibility, incrementing by one, and
		// repeating via 'for' loop iterations.
		//
		// Afterwards, we advance only the size of the needle, as we don't want to
		// preclude the needle starting after our last scan range.
		//
		// For example, to find needle "NDL":
		//
		// AAAAND|L|AAAA
		//     |------|^- [NDLAAA], 0
		//
		// AAAAN|D|NDL|AAAA
		//    |------| [ANDNDL], 3
		//
		// AAAA|A|A|NDL
		//   |-------| [AAAAND], -1, consume 3 => A|NDL|
		//
		//
		// Note that we perform the read with a cloned View so we don't
		// actually consume this data.
		pr := r.Clone()
		amt, _ := pr.Read(tbuf)
		if amt < len(needle) {
			// All remaining buffers cannot hold the needle.
			return false
		}

		if idx = int64(bytes.Index(tbuf[:amt], needle)); idx >= 0 {
			r.Skip(idx)
			return true
		}
		r.Skip(int64(len(needle)))
	}
}
817117
func (b *BlockChain) removeOrphanBlock(orphan *orphanBlock) {
	// Protect concurrent access.
	b.orphanLock.Lock()
	defer b.orphanLock.Unlock()

	// Remove the orphan block from the orphan pool.
	orphanHash := orphan.block.Hash()
	delete(b.orphans, *orphanHash)

	// Remove the reference from the previous orphan index too.  An indexing
	// for loop is intentionally used over a range here as range does not
	// reevaluate the slice on each iteration nor does it adjust the index
	// for the modified slice.
	prevHash := &orphan.block.MsgBlock().Header.PrevBlock
	orphans := b.prevOrphans[*prevHash]
	for i := 0; i < len(orphans); i++ {
		hash := orphans[i].block.Hash()
		if hash.IsEqual(orphanHash) {
			copy(orphans[i:], orphans[i+1:])
			orphans[len(orphans)-1] = nil
			orphans = orphans[:len(orphans)-1]
			i--
		}
	}
	b.prevOrphans[*prevHash] = orphans

	// Remove the map entry altogether if there are no longer any orphans
	// which depend on the parent hash.
	if len(b.prevOrphans[*prevHash]) == 0 {
		delete(b.prevOrphans, *prevHash)
	}
}
982053
func (dbclient *CouchDatabase) WarmIndexAllIndexes() error {

	logger.Debugf("[%s] Entering WarmIndexAllIndexes()", dbclient.DBName)

	//Retrieve all indexes
	listResult, err := dbclient.ListIndex()
	if err != nil {
		return err
	}

	//For each index definition, execute an index refresh
	for _, elem := range listResult {

		err := dbclient.WarmIndex(elem.DesignDocument, elem.Name)
		if err != nil {
			return err
		}

	}

	logger.Debugf("[%s] Exiting WarmIndexAllIndexes()", dbclient.DBName)

	return nil

}
789357
func parseStandardIndex(indexSpec string) (*mgo.Index, error) {

	key := parseIndexKey(indexSpec)

	if key == "" {
		// invalid key format, was not parsed successfully
		return nil, errors.New("Standard key not of format: <key>_(-)1")
	}

	return &mgo.Index{
		Key: []string{key},
	}, nil
}
893596
func (dbclient *CouchDatabase) DeleteIndex(designdoc, indexname string) error {
	dbName := dbclient.DBName

	logger.Debugf("[%s] Entering DeleteIndex()  designdoc=%s  indexname=%s", dbName, designdoc, indexname)

	indexURL, err := url.Parse(dbclient.CouchInstance.conf.URL)
	if err != nil {
		logger.Errorf("URL parse error: %s", err)
		return errors.Wrapf(err, "error parsing CouchDB URL: %s", dbclient.CouchInstance.conf.URL)
	}

	//get the number of retries
	maxRetries := dbclient.CouchInstance.conf.MaxRetries

	resp, _, err := dbclient.handleRequest(http.MethodDelete, "DeleteIndex", indexURL, nil, "", "", maxRetries, true, nil, "_index", designdoc, "json", indexname)
	if err != nil {
		return err
	}
	defer closeResponseBody(resp)

	return nil

}
1288890
func (v *volumeSource) DetachVolumes(ctx context.ProviderCallContext, attachParams []storage.VolumeAttachmentParams) ([]error, error) {
	// noop
	return make([]error, len(attachParams)), nil
}