// DropSeries drops the provided series from the index.  If cascade is true
// and this is the last series to the measurement, the measurment will also be dropped.
507544
func (i *Index) DropSeries(seriesID tsdb.SeriesID, key []byte, cascade bool) error {
	// Remove from partition.
	if err := i.partition(key).DropSeries(seriesID); err != nil {
		return err
	}

	if !cascade {
		return nil
	}

	// Extract measurement name & tags.
	name, tags := models.ParseKeyBytes(key)

	// If there are cached sets for any of the tag pairs, they will need to be
	// updated with the series id.
	i.tagValueCache.RLock()
	if i.tagValueCache.measurementContainsSets(name) {
		for _, pair := range tags {
			i.tagValueCache.delete(name, pair.Key, pair.Value, seriesID) // Takes a lock on the series id set
		}
	}
	i.tagValueCache.RUnlock()

	// Check if that was the last series for the measurement in the entire index.
	if ok, err := i.MeasurementHasSeries(name); err != nil {
		return err
	} else if ok {
		return nil
	}

	// If no more series exist in the measurement then delete the measurement.
	if err := i.DropMeasurement(name); err != nil {
		return err
	}
	return nil
}
684740
func (m *DbMap) DropTables() error {
	var err error
	for i := range m.tables {
		table := m.tables[i]
		_, e := m.Exec(fmt.Sprintf("drop table %s;", m.Dialect.QuoteField(table.TableName)))
		if e != nil {
			err = e
		}
	}
	return err
}
346443
func (m *Manager) ToMetricSeries(ctx context.Context, series []types.BasePerfEntityMetricBase) ([]EntityMetric, error) {
	counters, err := m.CounterInfoByKey(ctx)
	if err != nil {
		return nil, err
	}

	var result []EntityMetric

	for i := range series {
		var values []MetricSeries
		s, ok := series[i].(*types.PerfEntityMetric)
		if !ok {
			panic(fmt.Errorf("expected type %T, got: %T", s, series[i]))
		}

		for j := range s.Value {
			v := s.Value[j].(*types.PerfMetricIntSeries)

			values = append(values, MetricSeries{
				Name:     counters[v.Id.CounterId].Name(),
				unit:     counters[v.Id.CounterId].UnitInfo.GetElementDescription().Key,
				Instance: v.Id.Instance,
				Value:    v.Value,
			})
		}

		result = append(result, EntityMetric{
			Entity:     s.Entity,
			SampleInfo: s.SampleInfo,
			Value:      values,
		})
	}

	return result, nil
}
484593
func (p IndexFiles) MeasurementSeriesIDIterator(name []byte) tsdb.SeriesIDIterator {
	a := make([]tsdb.SeriesIDIterator, 0, len(p))
	for _, f := range p {
		itr := f.MeasurementSeriesIDIterator(name)
		if itr == nil {
			continue
		}
		a = append(a, itr)
	}
	return tsdb.MergeSeriesIDIterators(a...)
}
1222935
func (m *Source) DropTable(t string) error {
	delete(m.raw, t)
	delete(m.tables, t)
	names := make([]string, 0, len(m.tables))
	for tableName, _ := range m.raw {
		names = append(names, tableName)
	}
	m.tablenamelist = names
	return nil
}
225543
func (p *SeriesPartition) Series(id SeriesID) ([]byte, models.Tags) {
	key := p.SeriesKey(id)
	if key == nil {
		return nil, nil
	}
	return ParseSeriesKey(key)
}
936788
func (s *SeriesCollection) ApplyConcurrentDrops() {
	state := s.getState(false)
	if state == nil {
		return
	}

	length, j := s.Length(), 0
	for i := 0; i < length; i++ {
		if _, ok := state.index[i]; ok {
			s.Dropped++

			if i < len(s.Keys) {
				s.DroppedKeys = append(s.DroppedKeys, s.Keys[i])
			}

			continue
		}

		s.Copy(j, i)
		j++
	}
	s.Truncate(j)

	if s.Reason == "" {
		s.Reason = state.reason
	}

	// clear concurrent state
	atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&s.state)), nil)
}
903284
func (sdb *SeriesDB) TimeSeries(series SeriesRange, args ...interface{}) *gorm.DB {
	sdb.series = series
	sdb.args = args
	return sdb.BuildScope()
}
868910
func (u *Unit) UpgradeSeriesStatus() (model.UpgradeSeriesStatus, error) {
	res, err := u.st.UpgradeSeriesUnitStatus()
	if err != nil {
		return "", errors.Trace(err)
	}
	if len(res) != 1 {
		return "", errors.Errorf("expected 1 result, got %d", len(res))
	}
	return res[0], nil
}
152253
func NewSeriesIDExprIterator(itr SeriesIDIterator, expr influxql.Expr) SeriesIDIterator {
	if itr == nil {
		return nil
	}

	return &SeriesIDExprIterator{
		itr:  itr,
		expr: expr,
	}
}
1140184
func (engine *Engine) DropTables(beans ...interface{}) error {
	session := engine.NewSession()
	defer session.Close()

	err := session.Begin()
	if err != nil {
		return err
	}

	for _, bean := range beans {
		err = session.dropTable(bean)
		if err != nil {
			session.Rollback()
			return err
		}
	}
	return session.Commit()
}
1158639
func GetSeries(name string) (seriesList SeriesList, err error) {
	response, err := http.Get(fmt.Sprintf(GetSeriesURL, url.QueryEscape(name)))

	if err != nil {
		return
	}

	data, err := ioutil.ReadAll(response.Body)

	if err != nil {
		return
	}

	err = xml.Unmarshal(data, &seriesList)

	return
}
1093428
func (m *MonitorFormatter) dropEvents(prefix string, data []byte) {
	dn := monitor.DropNotify{}

	if err := binary.Read(bytes.NewReader(data), byteorder.Native, &dn); err != nil {
		fmt.Printf("Error while parsing drop notification message: %s\n", err)
	}
	if m.match(monitorAPI.MessageTypeDrop, dn.Source, uint16(dn.DstID)) {
		switch m.Verbosity {
		case INFO:
			dn.DumpInfo(data)
		case JSON:
			dn.DumpJSON(data, prefix)
		default:
			fmt.Println(msgSeparator)
			dn.DumpVerbose(!m.Hex, data, prefix)
		}
	}
}
279580
func ValidateSeries(modelType ModelType, charmSeries string) error {
	os, err := series.GetOSFromSeries(charmSeries)
	if err != nil {
		return errors.Trace(err)
	}
	switch modelType {
	case CAAS:
		if !caasOS.Contains(os.String()) {
			return errors.NotValidf("series %q in a kubernetes model", charmSeries)
		}
	case IAAS:
		if caasOS.Contains(os.String()) {
			return errors.NotValidf("series %q in a non container model", charmSeries)
		}
	}
	return nil
}
433070
func (m *logMeasurement) seriesIDs() []tsdb.SeriesID {
	a := make([]tsdb.SeriesID, 0, m.cardinality())
	if m.seriesSet != nil {
		m.seriesSet.ForEachNoLock(func(id tsdb.SeriesID) { a = append(a, id) })
		return a // IDs are already sorted.
	}

	for seriesID := range m.series {
		a = append(a, seriesID)
	}
	sort.Slice(a, func(i, j int) bool { return a[i].Less(a[j]) })
	return a
}
1161738
func (d *Databases) DropDB(ctx context.Context, db string) error {
	return d.DropDBF(ctx, db)
}
84492
func (i *Index) measurementSeriesIDIterator(name []byte) (tsdb.SeriesIDIterator, error) {
	itrs := make([]tsdb.SeriesIDIterator, 0, len(i.partitions))
	for _, p := range i.partitions {
		itr, err := p.MeasurementSeriesIDIterator(name)
		if err != nil {
			tsdb.SeriesIDIterators(itrs).Close()
			return nil, err
		} else if itr != nil {
			itrs = append(itrs, itr)
		}
	}
	return tsdb.MergeSeriesIDIterators(itrs...), nil
}