-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
sql: add a SHOW TENANTS command #94734
sql: add a SHOW TENANTS command #94734
Conversation
f97766d
to
62c6e2b
Compare
@@ -161,7 +161,7 @@ func alterReplicationJobHook( | |||
return err | |||
} | |||
if tenInfo.TenantReplicationJobID == 0 { | |||
return errors.Newf("tenant %q does not have an active replication job", tenantName) | |||
return errors.Newf("tenant %q is not a replicated tenant", tenantName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm is this change necessary? Tenant foo could have been created as a result of c2c replication, so it could be confusing to say that it is not a replicated tenant if the job ID is 0. IMO it is sufficient to say that there is no active replication job associated with this tenant and so the replication information you are trying to access is unavailable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not necessary in this pr, dropping.
FWIW I think we should avoid saying "job" when possible.. ( I executed SHOW TENANT WITH REPLICATION STATUS
why are you mentioning jobs?).
pkg/sql/tenant.go
Outdated
|
||
tenants := make([]roachpb.TenantName, 0, len(rows)) | ||
for _, tenant := range rows { | ||
// If the tenants is in the DROP state the then name is nil. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe tenant name can also be zero if it was created prior to V23_1TenantNames, or using the create_tenant(id)
builtin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was assuming future tenants will always have a name, but maybe there is no need to assume that.. and also, it would be nice to show dropped tenants. anyway, changed this code to use ids instead of names.
pkg/sql/tenant.go
Outdated
@@ -202,6 +202,33 @@ func CreateTenantRecord( | |||
) | |||
} | |||
|
|||
func GetAllTenantNames( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: linter might scream at you to add a comment to this exported method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should! but it didn't.. fixed.
pkg/sql/show_tenant.go
Outdated
default: | ||
return errors.Newf("unknown tenant status %s", n.tenantInfo.State) | ||
status := fmt.Sprintf("tenant status: %s", values.tenantInfo.State) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer if we leave this an error. If we see a tenant in a state other than ADD
, DROP
, ACTIVE
then it means someone has added a state and not considered all the places it effects, so I'd rather it fail tests loudly. wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, done. I don't like it that the show command just breaks when one tenant has an issue but here it's fine.
pkg/sql/show_tenant.go
Outdated
|
||
func (n *showTenantNode) getTenantValues( | ||
params runParams, tenantName roachpb.TenantName, | ||
) (*tenantValues, error) { | ||
tenantRecord, err := GetTenantRecordByName(params.ctx, params.p.execCfg, params.p.Txn(), tenantName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a heads up, there is another PR in flight to make most of these commands work with either IDs or names. Not sure there is anything we want to do here other than being willing to help resolve the conflict when it occurs :D.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, thanks.
pkg/sql/show_tenant.go
Outdated
@@ -93,100 +110,145 @@ func (n *showTenantNode) getTenantName(params runParams) (roachpb.TenantName, er | |||
} | |||
|
|||
func (n *showTenantNode) startExec(params runParams) error { | |||
tenantName, err := n.getTenantName(params) | |||
if n.all { | |||
names, err := GetAllTenantNames(params.ctx, params.p.execCfg, params.p.Txn()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering, instead of passing this list of names around. Could we do more of this in sql? That is, we are essentially pretty-printing the results of SELECT id, FROM system.tenants
and annotating it with job details. I wonder if we could either: (1) use an iterator over a query we construct to select the correct nodes or (2) implement this as a delegated statement instead.
I'm OK doing this as a follow-up, just a little suspect of anywhere that we require passing around complete sets of user-generatable data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, as we discussed we might want to do this in a followup.
62c6e2b
to
bb968da
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfortunately too many changes :(
PTAL
mostly - this pr now gets the list of ids, not names, which means we also show dropped tenants without a name! (I thought of putting the droppedName there but then the name would not be unique which is not fun). because of that this pr is sorting the list by tenant id (probably better than by name?).
added some tests.
thanks!!
@@ -161,7 +161,7 @@ func alterReplicationJobHook( | |||
return err | |||
} | |||
if tenInfo.TenantReplicationJobID == 0 { | |||
return errors.Newf("tenant %q does not have an active replication job", tenantName) | |||
return errors.Newf("tenant %q is not a replicated tenant", tenantName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not necessary in this pr, dropping.
FWIW I think we should avoid saying "job" when possible.. ( I executed SHOW TENANT WITH REPLICATION STATUS
why are you mentioning jobs?).
pkg/sql/show_tenant.go
Outdated
|
||
func (n *showTenantNode) getTenantValues( | ||
params runParams, tenantName roachpb.TenantName, | ||
) (*tenantValues, error) { | ||
tenantRecord, err := GetTenantRecordByName(params.ctx, params.p.execCfg, params.p.Txn(), tenantName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, thanks.
pkg/sql/show_tenant.go
Outdated
default: | ||
return errors.Newf("unknown tenant status %s", n.tenantInfo.State) | ||
status := fmt.Sprintf("tenant status: %s", values.tenantInfo.State) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, done. I don't like it that the show command just breaks when one tenant has an issue but here it's fine.
pkg/sql/tenant.go
Outdated
@@ -202,6 +202,33 @@ func CreateTenantRecord( | |||
) | |||
} | |||
|
|||
func GetAllTenantNames( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should! but it didn't.. fixed.
pkg/sql/tenant.go
Outdated
|
||
tenants := make([]roachpb.TenantName, 0, len(rows)) | ||
for _, tenant := range rows { | ||
// If the tenants is in the DROP state the then name is nil. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was assuming future tenants will always have a name, but maybe there is no need to assume that.. and also, it would be nice to show dropped tenants. anyway, changed this code to use ids instead of names.
pkg/sql/show_tenant.go
Outdated
@@ -93,100 +110,145 @@ func (n *showTenantNode) getTenantName(params runParams) (roachpb.TenantName, er | |||
} | |||
|
|||
func (n *showTenantNode) startExec(params runParams) error { | |||
tenantName, err := n.getTenantName(params) | |||
if n.all { | |||
names, err := GetAllTenantNames(params.ctx, params.p.execCfg, params.p.Txn()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, as we discussed we might want to do this in a followup.
f983dfc
to
72c5903
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, this seems reasonable to me. I think a few new logic tests would be great though.
pkg/sql/tenant.go
Outdated
@@ -201,6 +201,35 @@ func CreateTenantRecord( | |||
) | |||
} | |||
|
|||
// GetAllTenantIds returns all tenants in the system table, excluding those in | |||
// the DROP state. | |||
func GetAllTenantIds( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] Ids -> IDs. Should this be GetAllNonDropTenantIDs
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
pkg/sql/tenant.go
Outdated
iTenantId := uint64(tree.MustBeDInt(tenant[0])) | ||
tenantId, err := roachpb.MakeTenantID(iTenantId) | ||
if err != nil { | ||
return nil, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to make this an AssertionFailedf since it implies we allowed someone to write an invalid tenant ID into the tenants table.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
@@ -76,10 +76,10 @@ id name status | |||
statement error tenant "seven" does not exist | |||
SHOW TENANT seven | |||
|
|||
statement error tenant "tenant-one" does not have an active replication job | |||
query error pq: tenant "tenant-one" does not have an active replication job |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a test to this file to show the output of SHOW TENANTS
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
definitely, forgot about those.. thanks! done. also added some in the tenant datadriven test.
72c5903
to
fc4bc05
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks! done.
pkg/sql/tenant.go
Outdated
@@ -201,6 +201,35 @@ func CreateTenantRecord( | |||
) | |||
} | |||
|
|||
// GetAllTenantIds returns all tenants in the system table, excluding those in | |||
// the DROP state. | |||
func GetAllTenantIds( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
@@ -76,10 +76,10 @@ id name status | |||
statement error tenant "seven" does not exist | |||
SHOW TENANT seven | |||
|
|||
statement error tenant "tenant-one" does not have an active replication job | |||
query error pq: tenant "tenant-one" does not have an active replication job |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
definitely, forgot about those.. thanks! done. also added some in the tenant datadriven test.
pkg/sql/tenant.go
Outdated
iTenantId := uint64(tree.MustBeDInt(tenant[0])) | ||
tenantId, err := roachpb.MakeTenantID(iTenantId) | ||
if err != nil { | ||
return nil, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
93d45f7
to
c6acd52
Compare
c6acd52
to
8d284bb
Compare
This command prints all available tenants and their status. To get the status for replication (c2c) tenants we need to get the job info. For example: ``` [email protected]:26257/defaultdb> show tenants; id | name | status -----+----------+---------------------------------------------------------------------- 1 | system | ACTIVE 2 | src | ACTIVE 3 | dest | REPLICATION PAUSED 4 | dest2 | REPLICATION UNKNOWN (succeeded) 6 | dest3 | REPLICATION UNKNOWN (job with ID 819888096954253313 does not exist) 11 | dest4 | ACTIVE 12 | dest5 | REPLICATING 13 | dest6 | INITIALIZING REPLICATION (8 rows) Time: 67ms total (execution 67ms / network 0ms) ``` Fixes: cockroachdb#92641 Epic: CRDB-18749 Release note: None
8d284bb
to
9a0dc10
Compare
This command prints all available tenants and their status.
To get the status for replication (c2c) tenants we need to get the job info.
For example:
Fixes: #92641
Epic: CRDB-18749
Release note: None