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

[#2167] refactor: refactor TestGravitinoConnector to enable StaticGuardedByInstance error-prone #2514

Merged
merged 6 commits into from
Mar 18, 2024

Conversation

coolderli
Copy link
Contributor

What changes were proposed in this pull request?

StaticGuardedByInstance amis to avoid public static fields. Because this field is not thread-safe. See more details at https://errorprone.info/bugpattern/StaticGuardedByInstance.

In this MR, I remove some test code in com.datastrato.gravitino.trino.connector.GravitinoPlugin and com.datastrato.gravitino.trino.connector.GravitinoConnectorFactory. At the same time, I enable StaticGuardedByInstance error-prone.

Why are the changes needed?

Does this PR introduce any user-facing change?

  • no

How was this patch tested?

  • original unit tests.

@jerryshao
Copy link
Contributor

@diqiu50 @yuqi1129 please help to review this.

@jerryshao jerryshao requested review from diqiu50 and yuqi1129 and removed request for diqiu50 March 13, 2024 04:34
server.setCatalogConnectorManager(GravitinoPlugin.catalogConnectorManager);

CatalogConnectorManager catalogConnectorManager =
gravitinoPlugin.getCatalogConnectorManager();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there is a real Gravitino client in the CatalogConnectorManager, which may be used to load catalogs. You can pass the mocked Gravitino client to the TestGravitinoFactory to initialize the CatalogConnectorManager.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@diqiu50 Sorry, I don't get it. I have already passed the mocked gravitino client to CatalogConnectorManager:

catalogConnectorManager.setGravitinoClient(gravitinoClient);

Can you please provide a more detailed explanation? Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

The code snippet:

76 queryRunner.createCatalog("test1", "gravitino", properties);
calls the GravitinoConnector.create() function, which instantiates a CatalogConnectorManager. When start() is invoked on the CatalogConnectorManager, it creates an instance of GravitinoClient. This instance is a real GravitinoClient object.

Later, the line:

81 catalogConnectorManager.setGravitinoClient(gravitinoClient);
replaces the instance with a mocked GravitinoClient.

At this point, the real GravitinoClient may still be performing background tasks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}

public CatalogConnectorManager getCatalogConnectorManager() {
return catalogConnectorManager;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't you return factory.getCatalogConnectorManager() directly as it also depends on method GravitinoConnectorFactory#create to initialize catalogConnectorManager;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

.Indeed. I will fix it.

@coolderli
Copy link
Contributor Author

@diqiu50 @yuqi1129 I have fixed the CI. Please take a look when you have time. Thanks.

@yuqi1129
Copy link
Contributor

It's okay with me for the current changes. @diqiu50, do you have any further comments?

@yuqi1129
Copy link
Contributor

@coolderli
Can you resolve the conflicts?

diqiu50
diqiu50 previously approved these changes Mar 18, 2024
Copy link
Contributor

@diqiu50 diqiu50 left a comment

Choose a reason for hiding this comment

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

LGTM

@diqiu50 diqiu50 merged commit b0a6f0f into apache:main Mar 18, 2024
12 checks passed
coolderli added a commit to coolderli/gravitino that referenced this pull request Apr 2, 2024
…ticGuardedByInstance error-prone (apache#2514)

<!--
1. Title: [#<issue>] <type>(<scope>): <subject>
   Examples:
     - "[apache#123] feat(operator): support xxx"
     - "[apache#233] fix: check null before access result in xxx"
     - "[MINOR] refactor: fix typo in variable name"
     - "[MINOR] docs: fix typo in README"
     - "[apache#255] test: fix flaky test NameOfTheTest"
   Reference: https://www.conventionalcommits.org/en/v1.0.0/
2. If the PR is unfinished, please mark this PR as draft.
-->

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

`StaticGuardedByInstance` amis to avoid `public static` fields. Because
this field is not thread-safe. See more details at
https://errorprone.info/bugpattern/StaticGuardedByInstance.

In this MR, I remove some test code in
`com.datastrato.gravitino.trino.connector.GravitinoPlugin` and
`com.datastrato.gravitino.trino.connector.GravitinoConnectorFactory`. At
the same time, I enable `StaticGuardedByInstance` error-prone.

### Why are the changes needed?

- Fix: apache#2167 

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

- no

### How was this patch tested?

- original unit tests.
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.

[Improvement] GravitinoConnectorFactory.java writes to a static field is not thread-safe
5 participants