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

Add log lines to help debug NPE in resolveLocationForPath #585

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

d87zhang
Copy link

We could have NPEs in BasePolarisCatalog.resolveLocationForPath() today. This PR adds log lines to help debug in these situations.

@d87zhang d87zhang force-pushed the log-lines-for-npe-resolveLocationForPath branch from 4de6855 to 8e75d9d Compare December 19, 2024 23:47
Copy link
Contributor

@flyrain flyrain left a comment

Choose a reason for hiding this comment

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

LGTM with minor suggestions.

@@ -554,14 +554,27 @@ private String resolveNamespaceLocation(Namespace namespace, Map<String, String>
.map(
entity -> {
if (entity.getType().equals(PolarisEntityType.CATALOG)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor suggestion: would the code be cleaner if we put these into a new method like

  private static String baseLocation(PolarisEntity entity) {
    if (entity.getType().equals(PolarisEntityType.CATALOG)) {
      return CatalogEntity.of(entity).getDefaultBaseLocation();
    } else {
      String baseLocation =
          entity.getPropertiesAsMap().get(PolarisEntityConstants.ENTITY_BASE_LOCATION);
      if (baseLocation != null) {
        return baseLocation;
      } else {
        return entity.getName();
      }
    }
  }

Copy link
Author

Choose a reason for hiding this comment

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

sounds good. Moved this logic to baseLocation helper!

Comment on lines 559 to 564
if (catalogDefaultBaseLocation == null) {
LOGGER.warn(
"Tried to resolve location with catalog with null default base location. Catalog = {}",
catEntity);
}
return catalogDefaultBaseLocation;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should a catalog ever have a null base location? This feels like a case for PolarisDiagnostics.checkNotNull rather than a log statement.

Copy link
Author

Choose a reason for hiding this comment

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

I'm not too familiar and don't know if this should ever not happen but sounds good to use PolarisDiagnostics.checkNotNull. I'm adding some code

callContext
              .getPolarisCallContext().getDiagServices().checkNotNull

to get the diagnostic services to call checkNotNull though so please check if it's safe to do this or if we should be worried about NPEs.. It seems like elsewhere in the code we're assuming there aren't nulls when calling such methods.

Comment on lines 571 to 577
String entityName = entity.getName();
if (entityName == null) {
LOGGER.warn(
"Tried to resolve location with entity without base location or name. entity = {}",
entity);
}
return entityName;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here - there should never be an entity without a name.

Copy link
Author

Choose a reason for hiding this comment

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

@d87zhang d87zhang force-pushed the log-lines-for-npe-resolveLocationForPath branch from 04426e8 to 0589ae9 Compare December 21, 2024 00:42
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.

3 participants