Skip to content

Fix test memory leak #88362

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

Merged
merged 6 commits into from
Jul 12, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,22 @@
import org.elasticsearch.immutablestate.ImmutableClusterStateHandler;
import org.elasticsearch.immutablestate.ImmutableClusterStateHandlerProvider;

import java.util.Arrays;
import java.util.Collection;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Collections;
import java.util.List;

/**
* ILM Provider implementation for the {@link ImmutableClusterStateHandlerProvider} service interface
*/
public class ILMImmutableStateHandlerProvider implements ImmutableClusterStateHandlerProvider {
private static final Set<ImmutableClusterStateHandler<?>> handlers = ConcurrentHashMap.newKeySet();
private static volatile Collection<ImmutableClusterStateHandler<?>> handlers = Collections.emptyList();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private static volatile Collection<ImmutableClusterStateHandler<?>> handlers = Collections.emptyList();
private static final SetOnce<Collection<ImmutableClusterStateHandler<?>>> handlers = new SetOnce<>();

I wonder if this should be a SetOnce<Collection<ImmutableClusterStateHandler<?>>>, then when registerHandlers is called trySet() can be used to atomically update the collection?


@Override
public Collection<ImmutableClusterStateHandler<?>> handlers() {
return handlers;
}

public static void registerHandlers(ImmutableClusterStateHandler<?>... stateHandlers) {
handlers.addAll(Arrays.asList(stateHandlers));
handlers = List.of(stateHandlers);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
handlers = List.of(stateHandlers);
handlers.trySet(List.of(stateHandlers));

Since this completely changes the stored values, it may be good to rename registerHandlers to better indicate that it won't set the values if they are already set.

}
}