Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show shards gives empty expiry time for inf duration shards #21795

Merged
merged 1 commit into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- [#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
- [#21792](https://github.com/influxdata/influxdb/pull/21792): fix: error instead of panic for statement rewrite failure
- [#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