-
Notifications
You must be signed in to change notification settings - Fork 24
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 issue 414 CLC-418 #417
Conversation
…es to failed state in WaitForMigrationToBeInProgress
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 cannot comment on the code itself, as I don't have much experience w/ golang, but building the tool from this branch does look to solve the issue.
_ "github.com/hazelcast/hazelcast-commandline-client/base" | ||
_ "github.com/hazelcast/hazelcast-commandline-client/base/commands" | ||
"github.com/hazelcast/hazelcast-commandline-client/base/commands/migration" | ||
"github.com/hazelcast/hazelcast-commandline-client/clc/paths" | ||
. "github.com/hazelcast/hazelcast-commandline-client/internal/check" | ||
"github.com/hazelcast/hazelcast-commandline-client/internal/it" | ||
hz "github.com/hazelcast/hazelcast-go-client" | ||
"github.com/hazelcast/hazelcast-go-client/serialization" | ||
"github.com/stretchr/testify/require" |
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.
this is done by goland automatically and I can't prevent it doing that :D
errs, err := fetchMigrationErrors(ctx, ci, migrationID) | ||
if err != nil { | ||
return fmt.Errorf("migration failed and dmt cannot fetch migration errors: %w", err) | ||
} else { |
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.
else
is not necessary.
@@ -235,7 +243,7 @@ func fetchMigrationReport(ctx context.Context, ci *hazelcast.ClientInternal, mig | |||
} | |||
|
|||
func fetchMigrationErrors(ctx context.Context, ci *hazelcast.ClientInternal, migrationID string) (string, error) { | |||
q := fmt.Sprintf(`SELECT JSON_QUERY(this, '$.errors') FROM %s WHERE __key='%s'`, StatusMapName, migrationID) | |||
q := fmt.Sprintf(`SELECT JSON_QUERY(this, '$.errors' WITH WRAPPER) FROM %s WHERE __key='%s'`, StatusMapName, migrationID) |
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.
What is WITH WRAPPER
?
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.
errs, err := fetchMigrationErrors(ctx, ci, migrationID) | ||
if err != nil { | ||
return fmt.Errorf("migration failed and dmt cannot fetch migration errors: %w", err) | ||
} else { |
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 else
is not necessary.
@@ -42,7 +43,7 @@ func TestMigrationStages(t *testing.T) { | |||
"testdata/start/migration_success_initial.json", | |||
"testdata/start/migration_success_failure.json", | |||
}, | |||
expectedErr: errors.New("Failed migrating IMAP: imap5: some error"), | |||
expectedErr: errors.New("Failed migrating IMAP: imap5: [\"some error\"]"), |
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 think this error message is not optimal.
Can't we keep the original string?
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 would rewrite fetchMigrationErrors
function like:
func fetchMigrationErrors(ctx context.Context, ci *hazelcast.ClientInternal, migrationID string) (string, error) {
q := fmt.Sprintf(`SELECT JSON_QUERY(this, '$.errors' WITH WRAPPER) FROM %s WHERE __key='%s'`, StatusMapName, migrationID)
row, err := querySingleRow(ctx, ci, q)
if err != nil {
return "", err
}
// ex. converts ["some error", "another error"] -> some error\nanother error
r := strings.Split(
strings.ReplaceAll(
strings.ReplaceAll(
strings.ReplaceAll(string(row.(serialization.JSON)), `"`, ``),
"[", ""),
"]", ""),
",")
return strings.Join(r, "\n"), 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.
If it is possible to iterate errors
it would be more convenient of course.
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.
Looks good!
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.
Thank you Serkan!
fixes #414
Adds the logic of throwing the error if migration becomes failed in WaitForMigrationToBeInProgress.
JSON queries that are expected to return an array should use WITH WRAPPER (see https://docs.hazelcast.com/hazelcast/5.3/sql/working-with-json), I fixed that as well.