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

[CLC-425]: Print Warnings Before Exit #420

Merged
merged 5 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
19 changes: 19 additions & 0 deletions base/commands/migration/migration_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,22 @@ func finalizeMigration(ctx context.Context, ec plug.ExecContext, ci *hazelcast.C
return nil
}

func maybePrintWarnings(ctx context.Context, ec plug.ExecContext, ci *hazelcast.ClientInternal, migrationID string) {
q := fmt.Sprintf(`SELECT JSON_QUERY(this, '$.warnings' WITH WRAPPER) FROM %s WHERE __key='%s'`, StatusMapName, migrationID)
row, err := querySingleRow(ctx, ci, q)
if err != nil {
ec.Logger().Error(err)
return
}
var warnings []string
err = json.Unmarshal(row.(serialization.JSON), &warnings)
if err != nil {
ec.Logger().Error(err)
return
}
ec.PrintlnUnnecessary("* " + strings.Join(warnings, "\n* "))
Copy link
Member

Choose a reason for hiding this comment

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

If there're lots of them, it can be more reasonable to point to the migration report instead. The warnings will be in the report as well. If there're less than 5 we can directly print them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think there won't be too many warning that makes it hard to display in the terminal.

Copy link
Member

Choose a reason for hiding this comment

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

There can be in the future. We'll keep adding things to warnings field.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Note that, it's not just for future. 1000 ds skips can even happen now.

}

func querySingleRow(ctx context.Context, ci *hazelcast.ClientInternal, query string) (any, error) {
res, err := ci.Client().SQL().Execute(ctx, query)
if err != nil {
Expand All @@ -288,6 +304,9 @@ func querySingleRow(ctx context.Context, ci *hazelcast.ClientInternal, query str
if err != nil {
return "", err
}
if r == nil {
return nil, errors.New("no rows found")
}
return r, nil
}
return nil, errors.New("no rows found")
Expand Down
1 change: 1 addition & 0 deletions base/commands/migration/migration_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Selected data structures in the source cluster will be migrated to the target cl
ec.PrintlnUnnecessary("")
mID := MakeMigrationID()
defer func() {
maybePrintWarnings(ctx, ec, ci, mID)
finalizeErr := finalizeMigration(ctx, ec, ci, mID, ec.Props().GetString(flagOutputDir))
if err == nil {
err = finalizeErr
Expand Down
1 change: 1 addition & 0 deletions base/commands/migration/migration_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func (s StatusCmd) Exec(ctx context.Context, ec plug.ExecContext) (err error) {
return err
}
defer func() {
maybePrintWarnings(ctx, ec, ci, mID.(string))
finalizeErr := finalizeMigration(ctx, ec, ci, mID.(string), ec.Props().GetString(flagOutputDir))
if err == nil {
err = finalizeErr
Expand Down
Loading