Repository: influxdata/influxdb
File: tsdb/store.go (Go)

Code before:
			for idx, source := range sources {
				if measurement, ok := source.(*influxql.Measurement); ok {
					if idx == 0 {
						rp = measurement.RetentionPolicy
					} else if rp != measurement.RetentionPolicy {
						return fmt.Errorf("mixed retention policies not supported, wanted %q got %q", rp, measurement.RetentionPolicy), nil, nil, nil
					}
				} else {
					return fmt.Errorf("unsupported source type in delete %v", source), nil, nil, nil
				}
			}

			if rp != "" {
				shardFilterFn = ComposeShardFilter(shardFilterFn, byRetentionPolicy(rp))
			}
		}

		shards := s.filterShards(shardFilterFn)
		epochs := s.epochsForShards(shards)
		return nil, shards, epochs, sfile
	}

	err, shards, epochs, sfile := getEpochsAndShards()
	if err != nil && err != ErrNothingToDelete {
		return err
	} else if err == ErrNothingToDelete {
		return nil
	}

	// Limit deletes for each shard since expanding the measurement into the list
	// of series keys can be very memory intensive if run concurrently.
	limit := limiter.NewFixed(s.EngineOptions.Config.MaxConcurrentDeletes)

	return s.walkShards(shards, func(sh *Shard) error {
		// Determine list of measurements from sources.
		// Use all measurements if no FROM clause was provided.
		var names []string
		if len(sources) > 0 {
			for _, source := range sources {
				names = append(names, source.(*influxql.Measurement).Name)
			}
		} else {
			if err := sh.ForEachMeasurementName(func(name []byte) error {
				names = append(names, string(name))
				return nil
			}); err != nil {
				return err
			}
		}
		sort.Strings(names)


Review comment (suggestion):
I'm going to follow up with a commit to add error logging on the server as well here, since, we do not expose these errors except to the client handler. 

Code after:
			for idx, source := range sources {
				if measurement, ok := source.(*influxql.Measurement); ok {
					if idx == 0 {
						rp = measurement.RetentionPolicy
					} else if rp != measurement.RetentionPolicy {
						return fmt.Errorf("mixed retention policies not supported, wanted %q got %q", rp, measurement.RetentionPolicy), nil, nil, nil
					}
				} else {
					return fmt.Errorf("unsupported source type in delete %v", source), nil, nil, nil
				}
			}

			if rp != "" {
				shardFilterFn = ComposeShardFilter(shardFilterFn, byRetentionPolicy(rp))
			}
		}

		shards := s.filterShards(shardFilterFn)
		epochs := s.epochsForShards(shards)
		return nil, shards, epochs, sfile
	}

	err, shards, epochs, sfile := getEpochsAndShards()
	if err != nil && !errors.Is(err, ErrNothingToDelete) {
		s.Logger.Error("DeleteSeries failed", zap.String("error", err.Error()))
		return err
	} else if errors.Is(err, ErrNothingToDelete) {
		return nil
	}

	// Limit deletes for each shard since expanding the measurement into the list
	// of series keys can be very memory intensive if run concurrently.
	limit := limiter.NewFixed(s.EngineOptions.Config.MaxConcurrentDeletes)

	return s.walkShards(shards, func(sh *Shard) error {
		// Determine list of measurements from sources.
		// Use all measurements if no FROM clause was provided.
		var names []string
		if len(sources) > 0 {
			for _, source := range sources {
				names = append(names, source.(*influxql.Measurement).Name)
			}
		} else {
			if err := sh.ForEachMeasurementName(func(name []byte) error {
				names = append(names, string(name))
				return nil
			}); err != nil {
				return err
			}
		}
		sort.Strings(names)