Skip to content

Commit

Permalink
Fix Cluster Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperxpro committed Jul 28, 2024
1 parent 8889b15 commit 2b4adde
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public boolean remapCluster(String oldHostname, String newHostname) {
}

@Override
public boolean removeCluster(String hostname) {
return super.removeCluster(DEFAULT);
public boolean removeClusters(String hostname) {
return super.removeClusters(DEFAULT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import java.net.InetSocketAddress;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

Expand Down Expand Up @@ -231,6 +230,13 @@ public Map<String, Cluster> clusters() {
return Collections.unmodifiableMap(clusterMap);
}

/**
* Remove all Clusters from Load Balancer
*/
public void removeClusters() {
clusterMap.clear();
}

/**
* Set the default {@link Cluster}
*/
Expand Down Expand Up @@ -305,7 +311,7 @@ public boolean remapCluster(String oldHostname, String newHostname) {
* @param hostname Hostname of the Cluster
* @return Returns {@link Boolean#TRUE} if removal was successful else {@link Boolean#FALSE}
*/
public boolean removeCluster(String hostname) {
public boolean removeClusters(String hostname) {
boolean removed = false;
try {
Cluster cluster = clusterMap.remove(hostname);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import io.netty.channel.epoll.EpollServerSocketChannelConfig;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.unix.UnixChannelOption;
import io.netty.incubator.channel.uring.IOUringChannelOption;
import io.netty.incubator.channel.uring.IOUringServerSocketChannel;

import java.util.List;
Expand Down Expand Up @@ -128,7 +127,7 @@ public L4FrontListenerStartupEvent start() {
public L4FrontListenerStopEvent stop() {
L4FrontListenerStopEvent l4FrontListenerStopEvent = new L4FrontListenerStopEvent();

// If ChannelFutureList is empty then this listener is already stopped and we won't stop it again.
// If ChannelFutureList is empty, then this listener is already stopped, and we won't stop it again.
if (channelFutures.isEmpty()) {
l4FrontListenerStopEvent.markFailure(new IllegalArgumentException("Listener has already stopped and cannot be stopped again."));
return l4FrontListenerStopEvent;
Expand All @@ -137,7 +136,7 @@ public L4FrontListenerStopEvent stop() {
// Close all ChannelFutures
channelFutures.forEach(channelFuture -> channelFuture.channel().close());

// Add listener to last ChannelFuture to notify all listeners
// Add a listener to last ChannelFuture to notify all listeners
channelFutures.get(channelFutures.size() - 1).channel().closeFuture().addListener(future -> {
if (future.isSuccess()) {
channelFutures.clear();
Expand All @@ -159,7 +158,7 @@ public L4FrontListenerShutdownEvent shutdown() {
L4FrontListenerShutdownEvent shutdownEvent = new L4FrontListenerShutdownEvent();

event.future().whenCompleteAsync((_void, throwable) -> {
l4LoadBalancer().clusters().clear();
l4LoadBalancer().removeClusters();
l4LoadBalancer().eventLoopFactory().parentGroup().shutdownGracefully();
l4LoadBalancer().eventLoopFactory().childGroup().shutdownGracefully();
shutdownEvent.markSuccess();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public ResponseEntity<String> delete(@RequestParam String id, @RequestParam Stri
L4LoadBalancer l4LoadBalancer = CoreContext.getContext(id);
Objects.requireNonNull(hostname, "Hostname");

boolean removed = l4LoadBalancer.removeCluster(hostname);
boolean removed = l4LoadBalancer.removeClusters(hostname);
if (!removed) {
throw new NullPointerException("Cluster not found with Hostname: " + hostname);
}
Expand Down

0 comments on commit 2b4adde

Please sign in to comment.