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

Make static final Set constants immutable #13087

Merged
merged 6 commits into from
Feb 28, 2024

Conversation

sabi0
Copy link
Contributor

@sabi0 sabi0 commented Feb 7, 2024

For the mutable "global" Sets changed Collections.synchronizedSet() to ConcurrentHashMap.newKeySet() for better performance.

For the mutable "global" Sets changed Collections.synchronizedSet() to ConcurrentHashMap.newKeySet() for better performance.
# Conflicts:
#	lucene/CHANGES.txt
Copy link
Contributor

@uschindler uschindler left a comment

Choose a reason for hiding this comment

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

This PR has 2 different types of changes: One is to use ConcurrentHashMap for some synchronized sets, the other one is making stuff final and unmodifiable.

I generally agree, but we could better communicate that in the changes log.

@@ -65,7 +64,7 @@ public final class NativeFSLockFactory extends FSLockFactory {
/** Singleton instance */
public static final NativeFSLockFactory INSTANCE = new NativeFSLockFactory();

private static final Set<String> LOCK_HELD = Collections.synchronizedSet(new HashSet<String>());
private static final Set<String> LOCK_HELD = ConcurrentHashMap.newKeySet();
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 LOCK_HELP should be Set<Path>. This would make more sense as it would also be working with different slashes.

I know this isn't related to this cleanup task, but I just have seen it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will open a separate PR for this.

@@ -80,7 +81,7 @@ public abstract class BackwardsCompatibilityTestBase extends LuceneTestCase {
// make sure we never miss a version.
assertTrue("Version: " + version + " missing", binaryVersions.remove(version));
}
BINARY_SUPPORTED_VERSIONS = binaryVersions;
BINARY_SUPPORTED_VERSIONS = Collections.unmodifiableSet(binaryVersions);
Copy link
Contributor

Choose a reason for hiding this comment

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

We changed that code recently, maybe check also the other Ancient indexes test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TestAncientIndicesCompatibility.UNSUPPORTED_INDEXES is already immutable:

Or did you mean something else?

Copy link
Contributor

Choose a reason for hiding this comment

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

ok all fine.


private final Class<C> baseClass;
private final String method;
private final Class<?>[] parameters;
private final ClassValue<Integer> distanceOfClass =
new ClassValue<Integer>() {
new ClassValue<>() {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is unrelated and does not work with Java 11 (when you subclass on "new" you had to be explicit in former times). I'd like to be explicit 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.

Reverted

@@ -260,6 +260,8 @@ Improvements

* GITHUB#13092: `static final Map` constants have been made immutable (Dmitry Cherniachenko)

* GITHUB#13087: Some `static final Set` constants were mutable - rectified. (Dmitry Cherniachenko)
Copy link
Contributor

Choose a reason for hiding this comment

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

Move to 9.11

Copy link
Contributor

Choose a reason for hiding this comment

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

Also add the new set impl.

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

@uschindler uschindler self-assigned this Feb 19, 2024
@uschindler uschindler added this to the 9.11.0 milestone Feb 19, 2024
@uschindler
Copy link
Contributor

I checked backwards compatibility: Except the scandinavian analyzer everything is tests or implementation private.

I think for scandinavian normalizer we need a short note in the changes, because the public set is no longer mutable. Although it would be a downstream bug to actually change it.

@uschindler
Copy link
Contributor

Hi @sabi0,
what's going on with this? Should I merge this one after resolving the conflict? The changes entry needs to be moved to 9.11.

@sabi0
Copy link
Contributor Author

sabi0 commented Feb 28, 2024

Hi @uschindler,
I was away from computer last week. I will take care of the conflicts and your remarks later today.
Sorry for the delay.

@uschindler
Copy link
Contributor

Hi @uschindler, I was away from computer last week. I will take care of the conflicts and your remarks later today. Sorry for the delay.

There seems to be overlap with the latest PR regarding concurrent sets. Maybe revert those changes from this PR.

fixup! fixup! Make `static final Set` constants immutable
@sabi0
Copy link
Contributor Author

sabi0 commented Feb 28, 2024

There seems to be overlap with the latest PR regarding concurrent sets. Maybe revert those changes from this PR.

This was a good idea. Thank you.
Now there is a clean separation between "immutable" (this PR) and "concurrent" sets (#13142).

@uschindler uschindler merged commit 7b01f2f into apache:main Feb 28, 2024
4 checks passed
asfgit pushed a commit that referenced this pull request Feb 28, 2024
@uschindler
Copy link
Contributor

Thanks!

@dweiss dweiss self-requested a review February 29, 2024 07:00
Copy link
Contributor

@dweiss dweiss left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -65,7 +64,7 @@ public final class NativeFSLockFactory extends FSLockFactory {
/** Singleton instance */
public static final NativeFSLockFactory INSTANCE = new NativeFSLockFactory();

private static final Set<String> LOCK_HELD = Collections.synchronizedSet(new HashSet<String>());
Copy link
Contributor

Choose a reason for hiding this comment

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

There are subtle differences between these two things (synchronized set and a concurrent set). I would leave this change to a separate issue so that it can be assessed separately (I think it's a good idea, but we need to track down all the uses and make sure nothing will break).

@@ -74,14 +73,13 @@
*/
public final class VirtualMethod<C> {

private static final Set<Method> singletonSet =
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, perhaps (or merge with the issue above)?

@@ -61,7 +61,7 @@
@SuppressForbidden(reason = "We need Unsafe to actually crush :-)")
public class TestSimpleServer extends LuceneTestCase {

static final Set<Thread> clientThreads = Collections.synchronizedSet(new HashSet<>());
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems fine even here as it only affects one test.

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.

None yet

4 participants