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

Table addition validation #2469

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Table addition validation #2469

wants to merge 7 commits into from

Conversation

Amogh-Bharadwaj
Copy link
Contributor

@Amogh-Bharadwaj Amogh-Bharadwaj commented Jan 20, 2025

This PR introduces validation for table addition. The validation consists of:

  1. Checks if the added tables are part of the publication if it is a user provided publication.
  2. Performs ClickHouse destination table checks for the additional tables - these are the same checks as done in mirror creation validation.

A new Flow API endpoint has been made for this, and the UI sends a request to this if there are additional tables selected.

Screenshot 2025-01-21 at 4 55 26 AM

Screenshot 2025-01-21 at 4 57 56 AM

@@ -190,3 +196,93 @@ func (h *FlowRequestHandler) CheckIfMirrorNameExists(ctx context.Context, mirror

return nameExists.Bool, nil
}

func (h *FlowRequestHandler) ValidateTableAdditions(ctx context.Context, req *protos.ValidateTableAdditionsRequest) (*protos.ValidateCDCMirrorResponse, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we want to split the API into validating and then doing the actual operation? it seems more reasonable to have the existing endpoint check and then error out, would map better to the ClickPipes UI as well

Requires publication name as string and table values in the form of (schema::text, table::text) pairs.
The schema and table names should be quoted and escaped.
*/
func (c *PostgresConnector) CheckIfTablesAreInPublication(ctx context.Context, pubName string, tableValues []string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can share code with the check done in AddTablesToPublication

Comment on lines +172 to 179
err = chPeer.CheckDestinationTables(ctx, connclickhouse.ClickHouseDestinationCheckInput{
TableMappings: req.ConnectionConfigs.TableMappings,
TableNameSchemaMapping: res,
SyncedAtColName: req.ConnectionConfigs.SyncedAtColName,
Resync: req.ConnectionConfigs.Resync,
DoInitialSnapshot: req.ConnectionConfigs.DoInitialSnapshot,
})
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
err = chPeer.CheckDestinationTables(ctx, connclickhouse.ClickHouseDestinationCheckInput{
TableMappings: req.ConnectionConfigs.TableMappings,
TableNameSchemaMapping: res,
SyncedAtColName: req.ConnectionConfigs.SyncedAtColName,
Resync: req.ConnectionConfigs.Resync,
DoInitialSnapshot: req.ConnectionConfigs.DoInitialSnapshot,
})
if err != nil {
if err := chPeer.CheckDestinationTables(ctx, connclickhouse.ClickHouseDestinationCheckInput{
TableMappings: req.ConnectionConfigs.TableMappings,
TableNameSchemaMapping: res,
SyncedAtColName: req.ConnectionConfigs.SyncedAtColName,
Resync: req.ConnectionConfigs.Resync,
DoInitialSnapshot: req.ConnectionConfigs.DoInitialSnapshot,
}); err != nil {

Comment on lines +272 to +280
err = chPeer.CheckDestinationTables(ctx, connclickhouse.ClickHouseDestinationCheckInput{
TableMappings: req.AddedTables,
TableNameSchemaMapping: res,
SyncedAtColName: req.SyncedAtColName,
// TODO: Implement resync and cdc-only for table addition
Resync: false,
DoInitialSnapshot: true,
})
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
err = chPeer.CheckDestinationTables(ctx, connclickhouse.ClickHouseDestinationCheckInput{
TableMappings: req.AddedTables,
TableNameSchemaMapping: res,
SyncedAtColName: req.SyncedAtColName,
// TODO: Implement resync and cdc-only for table addition
Resync: false,
DoInitialSnapshot: true,
})
if err != nil {
if err := chPeer.CheckDestinationTables(ctx, connclickhouse.ClickHouseDestinationCheckInput{
TableMappings: req.AddedTables,
TableNameSchemaMapping: res,
SyncedAtColName: req.SyncedAtColName,
// TODO: Implement resync and cdc-only for table addition
Resync: false,
DoInitialSnapshot: true,
}); err != nil {

return nil, errors.New("source peer config is not postgres")
}

pgPeer, err := connpostgres.NewPostgresConnector(ctx, nil, sourcePeerConfig)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to stop creating postgres connectors like this in endpoints

See #2525 where I put validation behind a connector interface

Comment on lines +240 to +244
publicationErr := pgPeer.CheckIfTablesAreInPublication(ctx, req.PublicationName, addedTableValues)
if publicationErr != nil {
h.alerter.LogNonFlowWarning(ctx, telemetry.EditMirror, req.FlowJobName, publicationErr.Error())
return nil, publicationErr
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
publicationErr := pgPeer.CheckIfTablesAreInPublication(ctx, req.PublicationName, addedTableValues)
if publicationErr != nil {
h.alerter.LogNonFlowWarning(ctx, telemetry.EditMirror, req.FlowJobName, publicationErr.Error())
return nil, publicationErr
}
if err := pgPeer.CheckIfTablesAreInPublication(ctx, req.PublicationName, addedTableValues); err != nil {
h.alerter.LogNonFlowWarning(ctx, telemetry.EditMirror, req.FlowJobName, err.Error())
return nil, err
}

I know it seems nice to avoid shadowing, but what happens is someone makes a change to the error message or something, assumes the variable is called err, & ends up having their code reference some always-nil err from earlier in the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants