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

[#5066] refactor(drop-catalog): re-define drop catalog #5067

Merged
merged 11 commits into from
Oct 18, 2024

Conversation

mchades
Copy link
Contributor

@mchades mchades commented Oct 8, 2024

What changes were proposed in this pull request?

  • Add an in-use property to the catalog with the default value of true.
  • Only empty catalog with in-use=false can be dropped.
  • User can use dorce option to drop catalog
  • More drop catalog limitations please see the JavaDoc of dropCatalog in API module

Why are the changes needed?

Fix: #5066

Does this PR introduce any user-facing change?

yes, users now can not drop an in used catalog

How was this patch tested?

tests added

@mchades mchades self-assigned this Oct 8, 2024
@mchades mchades force-pushed the drop-catalog branch 8 times, most recently from fe68851 to cb738a2 Compare October 14, 2024 10:12
@mchades mchades requested review from jerryshao and jerqi October 16, 2024 07:55
@mchades mchades force-pushed the drop-catalog branch 2 times, most recently from 55b0e72 to 5f5e913 Compare October 16, 2024 11:19
Copy link
Contributor

@jerryshao jerryshao left a comment

Choose a reason for hiding this comment

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

Do you also need to update the doc?

@jerryshao
Copy link
Contributor

Just did a cursory review, I'm fine with the current implementation. I will spend more time to have a deep review.

api/src/main/java/org/apache/gravitino/Catalog.java Outdated Show resolved Hide resolved
gradle.properties Outdated Show resolved Hide resolved

if (!schemas.isEmpty()
&& !force
&& (!catalogEntity.getProvider().equals("kafka") || schemas.size() > 1)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please optimize the condition, if the execution goes to !catalogEntity.getProvider().equals("kafka") || schemas.size() > 1, schemas must be NOT empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no. schemas.size() may equals 1

Copy link
Contributor

Choose a reason for hiding this comment

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

The expression here is difficult to understand, maybe we can use multiple if to describe the exception message for different cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

import com.google.errorprone.annotations.FormatString;

/** Exception thrown when an entity is in use and cannot be deleted. */
public class EntityInUseException extends GravitinoRuntimeException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it better to define a CatalogInUseException and CatalogNotInUseException clearly? This also applies to metalake.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The error message will describe the reason exactly (what entity is not in use).

If we define CatalogInUseException, CatalogNotInUseException, MetalakeInUseException and MetalakeInUseException, then we also need SchemaNotInUseException, TableNotInUseException, TopicNotInUseException, etc which will make the code more complicated, so I think current exception define is enough.

}

public static Response inUse(String type, String message, Throwable throwable) {
return Response.status(Response.Status.CONFLICT)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I prefer 503. Just a discussion not a suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SERVICE_UNAVAILABLE(503, "Service Unavailable") means the server status, not the resource. So I think it's not suitable.

"""
params = {"force": str(force)}
Copy link
Contributor

Choose a reason for hiding this comment

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

str(force) will get "True/False" or "true/false"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In any case, the server side will ignore case sensitivity during query param conversion. So it's not a problem

@mchades
Copy link
Contributor Author

mchades commented Oct 17, 2024

Do you also need to update the doc?

Doc will be updated in final PR

CatalogEntity catalogEntity =
store.get(catalogIdent, EntityType.CATALOG, CatalogEntity.class);
return (boolean)
BASIC_CATALOG_PROPERTIES_METADATA.getOrDefault(
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 need a BASIC_CATALOG_PROPERTIES_METADATA?

@@ -187,6 +187,70 @@ public Response testConnection(
}
}

@GET
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it better to use PUT or POST?

protected Map<String, PropertyEntry<?>> specificPropertyEntries() {
return Collections.emptyMap();
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

We can create a singleton in BaseCatalogPropertiesMetadata and remove abstract in this class to make it simple.

@mchades
Copy link
Contributor Author

mchades commented Oct 17, 2024

All comments are resolved, plz help to review again, thx! @yuqi1129 @jerryshao

@jerryshao
Copy link
Contributor

Can you please fix the CI failure?

throws NonEmptyEntityException, CatalogInUseException;

/**
* Enable a catalog. If the catalog is already enable, this method does nothing.
Copy link
Contributor

Choose a reason for hiding this comment

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

"If the catalog is already enabled..."

Comment on lines 646 to 649
if (catalogInUse) {
// force is true, disable the catalog first
disableCatalog(ident);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the catalog will be deleted, I don't think it is necessary to do the disable here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The purpose of this operation is to modify the in-use value in the backend store

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

@Override
public void enableCatalog(NameIdentifier ident)
throws NoSuchCatalogException, CatalogNotInUseException {
// todo: support activate catalog event
Copy link
Contributor

Choose a reason for hiding this comment

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

Will you do this in a different PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

@jerryshao jerryshao merged commit 639dfc8 into apache:main Oct 18, 2024
26 checks passed
mplmoknijb pushed a commit to mplmoknijb/gravitino that referenced this pull request Nov 6, 2024
…5067)

### What changes were proposed in this pull request?

- Add an `in-use` property to the catalog with the default value of
true.
 - Only empty catalog with `in-use=false` can be dropped.
 - User can use `dorce` option to drop catalog 
- More drop catalog limitations please see the JavaDoc of `dropCatalog`
in API module

### Why are the changes needed?

Fix: apache#5066 

### Does this PR introduce _any_ user-facing change?

yes, users now can not drop an in used catalog

### How was this patch tested?

tests added
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.

[Subtask] refine drop catalog semantics and behavior
4 participants