Skip to content

Commit

Permalink
fix: show shards gives empty expiry time for inf duration shards
Browse files Browse the repository at this point in the history
  • Loading branch information
lesam committed Jul 6, 2021
1 parent 639527c commit 5b54a66
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
- [#21666](https://github.com/influxdata/influxdb/pull/21666): fix: do not panic on cleaning up failed iterators
- [#21693](https://github.com/influxdata/influxdb/pull/21693): fix: don't access a field in a nil struct
- [#21558](https://github.com/influxdata/influxdb/pull/21558): fix: do not send non-UTF-8 characters to subscriptions
- [#21750](https://github.com/influxdata/influxdb/pull/21750): fix: rename arm rpms with yum-compatible names
- [#21777](https://github.com/influxdata/influxdb/pull/21777): fix: convert arm arch names for rpms during builds via docker
- [#21750](https://github.com/influxdata/influxdb/pull/21750): fix: rename arm rpms with yum-compatible names
- [#21777](https://github.com/influxdata/influxdb/pull/21777): fix: convert arm arch names for rpms during builds via docker
- [#21795](https://github.com/influxdata/influxdb/pull/21795): fix: show shards gives empty expiry time for inf duration shards

v1.9.2 [unreleased]
- [#21631](https://github.com/influxdata/influxdb/pull/21631): fix: group by returns multiple results per group in some circumstances
Expand Down
7 changes: 5 additions & 2 deletions coordinator/statement_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,15 +810,18 @@ func (e *StatementExecutor) executeShowShardsStatement(stmt *influxql.ShowShards
for i, owner := range si.Owners {
ownerIDs[i] = owner.NodeID
}

expiry := ""
if rpi.Duration != 0 {
expiry = sgi.EndTime.Add(rpi.Duration).UTC().Format(time.RFC3339)
}
row.Values = append(row.Values, []interface{}{
si.ID,
di.Name,
rpi.Name,
sgi.ID,
sgi.StartTime.UTC().Format(time.RFC3339),
sgi.EndTime.UTC().Format(time.RFC3339),
sgi.EndTime.Add(rpi.Duration).UTC().Format(time.RFC3339),
expiry,
joinUint64(ownerIDs),
})
}
Expand Down
41 changes: 41 additions & 0 deletions tests/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,11 @@ func TestServer_Query_DefaultDBAndRP(t *testing.T) {
command: `show retention policies ON db0`,
exp: `{"results":[{"statement_id":0,"series":[{"columns":["name","duration","shardGroupDuration","replicaN","default"],"values":[["autogen","0s","168h0m0s",1,false],["rp0","0s","168h0m0s",1,true]]}]}]}`,
},
&Query{
name: "show shards works",
command: `show shards`,
exp: `{"results":[{"statement_id":0,"series":[{"name":"db0","columns":["id","database","retention_policy","shard_group","start_time","end_time","expiry_time","owners"],"values":[[1,"db0","rp0",1,"1999-12-27T00:00:00Z","2000-01-03T00:00:00Z","",""]]}]}]}`,
},
&Query{
name: "default rp",
command: `SELECT * FROM db0..cpu GROUP BY *`,
Expand Down Expand Up @@ -851,6 +856,42 @@ func TestServer_Query_DefaultDBAndRP(t *testing.T) {
}
}

func TestServer_ShowShardsNonInf(t *testing.T) {
t.Parallel()
s := OpenServer(NewConfig())
defer s.Close()

if err := s.CreateDatabaseAndRetentionPolicy("db0", NewRetentionPolicySpec("rp0", 1, 1000000*time.Hour), true); err != nil {
t.Fatal(err)
}

points := []string{
"cpu,host=server01 value=100 1621440001000000000",
}
if _, err := s.Write("db0", "rp0", strings.Join(points, "\n"), nil); err != nil {
t.Fatal("unexpected error: ", err)
}

if err := s.CreateDatabaseAndRetentionPolicy("db0", NewRetentionPolicySpec("rp1", 1, 0), true); err != nil {
t.Fatal(err)
}
if _, err := s.Write("db0", "rp1", strings.Join(points, "\n"), nil); err != nil {
t.Fatal("unexpected error: ", err)
}

// inf shard has no expiry_time, shard with expiry has correct expiry_time
exp := `{"results":[{"statement_id":0,"series":[{"name":"db0","columns":` +
`["id","database","retention_policy","shard_group","start_time","end_time","expiry_time","owners"],"values":[` +
`[1,"db0","rp0",1,"2021-05-17T00:00:00Z","2021-05-24T00:00:00Z","2135-06-22T16:00:00Z",""],` +
`[2,"db0","rp1",2,"2021-05-17T00:00:00Z","2021-05-24T00:00:00Z","",""]]}]}]}`
// Verify the data was written.
if res, err := s.Query(`show shards`); err != nil {
t.Fatal(err)
} else if exp != res {
t.Fatalf("unexpected results\nexp: %s\ngot: %s\n", exp, res)
}
}

// Ensure the server can have a database with multiple measurements.
func TestServer_Query_Multiple_Measurements(t *testing.T) {
t.Parallel()
Expand Down

0 comments on commit 5b54a66

Please sign in to comment.