-
Notifications
You must be signed in to change notification settings - Fork 35
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
Unregister topic listener on region shutdown #164
Conversation
Can one of the admins verify this patch? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks solid.
Thanks for the contribution! I want to make some points clear. When I run the test /* LocalRegionFactorySlowTest.java */
@Test
public void cleanUpRegisteredTopicOnRegionShutdown() {
HazelcastInstance sf1Instance = HazelcastAccessor.getHazelcastInstance(sf);
List<String> regions = new ArrayList<>(Arrays.asList(sf.getStatistics().getSecondLevelCacheRegionNames()));
// 'Query' cache is not subscribed to a topic in 5 and 52.
regions.removeIf(n -> n.contains("Query"));
regions.forEach(r ->
assertEquals(r,2, Accessors.getNodeEngineImpl(sf1Instance)
.getEventService().getRegistrations(TopicService.SERVICE_NAME, r).size()));
sf2.close();
regions.forEach(r ->
assertEquals(r,1, Accessors.getNodeEngineImpl(sf1Instance)
.getEventService().getRegistrations(TopicService.SERVICE_NAME, r).size()));
} I get
As I added some logs at the points where a listener is registered to and removed from the topic, I noticed Any idea about this behavior? |
@enozcan I checked and it seems Hibernate is not calling the |
@@ -31,19 +33,23 @@ | |||
private final Duration fixedDelay; | |||
private final String name; | |||
private final ScheduledExecutorService executor; | |||
private final List<Runnable> cacheDestroy; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be easier to actually store LocalRegionCache
instances and then iterate over them and call destroy()
on each?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it would be simpler. Also, it would increase the coupling for future changes, the idea was to just use the needed parts and hide the rest inside the CleanupService.
We can do it that other way too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that that would result in extra coupling. Keep in mind that the registerCache()
method accepts LocalRegionCache
objects and the rest is encapsulated within the CleanupService
class and doesn't really leak out in any way.
So I'd suggest we just store them as List<LocalRegionCache>
|
||
public CleanupService(final String name, final Duration fixedDelay) { | ||
this.fixedDelay = fixedDelay; | ||
this.name = name; | ||
executor = Executors.newSingleThreadScheduledExecutor(new CleanupThreadFactory()); | ||
cacheDestroy = new LinkedList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason why LinkedList
is better over ArrayList
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since is was just add at the end, one iteration on stop and an unknown size, I thought it would perform better. But doing some review, the cases an ArrayList would underperform are too edgy, so we should go with an ArrayList. I'll move to that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments already provided
@pivovarit , changes committed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one last thing and I think we're good to go
hazelcast-hibernate52/src/main/java/com/hazelcast/hibernate/local/CleanupService.java
Outdated
Show resolved
Hide resolved
hazelcast-hibernate5/src/main/java/com/hazelcast/hibernate/local/CleanupService.java
Outdated
Show resolved
Hide resolved
hazelcast-hibernate53/src/main/java/com/hazelcast/hibernate/local/CleanupService.java
Outdated
Show resolved
Hide resolved
Done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Let's wait for @enozcan to have a final look
Fix for #163