-
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
multitenant: append WITH REPLICATION STATUS
columns to SHOW TENANT
columns
#95526
Merged
craig
merged 1 commit into
cockroachdb:master
from
ecwall:multitenant_show_tenant_append_columns
Jan 19, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,10 +73,10 @@ func (p *planner) ShowTenant(ctx context.Context, n *tree.ShowTenant) (planNode, | |
tenantSpec: tspec, | ||
withReplication: n.WithReplication, | ||
} | ||
|
||
node.columns = colinfo.TenantColumns | ||
if n.WithReplication { | ||
node.columns = colinfo.TenantColumnsWithReplication | ||
} else { | ||
node.columns = colinfo.TenantColumns | ||
node.columns = append(node.columns, colinfo.TenantColumnsWithReplication...) | ||
} | ||
|
||
return node, nil | ||
|
@@ -234,61 +234,59 @@ func (n *showTenantNode) Next(params runParams) (bool, error) { | |
|
||
func (n *showTenantNode) Values() tree.Datums { | ||
v := n.values | ||
tenantId := tree.NewDInt(tree.DInt(v.tenantInfo.ID)) | ||
tenantName := tree.NewDString(string(v.tenantInfo.Name)) | ||
tenantStatus := tree.NewDString(string(v.tenantStatus)) | ||
if !n.withReplication { | ||
return tree.Datums{ | ||
tenantId, | ||
tenantName, | ||
tenantStatus, | ||
} | ||
tenantInfo := v.tenantInfo | ||
result := tree.Datums{ | ||
tree.NewDInt(tree.DInt(tenantInfo.ID)), | ||
tree.NewDString(string(tenantInfo.Name)), | ||
tree.NewDString(string(v.tenantStatus)), | ||
} | ||
|
||
// This is a 'SHOW TENANT name WITH REPLICATION STATUS' command. | ||
sourceTenantName := tree.DNull | ||
sourceClusterUri := tree.DNull | ||
replicationJobId := tree.NewDInt(tree.DInt(v.tenantInfo.TenantReplicationJobID)) | ||
replicatedTimestamp := tree.DNull | ||
retainedTimestamp := tree.DNull | ||
cutoverTimestamp := tree.DNull | ||
if n.withReplication { | ||
// This is a 'SHOW TENANT name WITH REPLICATION STATUS' command. | ||
sourceTenantName := tree.DNull | ||
sourceClusterUri := tree.DNull | ||
replicationJobId := tree.NewDInt(tree.DInt(tenantInfo.TenantReplicationJobID)) | ||
replicatedTimestamp := tree.DNull | ||
retainedTimestamp := tree.DNull | ||
cutoverTimestamp := tree.DNull | ||
|
||
if v.replicationInfo != nil { | ||
sourceTenantName = tree.NewDString(string(v.replicationInfo.IngestionDetails.SourceTenantName)) | ||
sourceClusterUri = tree.NewDString(v.replicationInfo.IngestionDetails.StreamAddress) | ||
if v.replicationInfo.ReplicationLagInfo != nil { | ||
minIngested := v.replicationInfo.ReplicationLagInfo.MinIngestedTimestamp | ||
// The latest fully replicated time. Truncating to the nearest microsecond | ||
// because if we don't, then MakeDTimestamp rounds to the nearest | ||
// microsecond. In that case a user may want to cutover to a rounded-up | ||
// time, which is a time that we may never replicate to. Instead, we show | ||
// a time that we know we replicated to. | ||
replicatedTimestamp, _ = tree.MakeDTimestampTZ(minIngested.GoTime().Truncate(time.Microsecond), time.Nanosecond) | ||
} | ||
// The protected timestamp on the destination cluster. Same as with the | ||
// replicatedTimestamp, we want to show a retained time that is within the | ||
// window (retained to replicated) and not below it. We take a timestamp | ||
// that is greater than the protected timestamp by a microsecond or less | ||
// (it's not exactly ceil but close enough). | ||
retainedCeil := v.protectedTimestamp.GoTime().Truncate(time.Microsecond).Add(time.Microsecond) | ||
retainedTimestamp, _ = tree.MakeDTimestampTZ(retainedCeil, time.Nanosecond) | ||
progress := v.replicationInfo.IngestionProgress | ||
if progress != nil && !progress.CutoverTime.IsEmpty() { | ||
cutoverTimestamp = eval.TimestampToDecimalDatum(progress.CutoverTime) | ||
replicationInfo := v.replicationInfo | ||
if replicationInfo != nil { | ||
sourceTenantName = tree.NewDString(string(replicationInfo.IngestionDetails.SourceTenantName)) | ||
sourceClusterUri = tree.NewDString(replicationInfo.IngestionDetails.StreamAddress) | ||
if replicationInfo.ReplicationLagInfo != nil { | ||
minIngested := replicationInfo.ReplicationLagInfo.MinIngestedTimestamp | ||
// The latest fully replicated time. Truncating to the nearest microsecond | ||
// because if we don't, then MakeDTimestamp rounds to the nearest | ||
// microsecond. In that case a user may want to cutover to a rounded-up | ||
// time, which is a time that we may never replicate to. Instead, we show | ||
// a time that we know we replicated to. | ||
replicatedTimestamp, _ = tree.MakeDTimestampTZ(minIngested.GoTime().Truncate(time.Microsecond), time.Nanosecond) | ||
} | ||
// The protected timestamp on the destination cluster. Same as with the | ||
// replicatedTimestamp, we want to show a retained time that is within the | ||
// window (retained to replicated) and not below it. We take a timestamp | ||
// that is greater than the protected timestamp by a microsecond or less | ||
// (it's not exactly ceil but close enough). | ||
retainedCeil := v.protectedTimestamp.GoTime().Truncate(time.Microsecond).Add(time.Microsecond) | ||
retainedTimestamp, _ = tree.MakeDTimestampTZ(retainedCeil, time.Nanosecond) | ||
progress := replicationInfo.IngestionProgress | ||
if progress != nil && !progress.CutoverTime.IsEmpty() { | ||
cutoverTimestamp = eval.TimestampToDecimalDatum(progress.CutoverTime) | ||
} | ||
} | ||
} | ||
|
||
return tree.Datums{ | ||
tenantId, | ||
tenantName, | ||
tenantStatus, | ||
sourceTenantName, | ||
sourceClusterUri, | ||
replicationJobId, | ||
replicatedTimestamp, | ||
retainedTimestamp, | ||
cutoverTimestamp, | ||
result = append(result, | ||
sourceTenantName, | ||
sourceClusterUri, | ||
replicationJobId, | ||
replicatedTimestamp, | ||
retainedTimestamp, | ||
cutoverTimestamp, | ||
) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The capabilities PR will add
|
||
return result | ||
} | ||
|
||
func (n *showTenantNode) Close(_ context.Context) {} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The capabilities PR will add