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

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

Closed
Tracked by #2225
justinmclean opened this issue Feb 9, 2024 · 3 comments · Fixed by #2514
Closed
Tracked by #2225
Labels
good first issue Good for newcomers improvement Improvements on everything

Comments

@justinmclean
Copy link
Member

What would you like to be improved?

GravitinoConnectorFactory.java:65: warning: [StaticGuardedByInstance] Write to static variable should not be guarded by instance lock 'this'
GravitinoPlugin.catalogConnectorManager = catalogConnectorManager;

See https://errorprone.info/bugpattern/StaticGuardedByInstance

How should we improve?

No response

@justinmclean justinmclean added good first issue Good for newcomers improvement Improvements on everything labels Feb 9, 2024
@raghits
Copy link

raghits commented Feb 10, 2024

@justinmclean Which branch is this issue on? I'm not seeing this in main branch.

@justinmclean
Copy link
Member Author

It's on the main branch here:
https://github.com/datastrato/gravitino/blob/ca4a8ab1c4907a7e7d35097de66c878a4fb3fdb9/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/GravitinoConnectorFactory.java#L65

You'll note that is inside a synchronized block and catalogConnectorManager is static.

@raghits
Copy link

raghits commented Feb 11, 2024

@justinmclean Assuming I add add a nested sychronized block here such as:
synchronized (GravitinoPlugin.class) { GravitinoPlugin.catalogConnectorManager = catalogConnectorManager; }
This could potentially cause a deadlock if multiple threads are creating connectors. I know this block was added to facilitate testing, could there be a better implementation to intialize GravitinoPlugin? I might need some pointers here. I'm just getting familiar with the project so I might be totally off.

Thanks.

coolderli added a commit to coolderli/gravitino that referenced this issue Mar 13, 2024
coolderli added a commit to coolderli/gravitino that referenced this issue Mar 13, 2024
coolderli added a commit to coolderli/gravitino that referenced this issue Mar 13, 2024
coolderli added a commit to coolderli/gravitino that referenced this issue Mar 18, 2024
diqiu50 pushed a commit that referenced this issue Mar 18, 2024
…rdedByInstance error-prone (#2514)

<!--
1. Title: [#<issue>] <type>(<scope>): <subject>
   Examples:
     - "[#123] feat(operator): support xxx"
     - "[#233] fix: check null before access result in xxx"
     - "[MINOR] refactor: fix typo in variable name"
     - "[MINOR] docs: fix typo in README"
     - "[#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: #2167 

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

- no

### How was this patch tested?

- original unit tests.
coolderli added a commit to coolderli/gravitino that referenced this issue 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
good first issue Good for newcomers improvement Improvements on everything
Projects
None yet
2 participants