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

Fix issue 414 CLC-418 #417

Merged
merged 7 commits into from
Oct 30, 2023
Merged

Fix issue 414 CLC-418 #417

merged 7 commits into from
Oct 30, 2023

Conversation

srknzl
Copy link
Member

@srknzl srknzl commented Oct 25, 2023

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.

…es to failed state in WaitForMigrationToBeInProgress
@srknzl srknzl added this to the Data Migration Tool [Phase 1] milestone Oct 25, 2023
@srknzl srknzl self-assigned this Oct 25, 2023
@srknzl srknzl changed the title Fix precheck issue 414 Fix issue 414 CLC-418 Oct 25, 2023
@srknzl srknzl changed the base branch from main to dmt October 25, 2023 18:26
Copy link

@sumnerib sumnerib left a 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"
Copy link
Member Author

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 {
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

What is WITH WRAPPER ?

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 {
Copy link
Collaborator

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\"]"),
Copy link
Collaborator

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?

Copy link
Contributor

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
}

Copy link
Contributor

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.

Copy link
Collaborator

@yuce yuce left a comment

Choose a reason for hiding this comment

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

Looks good!

@kutluhanmetin kutluhanmetin self-requested a review October 30, 2023 13:37
Copy link
Contributor

@kutluhanmetin kutluhanmetin left a comment

Choose a reason for hiding this comment

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

Thank you Serkan!

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