Skip to content

Commit

Permalink
Fix running multiple CQs with the same name
Browse files Browse the repository at this point in the history
Previously, CQs with the same name would be stored in the last run map
the same way. This caused only one of the CQs to run because after the
first one ran it would update the last run time for all CQs with the
same name.

Add the database name to the CQ ID in the last run map to differentiate
between CQs in different databases.

Fixes #5814.
  • Loading branch information
jsternberg committed Feb 24, 2016
1 parent 60e0d16 commit 0730573
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
- [#5754](https://github.com/influxdata/influxdb/issues/5754): Adding a node as meta only results in a data node also being registered
- [#5787](https://github.com/influxdata/influxdb/pull/5787): HTTP: Add QueryAuthorizer instance to httpd service’s handler. @chris-ramon
- [#5753](https://github.com/influxdata/influxdb/pull/5753): ensures that drop-type commands work correctly in a cluster
- [#5814](https://github.com/influxdata/influxdb/issues/5814): Run CQs with the same name from different databases

## v0.10.1 [2016-02-18]

Expand Down
10 changes: 6 additions & 4 deletions services/continuous_querier/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ func (s *Service) Run(database, name string, t time.Time) error {
for _, cq := range db.ContinuousQueries {
if name == "" || cq.Name == name {
// Remove the last run time for the CQ
if _, ok := s.lastRuns[cq.Name]; ok {
delete(s.lastRuns, cq.Name)
id := fmt.Sprintf("%s:%s", db.Name, cq.Name)
if _, ok := s.lastRuns[id]; ok {
delete(s.lastRuns, id)
}
}
}
Expand Down Expand Up @@ -260,7 +261,8 @@ func (s *Service) ExecuteContinuousQuery(dbi *meta.DatabaseInfo, cqi *meta.Conti
// Get the last time this CQ was run from the service's cache.
s.mu.Lock()
defer s.mu.Unlock()
cq.LastRun, cq.HasRun = s.lastRuns[cqi.Name]
id := fmt.Sprintf("%s:%s", dbi.Name, cqi.Name)
cq.LastRun, cq.HasRun = s.lastRuns[id]

// Set the retention policy to default if it wasn't specified in the query.
if cq.intoRP() == "" {
Expand Down Expand Up @@ -291,7 +293,7 @@ func (s *Service) ExecuteContinuousQuery(dbi *meta.DatabaseInfo, cqi *meta.Conti
// We're about to run the query so store the current time closest to the nearest interval.
// If all is going well, this time should be the same as nextRun.
cq.LastRun = now.Truncate(resampleEvery)
s.lastRuns[cqi.Name] = cq.LastRun
s.lastRuns[id] = cq.LastRun

// Retrieve the oldest interval we should calculate based on the next time
// interval. We do this instead of using the current time just in case any
Expand Down

0 comments on commit 0730573

Please sign in to comment.