Skip to content

Conversation

@TrafalgarZZZ
Copy link
Member

Ⅰ. Describe what this PR does

  • Add a new function GetPossibleTargetDatasetNamespacedNames() for all data operations. It's currently only used when cleaning data operations. The function returns a list of possible datasets' types.NamespacedName, after then the operation reconciler can correctly remove engines with the namespace and name.
  • Refactor func GetTargetDatasetOfMigrate to make it easier to read.

Ⅱ. Does this pull request fix one issue?

fixes #4328

Ⅲ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

…igrate utils

Signed-off-by: trafalgarzzz <trafalgarz@outlook.com>
…data operations

Signed-off-by: trafalgarzzz <trafalgarz@outlook.com>
Signed-off-by: trafalgarzzz <trafalgarz@outlook.com>
Signed-off-by: trafalgarzzz <trafalgarz@outlook.com>
@sonarqubecloud
Copy link

@xliuqq
Copy link
Collaborator

xliuqq commented Sep 26, 2024

@TrafalgarZZZ I read through the code and figure out the reason for #4328.
The engine will not be deleted because we does not set the NamespacedName in ctx before ReconcileDeletion(causing memory leak too). see code below for details.

ctx.NamespacedName = types.NamespacedName{

I know the DataMigrate must get the dataset object for checking runtime type so we can not set the NamespacedName in ctx before ReconcileDeletion. But, do we still have a way to merge the GetPossibleTargetDatasetNamespacedNames and GetTargetDataset functions into one for OperationInterface ?

@TrafalgarZZZ
Copy link
Member Author

@TrafalgarZZZ I read through the code and figure out the reason for #4328. The engine will not be deleted because we does not set the NamespacedName in ctx before ReconcileDeletion(causing memory leak too). see code below for details.

ctx.NamespacedName = types.NamespacedName{

I know the DataMigrate must get the dataset object for checking runtime type so we can not set the NamespacedName in ctx before ReconcileDeletion. But, do we still have a way to merge the GetPossibleTargetDatasetNamespacedNames and GetTargetDataset functions into one for OperationInterface ?

@xliuqq Thanks for the advice. But I am currently not sure how to merge these two functions. GetPossibleTargetDatasetNamespacedNames gets namespacedNames only from Data Operation's spec, while GetTargetDataset can get Dataset objects from the cluster. Did you mean something like:

func GetTargetDataset() (namespacedNames []types.NamespacedName, targetDataset *datav1alpha1.Dataset) {
  // If dataset object cannot be found -> returns full namespacedNames

  // If dataset object can be found -> returns a namespacedName and the corresponding Dataset
}


dataset, innerErr := GetDataset(client, toCheck.Name, namespace)
if innerErr != nil {
err = errors.Wrapf(innerErr, "failed to get dataset \"%s/%s\" from DataMigrate \"%s/%s\"'s spec", namespace, toCheck.Name, dataMigrate.Namespace, dataMigrate.Name)
Copy link
Collaborator

@xliuqq xliuqq Sep 27, 2024

Choose a reason for hiding this comment

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

we can not wrap the error, as the code in

err = base.ReleaseTargetDataset(ctx.ReconcileRequestContext, implement)

calls
dataset, err := operation.GetTargetDataset()

and later code will check the not found error.

Copy link
Member Author

@TrafalgarZZZ TrafalgarZZZ Sep 29, 2024

Choose a reason for hiding this comment

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

@xliuqq Thank you! Very careful advice. I've tested such case and I think that would not be a problem.

In vendor/k8s.io/apimachinery/pkg/api/errors/errors.go, you can see the function automatically unwraps the error and checks if it's a NotFound error.

// IsNotFound returns true if the specified error was created by NewNotFound.
// It supports wrapped errors and returns false when the error is nil.
func IsNotFound(err error) bool {
	reason, code := reasonAndCodeForError(err)
	if reason == metav1.StatusReasonNotFound {
		return true
	}
	if _, ok := knownReasons[reason]; !ok && code == http.StatusNotFound {
		return true
	}
	return false
}

I've also tried something like this, and it prints "Wrapped error supported". From my understanding, the code now should works fine.

func main() {
	err := apierrors.NewNotFound(schema.ParseGroupResource("datasets.data.fluid.io"), "dataset not found")
	wrappedErr := errors.Wrap(err, "A wrapped error")

	if apierrors.IsNotFound(wrappedErr) {
		fmt.Println("Wrapped error supported")
	} else {
		fmt.Println("Wrapped error is not support")
	}
}

Copy link
Collaborator

@cheyang cheyang left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@fluid-e2e-bot
Copy link

fluid-e2e-bot bot commented Sep 29, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cheyang

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@cheyang
Copy link
Collaborator

cheyang commented Sep 29, 2024

/test fluid-e2e

@TrafalgarZZZ
Copy link
Member Author

/retest

@fluid-e2e-bot fluid-e2e-bot bot merged commit 7a74eac into fluid-cloudnative:master Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] DataLoad fails on recreated Dataset after upgrading JindoRuntime

3 participants